用于在vim中创建编号列表的宏? [英] Macro for making numbered lists in vim?

查看:66
本文介绍了用于在vim中创建编号列表的宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,我似乎有一个项目列表,并且需要在它们前面添加数字.例如:

Often times it seems I have a list of items, and I need to add numbers in front of them. For example:

Item one
Item two
Item three

应为:

1. Item one
2. Item two
3. Item three

在vim中,我可以在编辑模式下按I,插入"1.",然后按Escape键.然后我转到下一行,按.,然后按^A以增加数字.这似乎效率很低……我将如何创建一个宏,以便转到下一行,并在开头插入一个比前一行大一个数字的数字?

In vim, I can press I in edit mode, insert "1.", hit escape. Then I go to the next line, press ., and then ^A to increment the number. This seems hugely inefficient... how would I make a macro so that I can go to the next line, and insert a number at the beginning which is one greater than the line before?

推荐答案

您可以轻松地记录一个宏来完成它.

You can easily record a macro to do it.

首先在第一行的开头插入1.(在1.之后有几个空格,但看不到它们).

First insert 1. at the start of the first line (there are a couple of spaces after the 1. but you can't see them).

转到第二行的开头,并使用qa进入记录模式.

Go to the start of the second line and go into record mode with qa.

按以下键序列:

i                         # insert mode
<ctrl-Y><ctrl-Y><ctrl-Y>  # copy the first few characters from the line above  
<ESC>                     # back to normal mode
|                         # go back to the start of the line
<ctrl-A>                  # increment the number
j                         # down to the next line
q                         # stop recording

现在,您可以使用@a回放录音(第一次;对于以后的时间,您可以执行@@重复最后执行的宏),并且它将在每个开始处添加一个新的递增编号.线.

Now you can play back the recording with @a (the first time; for subsequent times, you can do @@ to repeat the last-executed macro) and it will add a new incremented number to the start of each line.

这篇关于用于在vim中创建编号列表的宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆