Validate `~/.vimrc`
Clash Royale CLAN TAG#URR8PPP
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.
vim vimrc
add a comment |
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.
vim vimrc
add a comment |
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.
vim vimrc
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.
vim vimrc
vim vimrc
edited Jan 21 at 10:24
mosvy
7,3191529
7,3191529
asked Jan 21 at 7:07
Joshua SpenceJoshua Spence
1434
1434
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use a try-catch block to catch errors (which get converted to exceptions), and fail on any exception:
$ cat vimrc-fail
echoerr 'test'
$ cat vimrc-pass
echo 'test'
$ vim -u NONE -c 'try | source vimrc-pass | catch | cq | endtry | q'; echo $?
0
$ vim -u NONE -c 'try | source vimrc-fail | catch | cq | endtry | q'; echo $?
1
From the help:
:try :try :endt :endtry E600 E601 E602
:endt[ry] Change the error handling for the commands between
":try" and ":endtry" including everything being
executed across ":source" commands, function calls,
or autocommand invocations.
And from :echoerr
:
When used inside a try conditional, the message is raised as an error exception instead (see try-echoerr).
Other notes:
-u NONE
prevents sourcing the default vimrcs:cq
makes Vim return a non-zero exit status
To get the last error message (now actually an exception), use v:exception
:
$ vim -u NONE -c 'try | source vimrc-fail | catch | silent exec "!echo " shellescape(v:exception) |cq | endtry | q'; echo $?
Vim(echoerr):test
1
Thanks! Is there a way to echo the error message as well?
– Joshua Spence
Jan 21 at 23:11
@JoshuaSpence I think the last exception is stored inv:exception
. Maybe something likeexec "!echo " shellescape(v:exception) | cq
instead of the plaincq
would work.
– Olorin
Jan 22 at 1:10
That almost works... it requires me to press enter though.
– Joshua Spence
Jan 22 at 3:56
Ok, it works if I runvim
with-E
and-s
– Joshua Spence
Jan 22 at 4:11
silent exec
should fix the Enter problem.
– Olorin
Jan 22 at 4:37
|
show 1 more comment
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495721%2fvalidate-vimrc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use a try-catch block to catch errors (which get converted to exceptions), and fail on any exception:
$ cat vimrc-fail
echoerr 'test'
$ cat vimrc-pass
echo 'test'
$ vim -u NONE -c 'try | source vimrc-pass | catch | cq | endtry | q'; echo $?
0
$ vim -u NONE -c 'try | source vimrc-fail | catch | cq | endtry | q'; echo $?
1
From the help:
:try :try :endt :endtry E600 E601 E602
:endt[ry] Change the error handling for the commands between
":try" and ":endtry" including everything being
executed across ":source" commands, function calls,
or autocommand invocations.
And from :echoerr
:
When used inside a try conditional, the message is raised as an error exception instead (see try-echoerr).
Other notes:
-u NONE
prevents sourcing the default vimrcs:cq
makes Vim return a non-zero exit status
To get the last error message (now actually an exception), use v:exception
:
$ vim -u NONE -c 'try | source vimrc-fail | catch | silent exec "!echo " shellescape(v:exception) |cq | endtry | q'; echo $?
Vim(echoerr):test
1
Thanks! Is there a way to echo the error message as well?
– Joshua Spence
Jan 21 at 23:11
@JoshuaSpence I think the last exception is stored inv:exception
. Maybe something likeexec "!echo " shellescape(v:exception) | cq
instead of the plaincq
would work.
– Olorin
Jan 22 at 1:10
That almost works... it requires me to press enter though.
– Joshua Spence
Jan 22 at 3:56
Ok, it works if I runvim
with-E
and-s
– Joshua Spence
Jan 22 at 4:11
silent exec
should fix the Enter problem.
– Olorin
Jan 22 at 4:37
|
show 1 more comment
You can use a try-catch block to catch errors (which get converted to exceptions), and fail on any exception:
$ cat vimrc-fail
echoerr 'test'
$ cat vimrc-pass
echo 'test'
$ vim -u NONE -c 'try | source vimrc-pass | catch | cq | endtry | q'; echo $?
0
$ vim -u NONE -c 'try | source vimrc-fail | catch | cq | endtry | q'; echo $?
1
From the help:
:try :try :endt :endtry E600 E601 E602
:endt[ry] Change the error handling for the commands between
":try" and ":endtry" including everything being
executed across ":source" commands, function calls,
or autocommand invocations.
And from :echoerr
:
When used inside a try conditional, the message is raised as an error exception instead (see try-echoerr).
Other notes:
-u NONE
prevents sourcing the default vimrcs:cq
makes Vim return a non-zero exit status
To get the last error message (now actually an exception), use v:exception
:
$ vim -u NONE -c 'try | source vimrc-fail | catch | silent exec "!echo " shellescape(v:exception) |cq | endtry | q'; echo $?
Vim(echoerr):test
1
Thanks! Is there a way to echo the error message as well?
– Joshua Spence
Jan 21 at 23:11
@JoshuaSpence I think the last exception is stored inv:exception
. Maybe something likeexec "!echo " shellescape(v:exception) | cq
instead of the plaincq
would work.
– Olorin
Jan 22 at 1:10
That almost works... it requires me to press enter though.
– Joshua Spence
Jan 22 at 3:56
Ok, it works if I runvim
with-E
and-s
– Joshua Spence
Jan 22 at 4:11
silent exec
should fix the Enter problem.
– Olorin
Jan 22 at 4:37
|
show 1 more comment
You can use a try-catch block to catch errors (which get converted to exceptions), and fail on any exception:
$ cat vimrc-fail
echoerr 'test'
$ cat vimrc-pass
echo 'test'
$ vim -u NONE -c 'try | source vimrc-pass | catch | cq | endtry | q'; echo $?
0
$ vim -u NONE -c 'try | source vimrc-fail | catch | cq | endtry | q'; echo $?
1
From the help:
:try :try :endt :endtry E600 E601 E602
:endt[ry] Change the error handling for the commands between
":try" and ":endtry" including everything being
executed across ":source" commands, function calls,
or autocommand invocations.
And from :echoerr
:
When used inside a try conditional, the message is raised as an error exception instead (see try-echoerr).
Other notes:
-u NONE
prevents sourcing the default vimrcs:cq
makes Vim return a non-zero exit status
To get the last error message (now actually an exception), use v:exception
:
$ vim -u NONE -c 'try | source vimrc-fail | catch | silent exec "!echo " shellescape(v:exception) |cq | endtry | q'; echo $?
Vim(echoerr):test
1
You can use a try-catch block to catch errors (which get converted to exceptions), and fail on any exception:
$ cat vimrc-fail
echoerr 'test'
$ cat vimrc-pass
echo 'test'
$ vim -u NONE -c 'try | source vimrc-pass | catch | cq | endtry | q'; echo $?
0
$ vim -u NONE -c 'try | source vimrc-fail | catch | cq | endtry | q'; echo $?
1
From the help:
:try :try :endt :endtry E600 E601 E602
:endt[ry] Change the error handling for the commands between
":try" and ":endtry" including everything being
executed across ":source" commands, function calls,
or autocommand invocations.
And from :echoerr
:
When used inside a try conditional, the message is raised as an error exception instead (see try-echoerr).
Other notes:
-u NONE
prevents sourcing the default vimrcs:cq
makes Vim return a non-zero exit status
To get the last error message (now actually an exception), use v:exception
:
$ vim -u NONE -c 'try | source vimrc-fail | catch | silent exec "!echo " shellescape(v:exception) |cq | endtry | q'; echo $?
Vim(echoerr):test
1
edited Jan 22 at 4:38
answered Jan 21 at 8:02
OlorinOlorin
3,3331418
3,3331418
Thanks! Is there a way to echo the error message as well?
– Joshua Spence
Jan 21 at 23:11
@JoshuaSpence I think the last exception is stored inv:exception
. Maybe something likeexec "!echo " shellescape(v:exception) | cq
instead of the plaincq
would work.
– Olorin
Jan 22 at 1:10
That almost works... it requires me to press enter though.
– Joshua Spence
Jan 22 at 3:56
Ok, it works if I runvim
with-E
and-s
– Joshua Spence
Jan 22 at 4:11
silent exec
should fix the Enter problem.
– Olorin
Jan 22 at 4:37
|
show 1 more comment
Thanks! Is there a way to echo the error message as well?
– Joshua Spence
Jan 21 at 23:11
@JoshuaSpence I think the last exception is stored inv:exception
. Maybe something likeexec "!echo " shellescape(v:exception) | cq
instead of the plaincq
would work.
– Olorin
Jan 22 at 1:10
That almost works... it requires me to press enter though.
– Joshua Spence
Jan 22 at 3:56
Ok, it works if I runvim
with-E
and-s
– Joshua Spence
Jan 22 at 4:11
silent exec
should fix the Enter problem.
– Olorin
Jan 22 at 4:37
Thanks! Is there a way to echo the error message as well?
– Joshua Spence
Jan 21 at 23:11
Thanks! Is there a way to echo the error message as well?
– Joshua Spence
Jan 21 at 23:11
@JoshuaSpence I think the last exception is stored in
v:exception
. Maybe something like exec "!echo " shellescape(v:exception) | cq
instead of the plain cq
would work.– Olorin
Jan 22 at 1:10
@JoshuaSpence I think the last exception is stored in
v:exception
. Maybe something like exec "!echo " shellescape(v:exception) | cq
instead of the plain cq
would work.– Olorin
Jan 22 at 1:10
That almost works... it requires me to press enter though.
– Joshua Spence
Jan 22 at 3:56
That almost works... it requires me to press enter though.
– Joshua Spence
Jan 22 at 3:56
Ok, it works if I run
vim
with -E
and -s
– Joshua Spence
Jan 22 at 4:11
Ok, it works if I run
vim
with -E
and -s
– Joshua Spence
Jan 22 at 4:11
silent exec
should fix the Enter problem.– Olorin
Jan 22 at 4:37
silent exec
should fix the Enter problem.– Olorin
Jan 22 at 4:37
|
show 1 more comment
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495721%2fvalidate-vimrc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown