每行增加行号

Vim、Emacs配置和使用
回复
罗非鱼
帖子: 980
注册时间: 2008-04-12 12:44

每行增加行号

#1

帖子 罗非鱼 » 2013-05-26 15:36

对一个文本的每行开头增加一个行号

:%s/^/\=line(".")/

% 代表所有行
s 代表替换
^ 行头
请问 这个 \= 里面的 \ 符号,是表达转义的含义吗?

line函数里面的 (".") "." 是什么含义?看了帮助手册也没有懂。
line({expr}) The result is a Number, which is the line number of the file
position given with {expr}. The accepted positions are:
. the cursor position
$ the last line in the current buffer
'x position of mark x (if the mark is not set, 0 is
returned)
w0 first line visible in current window
w$ last line visible in current window
v In Visual mode: the start of the Visual area (the
cursor is the end). When not in Visual mode
returns the cursor position. Differs from |'<| in
that it's updated right away.
Note that a mark in another file can be used. The line number
头像
lilydjwg
论坛版主
帖子: 4250
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 每行增加行号

#2

帖子 lilydjwg » 2013-05-26 20:24

说得很清楚了,代表当前行啊。
头像
yjcong
帖子: 2470
注册时间: 2006-02-28 3:11

Re: 每行增加行号

#3

帖子 yjcong » 2013-05-26 20:51

nl file_input > file_output

??
一梦三年,
松风依旧,
萝月何曾老.


灵幽听微, 谁观玉颜?
灼灼春华, 绿叶含丹.
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 每行增加行号

#4

帖子 eexpress » 2013-05-26 22:19

擦,居然还有nl
● 鸣学
wangjun403
帖子: 433
注册时间: 2009-07-06 14:26

Re: 每行增加行号

#5

帖子 wangjun403 » 2013-05-27 9:04

又多了个爱学习的童靴
生命只不过是上帝借你一用的资本!
头像
oneleaf
论坛管理员
帖子: 10441
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04

Re: 每行增加行号

#6

帖子 oneleaf » 2013-05-27 9:12

eexpress 写了:擦,居然还有nl
头像
枫叶饭团
帖子: 14683
注册时间: 2010-06-16 1:05
系统: Mac OS X
来自: Tencent
联系:

Re: 每行增加行号

#7

帖子 枫叶饭团 » 2013-05-27 9:27

nl也是命令?powershell里没有 :em02
头像
tpli
帖子: 250
注册时间: 2007-01-16 16:14
来自: 郑州

Re: 每行增加行号

#8

帖子 tpli » 2013-05-27 9:30

nl貌似不行的..
xhm@xhmdeb:~$ cat usecontext
/home/xhm/context/tex/setuptex

export OSFONTDIR=/home/xhm/font/context

mtxrun --script fonts --reload

xhm@xhmdeb:~$
xhm@xhmdeb:~$ nl usecontext > nlout
xhm@xhmdeb:~$ cat nlout
1 /home/xhm/context/tex/setuptex

2 export OSFONTDIR=/home/xhm/font/context

3 mtxrun --script fonts --reload

xhm@xhmdeb:~$
头像
oneleaf
论坛管理员
帖子: 10441
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04

Re: 每行增加行号

#9

帖子 oneleaf » 2013-05-27 10:13

代码: 全选

nl -ba usecontext
罗非鱼
帖子: 980
注册时间: 2008-04-12 12:44

Re: 每行增加行号

#10

帖子 罗非鱼 » 2013-05-27 16:47

. the cursor position,光标的位置,那么" " ,这里的引号是什么意思呢?
头像
tpli
帖子: 250
注册时间: 2007-01-16 16:14
来自: 郑州

Re: 每行增加行号

#11

帖子 tpli » 2013-05-27 17:12

oneleaf 写了:

代码: 全选

nl -ba usecontext
thx,
忘记man了...
回复