Reputation: 13143
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?
Upvotes: 1
Views: 472
Reputation: 2541
You might also want to check out the increment package here. If you have a block of text,
test
test
test
test
test
test
test
test
test
test
test
You can select the 't' on the first line, and enter visual block mode using Ctrl-V
. Select until the last line, then enter insert mode with I
. Enter the number '1' plus a space, and hit escape to leave visual block mode. You'll then have a 1 before each line:
1 test
1 test
1 test
1 test
1 test
1 test
1 test
1 test
1 test
1 test
1 test
Next, highlight all of the 1's in visual block mode again, and type :Inc<CR>
. This will increment the numbers, essentially numbering your lines in text:
1 test
2 test
3 test
4 test
5 test
6 test
7 test
8 test
9 test
10 test
11 test
Upvotes: 2
Reputation: 111229
You can pass the file through a program that numbers the lines, for example cat
:
:%!cat -n
To number only some lines, first select the lines in visual mode (command V) and then type :. The prompt changes into :'<,'>
and you can type the rest of command !cat -n
. The full command is:
:'<,'>!cat -n
Upvotes: 8