Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format code with VIM using external commands

Tags:

vim

I know that using VIM I can format C++ code just using

gg=G

Now I have to format 30 files, so doing it by hand becomes tedious. I had a look how to do it passing external commands to VIM, so I tried

vim -c gg=G -c wq file.cpp

but it does not work.

Can you give me a hint?

Thanks

like image 849
Open the way Avatar asked Jan 23 '26 00:01

Open the way


2 Answers

Why not load all the files up in buffers and use bufdo to execute the command on all of them at one time?

:bufdo "execute normal gg=G"
like image 165
michaelmichael Avatar answered Jan 25 '26 00:01

michaelmichael


Change -c gg=G to -c 'normal! gg=G'. -c switch accepts only ex mode commands, gg=G are two normal mode commands.

like image 39
ZyX Avatar answered Jan 25 '26 02:01

ZyX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!