Something that's bothered me for about a decade now is that when I switch from command line into the command-line-history window (by pressing <c-f>) and then switch back (by pressing <c-c>), the command line history window remains visible. I noticed that if I force a refresh by changing the size of the gVim window then the history window goes away so I think it just needs a redraw. Is there a way to force a redraw to occur when hitting <c-c>?

up vote 1 down vote accepted

Try this autocmd:

augroup my_cmdline_window
    au!
    au CmdWinEnter * nno  <buffer><expr><nowait>  <c-c>  '<c-c>'.timer_start(0, {-> execute('redraw')})[-1]
augroup END

The timer is necessary to delay :redraw. Without it, :redraw would be executed before C-c is pressed, that is before the command line window is left, which is too soon. Vim needs to redraw the screen after the command line window has been left.

For more information, see:

:h CmdWinEnter
:h map-<buffer>
:h map-<expr>
:h map-<nowait>
:h timer_start()
:h lambda
:h execute()
:h :redraw
  • Im not sure I understand why the timer is necessary; could you explain that a bit further? – D. Ben Knoble Dec 6 at 5:41
  • Works like a charm. Thanks – Steve Vermeulen Dec 6 at 15:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.