How do I disable the "Press ENTER or type command to continue" prompt in Vim?

Viewed 76521

Is there any way to disable the "Press ENTER or type command to continue" prompt that appears after executing an external command?

EDIT: Found a workaround: Add an extra <CR> to the shortcut in my .lvimrc.

map <F5> :wall!<CR>:!sbcl --load foo.cl<CR><CR>

Any better ideas?

18 Answers

I'm not sure how to do it globally though for one command:

:silent !<command>

Be sure to include a space after silent

Found out one workaround: Add an extra <CR> to the map command.

map <F5> :wall!<CR>:!sbcl --load foo.cl<CR><CR>

I my case (an autocommand) set shortmess+=F did the trick.

:h shortmess
F don't give the file info when editing a file, like :silent

Putting a redraw before the screen clear works too. Here's what I had:

exe 'ls'  
exe 'b4'  "This redraws, so the Prompt is triggered

But this won't trigger prompt:

exe 'ls'  
redraw  
exe 'b4'
  • If you are using a key map then your life can be much easier by adding several more to the end of your command -- but usually 2 times is well enough.
  • But if you are executing a command from the vim command line. Then it's kind of tricky. You may add keyword silent before your actually command. It will bring you back to the vim window automatically after the command has been executed. But you still need to manually execute redraw as some of the windows like NERD_Tree need to be redrawn.

    • For this case, try to follow the instructions from the vim help doc:

      To reduce the number of hit-enter prompts:

      • Set 'cmdheight' to 2 or higher.
      • Add flags to 'shortmess'.
      • Reset 'showcmd' and/or 'ruler'.
    • This link provides another way out. Put this into your vimrc file

      command! -nargs=1 Silent
      \   execute 'silent !' . 
      \ | execute 'redraw!'
      

And then you may use :Silent command like a regular command.

If your error is caused by E303, then creating a temporary directory in the .vimrc file may fix it.

After opening any file, write and enter:

:messages

If there are errors it will prompt.

If you see E303 (Error303) "Unable to open swap file for "{filename}", recovery impossible", it may indicate that there is an old attempt to recover a swap file (most likely lost or non-existent) in the system.

To fix this, assign a temporary directory in the .vimrc file.

To find the location of .vimrc file, type and enter this:

$ locate .vimrc
/root/.vimrc

Open the file $ vi .vimrc

Append this to the end of the file:

set directory=.,$TEMP

Save and close with :wq

Finally, reload the profile with:

$ . /etc/profile

Try to open any file with VI. The problem shall be fixed.

At my side the solution was to use silent more frequently in a command chain.

Specifically before, .vimrc had:

nnoremap M :silent make\|redraw!\|cc<CR>

This was changed to:

nnoremap M :silent make\|silent redraw!\|silent cc<CR>

Before, the "Press ENTER" not always showed up, but annoyingly often. The additional silents fixed this. (It looks like silent is not needed on redraw! as :cc caused the "Press ENTER" message.)

This change has the drawback of no more showing the output of :cc, so you have to guess what's the error. A little tweak fixes this:

nnoremap M :silent make\|redraw!\|cw\|silent cc<CR>

This makes the error QuickFix list (Output of make) automatically appear (and, by vim-magic, disappear if there is no error).

FYI:

Motivation of this M-mapping is to just press M in Normal-Mode to:

  • save the edit (when using make everything is under git-control anyway)
  • invoke make
  • and directly jump to the first error or warning

My Makefiles are usually constructed such, that this only takes a fraction of a second.

With a bit of tweaking this can be applied to non-C type workloads as well:

In .vimrc add

set efm+=#%t#%f#%l#%c#%m#

This allows vim to interpret messages like following for :cc (display error):

#E#file#line#column#message#
#W#file#line#column#message#
#I#file#line#column#message#

(Errors, Warnings, Info, based on vim magic)

Example how to use this for Python scripts. (Sorry, no copy here, it's a different story.)

On gvim, if you have set guioptions+=! (Added ! in guioptions), this is because of that. This option (!) make gvim execute some commands on external terminal (which support more features, like color and so many others).

You can try it using :set guioptions-=i and see if this works for you.

You can write 2 lines below to your vimrc to disable all message from vim

set shortmess=
set cmdheight=2

This work for me and hope you can fix the problem

Related