I want to validate that my ~/.vimrc
file is correct, basically just by launching vim
and immediately running quit
. I can almost do this with vim -c quit
, except that I have to press the enter key. For example,
> cat ~/.vimrc
echoerr 'test'
> vim -c quit
Error detected while processing /home/josh/.vimrc:
line 1:
test
Press ENTER or type command to continue
Is there a way to do this without pressing enter? I guess I could just run echo | vim -c quit
, but I was hoping there was a more elegant solution.
Best Answer
You can use a try-catch block to catch errors (which get converted to exceptions), and fail on any exception:
From the help:
And from
:echoerr
:Other notes:
-u NONE
prevents sourcing the default vimrcs:cq
makes Vim return a non-zero exit statusTo get the last error message (now actually an exception), use
v:exception
: