Tuesday, April 24, 2012

Re: How I can run vim commands from a bash script?

On Tue, 2012-04-24 at 04:51 -0700, Antonio Recio wrote:
> Oups, you are right I have forgotten the filename:
> for i in *.txt; do vim $i "%s/foo/bar/g"; done
>
> Now it opens each txt file but it doesn't replace or save them.
>

How about trying to save and quit as well in the command. Although not
the preferred way but something like this should work :
vim $i -c "s/foo/bar/|w|q"
or
vim $i -c "silent! s/foo/bar/|w|q"

If you simply want to replace pattern in files, why not use sed.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment