6

I love to use vim as simple IDE when comiling C/C++ programs (let say with gcc on a linux terminal), just inside vim with command:

:w | make | cw

In that way:

  • the :w vim command save editing
  • the :make INTERNAL vim command invoke the external make program using makefile.
  • the :cw vim command the quickfix window showing list of errors and letting me to go directly to line where errors are.

That's great! but (in case of compiler error) I have to press key ENTER TWICE:

a first time (in the shell):

"press ENTER or type command to continue" ENTER

second time (inside the editor):

"press ENTER or type command to continue" ENTER

BTW, I read about the shortmess setting but didn't help this:

set shortmess=aoOtI

Any idea to avoid to press enter and go directly to the quickfix windows ?

8

Vim displays the "Press ENTER" prompt when the number of lines printed in the command area is greater than the number of lines it has available. This is to ensure the user doesn't miss a message.

The issue has been documented in Vim's help (:h press-enter) and also addressed on the VimTips wiki.

Make more space for messages

An easy and reliable fix is to increase the size of the command-line area.

:set cmdheight=4

But this has the disadvantage of using up extra screen space.

Reduce number/size of messages

Reducing the number of lines printed by :w and :make could also help:

  1. Use :silent w or :silent make so they don't display anything.
  2. Make messages shorter with :set shortmess=a

Handle the prompt with a keymap

If you know you will always get a prompt when you run a particular mapping, then you can add <Enter> or <CR> to the mapping to answer the prompt for you!

This is a dirty solution, because if later the prompt is not displayed (e.g. you increase cmdheight or decrease the number of messages) then the <CR> will still be sent! That's not a big problem if Normal mode interprets it as "go to beginning of next line", but it could be more disruptive if focus was on the quickfix list, or an explorer window, where Enter performs a more significant action.

  • thx. It partially solve, because in case of compiler errors, I stll have to press the first ENTER. I'll investigate about :w and :make command as you suggest – Giorgio Robino Oct 12 '15 at 12:48
  • 1
    Yes! voted! :) the winner sequence is: silent w | silent make | cw – Giorgio Robino Oct 12 '15 at 14:56
  • leaving usual cmdheight=1, I added in my .vimrc the command: command! Make silent w | silent make | cw – Giorgio Robino Oct 12 '15 at 15:00
4

Based on the previous answer suggesting the use of silent I made the following :Vmake command with a small modification to redraw the screen:

:command! Vmake silent w | silent make | unsilent redraw! | cwindow

It saves the buffer and runs make silently to avoid the hit enter prompt. Then redraws the screen to workaroud the :silent weirdness (see :help :silent). Then automatically closes the quickfix window if there where no errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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