139

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?

Quuxplusone
  • 23,928
  • 8
  • 94
  • 159
Johan Kotlinski
  • 25,185
  • 9
  • 78
  • 101
  • 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. – Lucas Jul 27 '11 at 18:47

18 Answers18

94

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

:silent !<command>

Be sure to include a space after silent

Community
  • 1
  • 1
Tabitha
  • 2,554
  • 1
  • 21
  • 21
  • 9
    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. – Johan Kotlinski May 20 '09 at 23:59
  • 1
    Worked for my grep script though! – Mikko Rantanen Jul 23 '09 at 19:58
  • 6
    In line with commenter below (who suggested to add extra at the end of command), when using silent, you can add extra , so that you do not have to press it manually. Works with screen well, then. – Victor Farazdagi Sep 03 '11 at 09:52
  • 1
    I may case I then had to force a screen refresh, which immediately led me to http://stackoverflow.com/questions/1117725/how-to-make-vi-redraw-screen – Von Feb 03 '14 at 22:14
  • 7
    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 – osirisgothra Sep 14 '14 at 12:06
  • 4
    Yeah.. it messes up the screen for me too. the `:redraw!` option solves it. The double `` is probably similar. and less complicated – alpha_989 Feb 19 '18 at 02:33
69

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

map <F5> :wall!<CR>:!sbcl --load foo.cl<CR><CR>
Johan Kotlinski
  • 25,185
  • 9
  • 78
  • 101
28
:help hit-enter
anthony
  • 40,424
  • 5
  • 55
  • 128
  • 3
    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? – cjs May 21 '09 at 01:55
  • 48
    What information from ':help hit-enter' answers the question? I can't find it. – Johan Kotlinski May 24 '09 at 12:26
  • 1
    It is possible you could get a "Press ENTER" prompt from the write all command before you shell out. The information under shortmess which hit-enter 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 :help :silent "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. – Conspicuous Compiler Jun 30 '09 at 21:16
  • For me, it was about `set hl` (`:highlight`) I wrongly used as a shortcut for `hlsearch` who's real shortcut is `hls`. One `s` matters :) –  Jun 18 '17 at 21:13
  • 1
    @JohanKotlinski the `set nomore` – Tinmarino Aug 08 '20 at 20:19
24

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

:set cmdheight=2

More info here.

TankorSmash
  • 12,186
  • 6
  • 68
  • 106
19

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
emil.p.stanchev
  • 672
  • 5
  • 13
17

It is possibly a syntax error in vimrc file

8.8.8.8
  • 678
  • 7
  • 11
15

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
svlasov
  • 9,923
  • 2
  • 38
  • 39
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.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Juan Lanus
  • 2,293
  • 23
  • 18
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
yolenoyer
  • 8,797
  • 2
  • 27
  • 61
  • Thanks for this answer! Quick and easy and actually effective for my personal case unlike many of the other answers listed. – ab5tract Jun 02 '20 at 05:19
4

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

Biggybi
  • 266
  • 1
  • 10
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
Matt Vukomanovic
  • 1,392
  • 1
  • 15
  • 23
  • That was the answer: `:set nomore` , bad lick it is still at the end. It is also in `:h help hit-enter` of @anthony – Tinmarino Aug 08 '20 at 20:21
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'
Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
Liang Li
  • 31
  • 1
  • 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. – Daniel Andersson Aug 29 '14 at 11:25
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.

hzh
  • 342
  • 2
  • 15
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.

Rafael Vidal
  • 333
  • 4
  • 17
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.)

Tino
  • 9,583
  • 5
  • 55
  • 60
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

Pham Hung
  • 53
  • 1
  • 6
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.

jayemar
  • 332
  • 2
  • 8
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.

Nilesh Kevlani
  • 1,278
  • 1
  • 10
  • 10