Vim Tips Wiki
(Added an alternative `Silent` command which fixes redraw issues in a slightly more general way.)
Tags: Visual edit apiedit
No edit summary
Tags: Visual edit apiedit
Line 11: Line 11:
 
|category2=Usage
 
|category2=Usage
 
}}
 
}}
  +
 
The "Hit ENTER to continue" prompt is displayed when Vim is about to redraw the screen, but there's text on the screen that you might need to read. This happens when something is displayed on the status line that is wider than the window, and after executing an external command.
 
The "Hit ENTER to continue" prompt is displayed when Vim is about to redraw the screen, but there's text on the screen that you might need to read. This happens when something is displayed on the status line that is wider than the window, and after executing an external command.
   
Line 16: Line 17:
   
 
To decrease message size, use the <code>'shortmess'</code> option. Add the following line to your [[vimrc]]:
 
To decrease message size, use the <code>'shortmess'</code> option. Add the following line to your [[vimrc]]:
  +
 
<pre>
 
<pre>
 
:set shortmess=a
 
:set shortmess=a
Line 23: Line 25:
   
 
To give more space for displaying messages, you can increase the height of the command line to 2 or greater:
 
To give more space for displaying messages, you can increase the height of the command line to 2 or greater:
  +
 
<pre>
 
<pre>
 
:set cmdheight=2
 
:set cmdheight=2
Line 39: Line 42:
 
If the command generates any output, you may need to manually refresh the screen once you return to Vim (by typing Ctrl-L or entering <code>:redraw!</code>). If you're running a GUI version of Vim, <code>:silent</code> may keep you from seeing any output from the command at all!
 
If the command generates any output, you may need to manually refresh the screen once you return to Vim (by typing Ctrl-L or entering <code>:redraw!</code>). If you're running a GUI version of Vim, <code>:silent</code> may keep you from seeing any output from the command at all!
 
To fix the above problem with regular vim, you can use a custom command like this one:
 
To fix the above problem with regular vim, you can use a custom command like this one:
  +
 
<pre>
 
<pre>
 
command! -nargs=1 Silent
 
command! -nargs=1 Silent
\ | execute ':silent !'.<q-args>
+
\ execute 'silent !' . <q-args>
\ | execute ':redraw!'
+
\ | execute 'redraw!'
 
</pre>
 
</pre>
  +
 
Use it like a regular command:
 
Use it like a regular command:
  +
 
<pre>
 
<pre>
 
:Silent command
 
:Silent command
  +
</pre>
</pre>Or to fix the redraw problems with external grep use:
 
  +
command! -nargs=+ Silent execute 'silent <args>' | redraw!
 
 
Or to fix the redraw problems with external grep use:
  +
  +
<pre>
  +
command! -nargs=+ Silent
 
\ execute 'silent <args>'
  +
\ | redraw!
  +
</pre>
  +
 
Which you can use like this:
 
Which you can use like this:
:Silent grep! -RIi "Lost words" .
 
   
  +
<pre>
==See also==
 
 
:Silent grep -RIi "Lost words" .
*[[VimTip1549|Execute external programs asynchronously under Windows]] for the "Hit any key to close this window..." prompt under Windows
 
  +
</pre>
  +
  +
To prevent prompt on mappings create mappings using <code>:map &lt;silent&gt;</code>:
  +
  +
<pre>
  +
:map <silent> <F12> :call Your_function()<cr>
  +
</pre>
  +
 
== See also ==
  +
 
*[[VimTip1549|Execute external programs asynchronously under Windows]] for the "Hit any key to close this window..." prompt.
   
 
==References==
 
==References==
  +
 
*{{help|hit-enter}}
 
*{{help|hit-enter}}
 
*{{help|'shortmess'}}
 
*{{help|'shortmess'}}
Line 61: Line 86:
 
*{{help|:!cmd}}
 
*{{help|:!cmd}}
 
*{{help|:silent}}
 
*{{help|:silent}}
  +
*{{help|:map-<silent>}}
   
 
==Comments==
 
==Comments==

Revision as of 19:12, 7 December 2016

Tip 16 Printable Monobook Previous Next

created 2001 · complexity basic · author Yegappan · version 5.7


The "Hit ENTER to continue" prompt is displayed when Vim is about to redraw the screen, but there's text on the screen that you might need to read. This happens when something is displayed on the status line that is wider than the window, and after executing an external command.

To reduce how often you see the "Hit ENTER to continue" prompt, you can shorten the messages, increase the space for displaying messages, or even tell Vim not to worry about external command output.

To decrease message size, use the 'shortmess' option. Add the following line to your vimrc:

:set shortmess=a

This will use abbreviations for status messages to make lines shorter. (There are several other flags for 'shortmess' that can shorten messages even more. :help 'shortmess')

To give more space for displaying messages, you can increase the height of the command line to 2 or greater:

:set cmdheight=2

The default command height is 1. Increasing cmdheight will allow more room for commands, although it will take some space away from editing.

You can temporarily change the cmdheight to display a prompt for example, and then revert it to its original value. This way, you won't have to hit enter and it won't take space once finished.

Finally, you can use :silent to keep external commands from triggering the "Hit ENTER" prompt:

:silent !echo Hello

If the command generates any output, you may need to manually refresh the screen once you return to Vim (by typing Ctrl-L or entering :redraw!). If you're running a GUI version of Vim, :silent may keep you from seeing any output from the command at all! To fix the above problem with regular vim, you can use a custom command like this one:

command! -nargs=1 Silent
\   execute 'silent !' . <q-args>
\ | execute 'redraw!'

Use it like a regular command:

:Silent command

Or to fix the redraw problems with external grep use:

command! -nargs=+ Silent
\   execute 'silent <args>'
\ | redraw!

Which you can use like this:

:Silent grep -RIi "Lost words" .

To prevent prompt on mappings create mappings using :map <silent>:

:map <silent> <F12> :call Your_function()<cr>

See also

References

Comments

  • putting the following setting into your .vimrc settings file works good for eliminating the <Press Enter> message when first bringing up a vim editor to a specific file with a large path.
    The 't' option chops the beginning portion of file lines, indicating the truncation with a < sign at the point of truncation.
    set shortmess=at
    Keithel 21:08, 13 August 2009 (UTC)
That option generally doesn't prevent the message.
Majkinetor (talk) 09:24, January 14, 2014 (UTC)