I wish to integrate the source code formatter Uncrustify with Vim. Any of the below two options will suffice.
- Format the code that I am currently editing (i.e. when
gq
is pressed). - Format the code when I save the file and then reload the formatted file into current Vim window.
Option 1 is preferable. I tried
set formatprg=uncrustify\ -c ~/misc/uncrustify.cfg --no-backup
i.e. I call Uncrustify with command line options.
This does not work. Vi gives the E518: Unknown option: ~/misc/uncrustify.cfg
error.
For option 2, I tried the following in the vimrc file
autocmd bufwritepost *.cpp ! ~/bin/uncrustify -c ~/misc/uncrustify.cfg --no-backup <afile>
The file is formatted after the save, but I have to manually reload the file into Vim.