Reputation: 1920
Let's say I have a file "edit_commands" with some editing commands, like:
:1,$s/good/better/g
:1,$s/bad/worse/g
Is there a way to let vi load and run the commands in "edit_commands"?
Update: It appears the "-S" option can be used for this. Refer to: How to run a series of vim commands from command prompt
Upvotes: 6
Views: 124
Reputation: 3053
It seems like you would want to use a program like sed which shares a common ancestor with vi (i.e. the 'ed' editor) for such a task:
sed -i 's/good/better/g; s/bad/worse/g' your_file
See this great sed tutorial.
Is there a reason you need to use vi to do it? You could use perl if you need more advanced regex capabilities.
Upvotes: 4
Reputation: 364
The solution in Perl may look this way:
perl -i.old -pe 's/good/better/g || s/bad/worse/g' your_file
The -i.old
option saves a copy of your old file under the name your_file.old
, what can be very useful when bad comes to worse and worse comes to worst...
Upvotes: 3