网上看的,比较有用
vim -e -s -c ":%s/old/new/g" -c ":wq" urfile
同理
vim -e -s -c ":1,$s/old/new/g" -c ":wq" urfile
-e Start Vim in Ex mode, just like the executable was called "ex".
-s Silent mode. Only when started as "Ex" or when the "-e" option was given before the "-s" option.
-c {command}
{command} will be executed after the first file has been read. {command} is interpreted as an Ex
command. If the {command} contains spaces it must be enclosed in double quotes (this depends on
the shell that is used). Example: Vim "+set si" main.c
Note: You can use up to 10 "+" or "-c" commands.
ex +:%s/old/new/g +:wq urfile
同理,这样也可以解决
在脚本里面非常有效
Vim behaves differently, depending on the name of the command (the executable may still be the same file).
vim The "normal" way, everything is default.
ex Start in Ex mode. Go to Normal mode with the ":vi" command. Can also be done with the "-e" argu-
ment.
view Start in read-only mode. You will be protected from writing the files. Can also be done with the
"-R" argument.
:g/keyword/d ----把含有keyword的行删除
如
:g/^$/d
就是把空行删除
阅读(628) | 评论(0) | 转发(0) |