Macro for making numbered lists in vim?

后端 未结 7 1941
渐次进展
渐次进展 2021-02-12 03:40

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

Which shoul

相关标签:
7条回答
  • 2021-02-12 04:46

    Maybe it's not a macro solution, but at least it's easy.

    add numbers to all lines

    It's possible to use :%!nl -ba or :%!cat -n commands which will add line numbers to all the lines.

    On Windows, you've to have Cygwin/MSYS/SUA installed.

    add numbers to selected lines

    To add numbers only for selected lines, please select them in visual mode (v and cursors), then when finished - execute the command: :%!nl (ignore blank lines) or :%!cat -n (blank lines included).

    formatting

    To remove extra spaces, select them in visual block (Ctrl+v) and remove them (x).

    To add some characters (., :, )) after the numbers, select them in visual block (Ctrl+v), then append the character (A, type the character, then finish with Esc).

    0 讨论(0)
提交回复
热议问题