Mar*_*man 22 vim macros repeat
在Vim中,我通常希望有时重复一些命令.说,我想评论5行,我会用
I//<Esc>j
.j.j.j.j
Run Code Online (Sandbox Code Playgroud)
有没有办法多次重复最后一个".j"部分?
Gre*_*ill 34
一种方法是将键序列分配给宏,然后运行宏一次,然后运行@@run-last-macro命令.例如:
qa.jq@a@@
Run Code Online (Sandbox Code Playgroud)
如果您知道要重复宏的次数,可以使用4@@或其他.
too*_*php 14
您可以直观地选择要重复的行,键入:normal! .以.在每行上使用vim .因为您从视觉选择开始,它最终看起来像这样:
:'<,'>normal! .
Run Code Online (Sandbox Code Playgroud)
但是,如果您添加和删除//注释很多,您可能会发现以下映射很有用:
" add // comment with K
noremap K :s,^\(//\)\=,//,e <BAR> nohls<CR>j
" remove // comment with CTRL+K
noremap <C-K> :s,^//,,e <BAR> nohls<CR>j
Run Code Online (Sandbox Code Playgroud)
你可以5K用来评论5行,你可以使用视觉模式首先选择你的行,或者你可以K直到你评论你想要的一切.
关于您的具体示例,我更喜欢使用可视块模式进行多行插入(使用访问Ctrl-v).例如,如果我有以下几行:
This should be a comment.
So should this.
This is definitely a comment.
Is this a comment? Yes.
Run Code Online (Sandbox Code Playgroud)
我会转到顶行的第一个顶部字符,点击Ctrl-v进入视觉模块模式,导航到最后一行(可能使用3j向下移动3行,也许使用4g直接转到第4行,或者可能只是G为了结束),然后键入I// <esc>以立即在所有行上插入注释:
// This should be a comment.
// So should this.
// This is definitely a comment.
// Is this a comment? Yes.
Run Code Online (Sandbox Code Playgroud)
此外,还有一个支持多语言的一个非常方便的评论员/非评议插件这里.它比手动插入/删除注释更容易.