VIM中的recording ( using recording in VIM )

访问量: 1495

recording 是一个高级功能,对于我来说。所以我一直没有学习哈哈。前天又做了一件人肉替换字符串的事儿,我觉得实在不能再忍了,于是今天早上使用了一下,感觉良好。 (Recording is an advanced feature in VIM and I am too busy these days, so I haven't paid any time on it. However the day before yesterday, I have to do a job that containing of many duplicated operations which could & should be done automatically. So I make my decision to learn how to use this feature) 

这个例子是: 把一个文本中的某个字,做一些替换。工作量呢,用人肉做不小,但是专门写个ruby脚本又显得过度重量了。(this example shown below is the case I met -- change some string by some patterns -- a Ruby script is too heavyweight, but manually doing it is too boring... so  ... ^_^)

把这段代码:

  link1
  link2
  link3

替换成下面:

link1

link2
link3

所以,使用 VIM 的recording 正好,步骤是:  ( so the steps are: ) 

1. 在普通模式下 按qq ( q<寄存器名> , 这里我为了方便,使用了 q )   ( press 'qq' in normal mode ) 

2. 开始编辑。 (edit it) 

3. 编辑好后,回到普通模式,再次按下 q . 表示录制结束  ( press 'q' again when you have done the edit in normal mode) 

4. 跳到第二行,然后按 @+q,  就会发现,第二行变化啦~ ( jump to the line you want to make changes and press '@q', see what happens~ )

5. 引申: 如果想一次操作多行,输入 5@q, 就可以操作接下来的5行哦亲~  (further more, press 'n@q' to apply the changes on the following n lines ) 

订阅/RSS Feed

Subscribe

分类/category