I wish to integrate the source code formatter Uncrustify with Vim. Any of the below two options will suffice.
gq
is pressed). Option 1 is preferable. I tried
set formatprg=uncrustify\ -c ~/misc/uncrustify.cfg --no-backup
ie 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.
Have you tried escaping whitespaces:
:set formatprg=uncrustify\\ -c\\ ~/misc/uncrustify.cfg\\ --no-backup
UPDATE
uncrustify
prints "Parsing: 170 bytes ..." message to stderr so we need to redirect it to /dev/null
:
:set formatprg=uncrustify\\ -c\\ ~/misc/uncrustify.cfg\\ -l\\ CPP\\ --no-backup\\ 2>/dev/null
gq
operates on lines, so you can select necessary lines in visual mode and execute gq
. For example, if you want to reformat whole file execute ggVGgq
.
More info at :help gq
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.