假设我已经编写了引用x维的代码。使vim复制一行代码以替换所有对x到y和z的引用的最佳方法是什么(最好是最清晰的方法)。
输入:
length_x = X_vec.dot(X_vec)**.5
所需的输出:
length_x = X_vec.dot(X_vec)**.5
length_y = Y_vec.dot(Y_vec)**.5
length_z = Z_vec.dot(Z_vec)**.5
到目前为止,这是我最好的。
function SwitchXtoYZ()
:normal yy
:normal p
:normal! V
:s/X/Y/ge
:normal! V
:s/x/y/ge
:normal p
:normal! V
:s/X/Z/ge
:normal! V
:s/x/z/ge
endfunction
command XtoYZ exec SwitchXtoYZ() | :normal `.
它可以工作,但是我感觉这不是很流行。如果光标返回到发出XtoYZ命令之前的位置(当前行至第二个插入行的开头),则奖励点。
您不需要执行此操作的函数,宏就可以满足您的要求。您也可以根据需要在vimrc中定义一个宏,以便每次打开vim时都可以使用它。
这是宏:
qqv<Esc>Y2p:s/x/y/gi<Enter>n:s//z/gi<Enter>`<q
因此已将其记录并保存在register中q
,您可以@q
重播它。
解释一下:
qq " start recording into q
v<esc> " enter visual mode and exit. to let `< work
Y2p " yank current line and paste twice below
:s/x/y/gi<Enter> " x->y sub, case insensitive
n " go to next x (here we could use j too)
:s//z/gi<Enter> " do another sub x->z
`< " back to the old cursor position
q " end recording
如果要X->Y
和x->y
,只需删除该i
标志并再添加两个:s
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句