When I use :make
, the command first shows me the shell and has me press Enter
and only then do I get to the actual error in the file.
Is there a reason for this behaviour ? Can I get rid of it ?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityUnfortunately, you cannot disable this behavior. Vim showing you the shell output is a good thing in most cases, particularly after running :make
. If makeprg
is not set, :make
will run make
in the current working directory. Therefore, it is running an external command, so it makes sense that it behaves as any other external command. I believe this is the right behavior because regardless of whether there are errors or not, you usually want to read the value of stdout from your program or the contents of stderr with the full traceback.
However, when you set :makeprg
(e.g. set makeprg=python\ %
), :make
displays the shell output with the message "Press ENTER or type command to continue". If there are any errors, it will show you the internal pager with the contents of the quickfix error and you need to press Enter again to go back to your buffer. In my opinion, that's undesirable, but you can set a mapping as follows:
nnoremap <Leader>! :w! \| :make \| :redraw!<cr>
and assuming a properly set makeprg
and errorformat
, you will be shown the error in the shell (as it should) and after pressing Enter once, you go back to your buffer with a populated quickfix list.
You might also want to open the quickfix list but only if an error was found and then move the cursor to the corresponding line:
nnoremap <Leader>! :w! \| :make \| :cw \| :silent! :.cc \| :redraw!<cr>
For neovim, I think it is not necessary to run :redraw
, so you can remove the last part as follows:
nnoremap <Leader>! :w! \| :make \| :cw \| :silent! :.cc<cr>
For the record, neovim implemented this feature (running external commands) in a way that is less intrusive. However, it is not interactive which has been an annoying side-effect for many users. You still have to press Enter to go back to your buffer, but it doesn't spawn the program with the shell output in a different "window".
:!echo hello
has the same behavior (minus the quickfix error, obviously)