146

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?

3
  • 9
    On Windows 7, you'll get this prompt often because of "unable to open swap file" errors that have been printed but you don't see them, which causes the prompt. The solution is to put set dir=$TEMP in your vimrc. This tells vim to use the correct temp folder for its temp files. This in turn fixes the errors and removes the "press enter" prompts. Commented Jul 27, 2011 at 18:47
  • For me it was an error in my .vimrc. type :messages to list errors. Once the error was fixed, the "press enter to contine... command" message went away. Commented Jul 25, 2024 at 19:52
  • hit-enter is triggered by messages that span more than one line. Therefore, zoom out (smaller font) reduces hit-enter prompts. That's useful if you can't change a command easily as is suggested below. Commented Nov 14, 2024 at 7:13

18 Answers 18

97

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

:silent !<command>

Be sure to include a space after silent

Sign up to request clarification or add additional context in comments.

6 Comments

Unfortunately not very helpful for me, it messes up the screen and I have to press Ctrl-L... which is even more annoying than pressing space.
Worked for my grep script though!
In line with commenter below (who suggested to add extra <CR> at the end of command), when using silent, you can add extra <C-l>, so that you do not have to press it manually. Works with screen well, then.
just use :silent !command, and then :redraw! after -- i think it doesnt do this automatically because of scripts that may do things to the screen that you want to stay, for example, a clock or some other status monitoring thing... just a guess
Yeah.. it messes up the screen for me too. the :redraw! option solves it. The double <cr> is probably similar. and less complicated
|
72

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

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

3 Comments

Never would have thought of this. Absolutely brilliant!
Yep, adding the extra <CR> to my command did the trick as well.
Incredibly simple. It's super effective!
27
:help hit-enter

6 Comments

I'm curious as to why someone voted this answer down, since :help hit-enter provides some fairly useful background information on "Press ENTER..." prompt. Care to explain?
What information from ':help hit-enter' answers the question? I can't find it.
It is possible you could get a "Press ENTER" prompt from the write all command before you shell out. The information under <code>shortmess</code> which <code>hit-enter</code> links to is valid in that case. However, the prompt you are getting is from shelling out, so Wergan's suggestion is the correct one. As noted in <code>:help :silent</code> "When using this for an external command, this may cause the screen to be messed up. Use |CTRL-L| to clean it up". You can add :redraw or Ctrl-L to your command to fix that. Or just do the two returns you're already doing.
@JohanKotlinski the set nomore
Put the info you think is relevant in the answer. Because you didin't, it was downvoted. Don't make users leave to external content blindly. Give them a reason to leave, and a link if your reason is convincing.
|
26

Set the cmdheight to 2, in my vimrc (:e $MYVIMRC):

:set cmdheight=2

More info here.

1 Comment

This is perfect for really long search queries
22

It is possibly a syntax error in vimrc file. Use :messages to see the full message(@NanoNova)

9 Comments

This. I had used set number and then set syntax right below in my .vimrc file. Once I removed set syntax Vim no longer prompted me.
@piperchester this worked! Tried tonnes of suggestions and only this worked. Thanks :)
I update vim, problem solved. But I think people could type :message to find out what's going wrong.
Yep. I had the line set syntax. Replaced it with set syntax=on and it fixes the problem.
@8.8.8.8 Please also mention what NanoNova captured above for debugging. :message gives the proper error that vimrc encountered while sourcing it. I removed the offending line, and it started loading properly. Really great tip there.
|
20

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

Comments

16

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

3 Comments

Is this reusable in any way? When I press F5 it just invokes a string <command>
<command> is meant to be replaced with an actual external command, e.g. map <expr> <F5> ":exe ':!gdb'\n:redraw\<CR>"
I was looking for this a very long time. The best solution for me! Thks.
10

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.

Comments

5

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

Comments

4

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

1 Comment

Thanks for this answer! Quick and easy and actually effective for my personal case unlike many of the other answers listed.
3

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'

1 Comment

This helped me since I just to programmatically get rid of the prompt at a certain place within a function. Just issuing a redraw solved it. The other solution did not fit, since I wanted to accept user input in between the original message and the disappearance of the prompt.
3

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

1 Comment

That was the answer: :set nomore , bad lick it is still at the end. It is also in :h help hit-enter of @anthony
1
  • 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.

Comments

1

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.)

Comments

1

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.

Comments

1

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

Comments

0

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.

Comments

0

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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.