1

I know about displaying line numbers in Vim using :set nu but what I really want is to make those line numbers the actual contents of the file , preferably only some part of the file. fancy and works outside vim cat -n fileName >> fileName.numbers . Any suggestions to make it work inside Vim?

4

2 回答 2

8

您可以通过对行编号的程序传递文件,例如cat

:%!cat -n

要仅对某些行编号,请首先在可视模式(命令V)中选择行,然后键入:。提示变为:'<,'>,您可以键入命令的其余部分!cat -n。完整的命令是:

:'<,'>!cat -n
于 2013-08-11T13:53:29.060 回答
2

您可能还想在此处查看增量包。如果你有一个文本块,

test
test
test
test
test
test
test
test
test
test
test

您可以选择第一行的“t”,然后使用 进入可视块模式Ctrl-V。选择直到最后一行,然后使用 进入插入模式I。输入数字“1”加一个空格,然后按 Escape 退出视觉块模式。然后,您将在每行之前有一个 1:

1 test
1 test
1 test
1 test
1 test
1 test
1 test
1 test
1 test
1 test
1 test

接下来,再次突出显示可视块模式中的所有 1,然后键入:Inc<CR>。这将增加数字,本质上是对文本中的行进行编号:

 1 test
 2 test
 3 test
 4 test
 5 test
 6 test
 7 test
 8 test
 9 test
10 test
11 test
于 2013-08-12T17:54:22.307 回答