每天一个vim小技巧[1] - 重复段落的复制,标号的递增

1. 重复段落的复制-使用macro

需求:重复line193-194指定次
image

q # 录制macro
a # assign an alias
Shift+V # at line 293, enable visual-line
j # select line 294
y # yank selected
j # jump to line 294
p # paste buffer
q # end record

To invoke a vim macro,

@a

指定20次,

20@a

image
VIM会将其重复20次。

2. 递增数字

需求:将when标号改为递增数字

q
w
<C-a>
j
<C-a>
q

其中,<C-a>是Ctrl+A,<C-x>是vim用来递减数字的快捷键。

类似的,可以使用

3@w

来递增3次。
image

3. 递增数字的另一个示例

这里有一个额外的示例,when的标号是相同的。

image

处理方式如下

qa
yiw
j
viwp
<C-a>
q

invoke N@a to repeate N times.

You can use relative line number to determine the value of N.

set rnu
set nornu

For more convenient, you can assign a key binding for them.

Add these lines to your .vimrc for VIM or init.vim for Neovim.

map <LEADER>m :set rnu<CR>
map <LEADER>m :set nornu<CR>

4. 一段数字整体+N

Visual-Block 选中,

N<C-A>
posted @ 2023-05-16 15:45  devindd  阅读(190)  评论(0编辑  收藏  举报