On Sat, 20 May 2006, Tim Chase wrote:
I don't really know how to do this but im sure that there's a
solution. I have some file and i need to insert a number
before each line and a separator. The number is the line
number. Is there any way in vim to do this easily?
Well, the canonical way to do this on *nix boxes is just
cat -n file.in > file.out
which can be used in vim with
:%!cat -n
[snip]
I see that Tim and Tony have both mentioned most of the ways of
inserting a number before each line. One more alternative: if you are on
a *nix box, the premier tool for doing this job is "nl". Check out 'man
nl'.
It lets you set the start number, increment amount, separator string,
number column width, empty-line skip, left/right justification with
optional leading zeros.
For example,
:%!nl -s" " -w4 -v7 -i2 -nln -ba
This will use
a 2-space separator
column width of 4
start with number 7
increment by 2
left justified
for all lines (don't skip empty lines)
HTH :)
--
Gerald