我想包装一些代码:
myObj.text;
Run Code Online (Sandbox Code Playgroud)
使用函数调用将代码作为参数传递.
console.log(myObj.text);
Run Code Online (Sandbox Code Playgroud)
我曾考虑使用surround.vim来做到这一点,但没有设法做到这一点.
有没有想过是否可能?一世
环绕声处于正常模式:
ysiwfconsole.log<CR>
Run Code Online (Sandbox Code Playgroud)
在可视模式下使用Surround:
Sfconsole.log<CR>
Run Code Online (Sandbox Code Playgroud)
在正常模式下没有环绕声:
ciwconsole.log(<C-r>")<Esc>
Run Code Online (Sandbox Code Playgroud)
在视觉模式下没有环绕声:
cconsole.log(<C-r>")<Esc>
Run Code Online (Sandbox Code Playgroud)
但那不是很容易扩展.映射肯定会更有用,因为您几乎肯定需要经常这样做:
xnoremap <key> cconsole.log(<C-r>")<Esc>
nnoremap <key> ciwconsole.log(<C-r>")<Esc>
Run Code Online (Sandbox Code Playgroud)
我知道并使用两种不同的方法来实现这一目标:
选择要在视觉模式下换行的文本(点击v后进行任何适当的移动)。
通过点击替换c该文本,然后键入您的函数调用console.log()。(旧文本并没有消失,它只是移到了一个寄存器中,在步骤 3 中将立即从该寄存器中检索它。)<esc>当您在右括号后面时点击,这将使您留在该)字符上。
通过点击将替换的文本粘贴到括号中P(这将插入到当前所在的字符之前,因此就在 和 之间())。
整个序列是v<movement>c<functionName>()<esc>P.
除了离开插入模式并从正常模式粘贴之外,您还可以通过点击<ctrl>R后直接从插入模式粘贴"。
整个序列是v<movement>c<functionName>(<ctrl>R")<esc>.