function! ReName()
let old_name = expand("<cword>")
let new_name = input("new name: ",old_name)
let cmd = "ref.sh ".expand(old_name).expand(" ").expand(new_name)
:call system(cmd)
endfunction
ref.sh is a bash file, context is
#! /bin/bash
find . -name '*.[ch]' | xargs sed -i s/$1/$2/g
but now, when i use ReName function in vim, it does not work.
Well, what do you expect it to do, and what / where is the error?
First of all, you ignore the output from the call to system()
. If there is output, either use :echo
instead of :call
, assign it to a variable, or :return
it. Otherwise, check the v:shell_error
variable for the exit status of the command.
Some more critiques: Instead of
let cmd = "ref.sh ".expand(old_name).expand(" ").expand(new_name)
leave out the superfluous expand()
:
let cmd = "ref.sh ".old_name." ".new_name
or assemble the command via printf()
:
let cmd = printf("ref.sh %s %s", old_name, new_name)
Your function will only work for certain, well-behaved arguments. Use shellescape()
in Vim, and proper quoting in your shell script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With