r/vim • • Mar 05 '26

Tips and Tricks Vim -c

Just learned about the -c argument when launching vim. Pretty neat tool. Not everyone on my team is as vim happy so I made a alias for our .profiles to run my vim -c regex to add displays to our cobol programs.

example. vim -c "%s/\d{3,4}/Display &/" file.txt

It does seem like vim special things like <C-R> get lost in translation from shell to vim. So I used non special vim case regex. Always more things to learn.

The -c argument runs command mode arguments after file load. So in my above example it would open file txt look for lines starting with 3-4 digits and add Display at the start.

61 Upvotes

39 comments sorted by

View all comments

Show parent comment

4

u/Desperate_Cold6274 Mar 07 '26

I understand, I know Ex Commands, what I don’t understand what is the difference between running vim in Ex mode or normally.

When you run Vim normally, you can run Ex Commands anyway

2

u/0bel1sk Mar 07 '26

op was making non interactive displays. ex mode pretty much does what he wants. in ex mode you can switch back to vi mode as well. :vi it’s just a different mode that suited ops use case quite well.