[HOLER]VI中执行shell命令

vi中执行shell命令
    在vi中也可以执行shell的命令。在line mode下执行指令!command, command 是 shell 命令。例如指令 !date 会把目前的时间和日期显示到屏幕上。
要是你想把 shell 命令的结果放到文件中,可以用 r !command。比如 r !date 会把现在的时间插入到游标所在行的下一行。可以指定行数,例如 20r !date 会把現在的时间放到第二十一行。
如果你想要执行一连串的的 shell命令但又不想离开vi,你可以在line mode下指令sh。这个指令会建立一个 shell,如果要离开,按【 ctrl-D 】,或者执行exit命令。
你也可以选择文档中的文字作为 shell 命令的输入。输出的结果会替换掉你输入的文字。例如 2,5!sort 会把第二列到第五列的文字依序排列,而原来的文字就会被覆盖。
 
实战:
#vi dosh.txt
 1       Love Ain’t Wait For You
 2       S Club 7
 3   Your heart beat's taking over
 4   And there's nowhere you can go
 5   And the love that you discover
 6   Is finally taking hold
 7   When it feels like the beginning
 8   And the story will unfold
 9   There's a time to take your chances
10   Don't be scared of the unknown
11   Cause you can't fight it
12   Don't deny it
13   Love is stronger than each other
14   Show me baby
15   What you're gonna do, do
16   Love ain't gonna wait for you
18   Love ain't gonna wait for you
 
执行
:1,5!sort
 
 1       Love Ain’t Wait For You
 2       S Club 7
 3   And the love that you discover
 4   And there's nowhere you can go
 5   Your heart beat's taking over
 6   Is finally taking hold
 7   When it feels like the beginning
 8   And the story will unfold
 9   There's a time to take your chances
10   Don't be scared of the unknown
11   Cause you can't fight it
12   Don't deny it
13   Love is stronger than each other
14   Show me baby
15   What you're gonna do, do
16   Love ain't gonna wait for you
17   Don't run, don't hide
18   Love ain't gonna wait for you
 
执行
:2r!date
 
 
1       Love Ain’t Wait For You
2       S Club 7
3 2007 年07月05日 星期四 16时29分48秒 CST
4   And the love that you discover
5   And there's nowhere you can go
 
注:文件内容前的数组为行号(:set nu)。
 
holer
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值