How do I disable the "Press ENTER or type command to continue" prompt in Vim?
VimVim Problem Overview
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?
Vim Solutions
Solution 1 - Vim
I'm not sure how to do it globally though for one command:
:silent !<command>
Be sure to include a space after silent
Solution 2 - Vim
Found out one workaround: Add an extra <CR>
to the map command.
map <F5> :wall!<CR>:!sbcl --load foo.cl<CR><CR>
Solution 3 - Vim
:help hit-enter
Solution 4 - Vim
Solution 5 - Vim
This is how I dealt with the problem that running an external program through silent messes up the screen in text-mode vim (in my experience, gvim doesn't suffer from this problem):
command! -nargs=1 Silent
\ | execute ':silent !'.<q-args>
\ | execute ':redraw!'
Use it instead of the regular silent command:
:Silent top
Solution 6 - Vim
It is possibly a syntax error in vimrc file
Solution 7 - Vim
This is how I run external commands in tricky scenarios without having "Press ENTER". Unlike :silent
, I can still see the command output.
Command line
:exe ":!<command>" | redraw
Script / function
exe ':!<command>'
redraw
Mapping with <expr>
map <expr> <F5> ":exe ':!<command>'\n:redraw\<CR>"
Mapping with <expr>
that calls a function
map <expr> <F5> MyFoo()
fu! MyFoo()
return ":exe ':!<command>' | redraw\<CR>"
endf
Solution 8 - Vim
The answer by anthony took me to the right place and I was able to configure gvim not to stop on a lot of messages.
I added set shortmess=aoOtI
to my gvimrc file.
It is explained in the help page brought to you by :help shortmess
.
The letters mean classes of messages you don't want to see, or would like vim to truncate to avoid the hit enter stop.
I managed this before by setting a wide initial window with columns=130
in gvimrc so few messages would overflow it and require the annoying, exhausting, need to hit enter.
Solution 9 - Vim
You can use:
call feedkeys(" ")
For example:
function! Interactive_Questions()
echo "Question 1:"
let response1 = getchar()
echo "Question 2:"
let response2 = getchar()
" Do something
" Without the next line, you would have to hit ENTER,
" even if what is written (the questions) has no interest:
call feedkeys(" ")
endf
Solution 10 - Vim
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
Solution 11 - Vim
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'
Solution 12 - Vim
I have a similar issue, but when I run an argdo to replace the same string in multiple files e.g.,
argdo %s/something/Something/eg|update
I was constantly having to press page down.
You can set the following option before running the script so that there is only the final prompt instead of many prompts
:set nomore
Solution 13 - Vim
- 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 executeredraw
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.
Solution 14 - Vim
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.
Solution 15 - Vim
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 silent
s 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 ccmake
) 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 undergit
-control anyway) - invoke
make
- and directly jump to the first error or warning
My Makefile
s 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#
(E
rrors, W
arnings, I
nfo, based on vim
magic)
Example how to use this for Python scripts. (Sorry, no copy here, it's a different story.)
Solution 16 - Vim
This happens to me if I'm saving a file that is in a directory where I don't have write permissions to the directory. I did a chmod 777 on the directory (I already had write permissions on the file itself) and the "Press ENTER" message no longer shows up.
Solution 17 - Vim
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.
Solution 18 - Vim
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