Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用sed命令用Vim替换多个文件中的字符串_Vim - Fatal编程技术网

使用sed命令用Vim替换多个文件中的字符串

使用sed命令用Vim替换多个文件中的字符串,vim,Vim,我想使用call:Rep(new,old)将旧字符串替换为新字符串。所以我的伪代码是这样的 我是vimscript新手,我不知道怎么做 function! Rep(old,new) !sed -i.bak 's/#{old}/#{new}/g' * endfunction 你知道吗? 谢谢。将您的功能更改为 function! Rep(old,new) exe "!sed -i.bak 's/".a:old."/".a:new."/g' *" endfunction 然后使用:呼

我想使用call:Rep(new,old)将旧字符串替换为新字符串。所以我的伪代码是这样的

我是vimscript新手,我不知道怎么做

function! Rep(old,new)
   !sed -i.bak 's/#{old}/#{new}/g' *
endfunction
你知道吗?
谢谢。

将您的功能更改为

function! Rep(old,new)
   exe "!sed -i.bak 's/".a:old."/".a:new."/g' *"
endfunction
然后使用
:呼叫代表(旧的、新的)
。还可以为其创建命令

command! -nargs=+ Rep call Rep(<args>)
命令-nargs=+Rep call Rep()
这样您就可以执行
:重复旧的新的