I would like to define a mapping in vim that looks for a special place in the file (using a regular expression) and executes an external command that depends on the matched pattern. That is, I am thinking of something like:
:g/set\ "\(.*\)"/!echo 'bla '\1' blubb' > file
or
:g:set\ "\(.*\)":call system("echo 'bla ". submatch(0) ." blubb' > file")
My goal here is to look for a line like
set "x=3"
and create a new file with the contents:
bla x=3 blubb
Unfortunately, both attempts (and several others) do not work. Thank!
Edit: adding the following to my .vimrc did not help either:
:map <F4> :g:set\ "\(.*\)":call Gnutex(submatch(1))
function Gnutex(str)
return system("echo 'bla ". a:str ." blubb' > file")
endfunction
Edit: Working solution (along with the function from earlier):
:% s/set\ output\ "\(.*\)"/\=[submatch(0), Gnutex(submatch(1))][0]/
I think there are better solutions, but it worked.
source
share