VIM TIP28
VimTip 28: add a line-number to every line without cat or awk alike utilities.
不使用cat或awk等在添加每行都添加行号
With Unix-like environment, you can use cat or awk to generate a line number easily, because vim has a friendly interface with shell, so everything work in vim as well as it does in shell.
在类Unix环境下,你可以轻松的使用cat或awk产生行号,因为vim与shell有友好的接口,所以同样可以在vim中执行shell中的操作。
:%!call -n
or
:%!awk '{print NR,$0}'
But, if you use vim in MS-DOS, of win9x, win2000, you loss these tookit.here is a very simple way to archive this only by vim:
但是,如果你在MS的系统下,你将无法使用这些工具。下边是仅靠vim来实现上述功能的方法:
Well, a sequence composed with alphabet is as easy as above:
那么,压缩为一行包括同样简单:
exe "s/^/".nr2char(line("."))."/"
Technorati Tags: VI, EDITOR
不使用cat或awk等在添加每行都添加行号
With Unix-like environment, you can use cat or awk to generate a line number easily, because vim has a friendly interface with shell, so everything work in vim as well as it does in shell.
在类Unix环境下,你可以轻松的使用cat或awk产生行号,因为vim与shell有友好的接口,所以同样可以在vim中执行shell中的操作。
:%!call -n
or
:%!awk '{print NR,$0}'
But, if you use vim in MS-DOS, of win9x, win2000, you loss these tookit.here is a very simple way to archive this only by vim:
但是,如果你在MS的系统下,你将无法使用这些工具。下边是仅靠vim来实现上述功能的方法:
fu! LineIt()
exe ":s/^/".line(".")."/"
endf
Well, a sequence composed with alphabet is as easy as above:
那么,压缩为一行包括同样简单:
exe "s/^/".nr2char(line("."))."/"
Technorati Tags: VI, EDITOR
Comments