2

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>?

1 Answer 1

1

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
1
  • Im not sure I understand why the timer is necessary; could you explain that a bit further?
    – D. Ben Knoble
    Dec 6, 2018 at 5:41

Your Answer

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

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