免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1748 | 回复: 0
打印 上一主题 下一主题

vi中执行shell命令 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-07-05 16:39 |只看该作者 |倒序浏览
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]VI中执行shell命令.rar
大小:
4KB
下载:
下载

holer
holeryu@hotmail.com
http://holeryu.cublog.cn/
http://blog.csdn.net/holeryu/



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/16991/showart_334929.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP