4

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 ?

1
  • Don't most external commands behave that way? :!echo hello has the same behavior (minus the quickfix error, obviously)
    – D. Ben Knoble
    Jun 24, 2022 at 15:31

1 Answer 1

2

Unfortunately, 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".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.