Tem*_*ora 2 vim search replace ed
我想在给定文件上执行一系列"搜索和替换",比如file.txt.例如,
s/foo/bar/g
s/abc/xyz/g
s/pqr/lmn/
g/string-delete/d
Run Code Online (Sandbox Code Playgroud)
等等.
我是如何在脚本文件中编写所有这些操作,然后在目标file.txt上单独运行它们以将其保存到newfile.txt?
我看到这篇文章使用bash/sed搜索和替换文件中的变量,但不知何故无法让它为我工作.
编辑:我更喜欢基于vim/ed的解决方案Thanx tempora
使用:source {file}运行Vim脚本.
将命令保存到文件中,例如commands.vim.然后打开要将命令应用到的源缓冲区并将其源commands.vim化为:
:so commands.vim
Run Code Online (Sandbox Code Playgroud)
注意::so是简称:source
有关更多帮助请参阅:
:h :so
Run Code Online (Sandbox Code Playgroud)