Often the mechanism to end up in the command line window is a transposition typo q: instead of :q when I intend to be closing Vim.

You can imagine the frustration at this point because the program state is now such that I have to (more carefully) type TWO more proper :q to achieve my goal. Although I do have, and can use a nice easy normal mode chord bind <s-q> for :q, my muscle memory and habits (using non-augmented vims) lead me to continue to use :q, so it is not a full solution.

In an effort to mitigate this situation, I have

nnoremap q: <Nop>

This works, however, now the q has an input delay (due to being bound now) and therefore causes the action of exiting from recording a macro/recording to be latent.

How can I remove my ability to enter the command line window without introducing such consequences?

  • :set timeoutlen=100...see if that helps – B Layer Jun 11 at 2:46
  • @BLayer I don't think I would want to do that, wouldn't that reduce my ability to execute any and all other multi-key binds?? – Steven Lu Jun 11 at 4:03
  • Eh? Why would that be? It just reduces the delay. This is exactly what you'll find in $VIMRUNTIME/defaults.vim (and what I use on a daily basis). – B Layer Jun 11 at 7:52
  • Rather than type :q which can be messed up, learn to type ZZ and friends ZX,ZQ ? (I think I got those right) – D. Ben Knoble Jun 11 at 14:09
  • 1
    I agree with D. Ben, you may want to change your workflow a bit to avoid the situation and make a new habit. I personally use <c-w>c/:close instead of using :q. I find the commandline-window to be super useful and use it many times though out the day. I think it is up there with <c-x><c-e> in bash. Maybe it would be better to just map q and use getchar(). – Peter Rincker Jun 11 at 15:00

I have not found a way to disable the command-line window, but, I have eliminated the need for the q: bind of mine, by removing it and changing the rest of my vim config to allow my command-line window to work again as intended.

You could say this is solved by application of the XY problem principle.

If your Vim version includes the patch 8.1.0020, you could try this code:

nno  <silent>  q  @=<sid>custom_q()<cr>
fu! s:custom_q() abort
    if reg_recording() isnot# ''
        return 'q'
    endif
    let key = nr2char(getchar())
    if key is# ':'
        return ':q'
    endif
    return 'q'.key
endfu

If you're recording characters into a register, pressing q should end the recording.
Otherwise, it should prompt you for the name of a register to start a recording.
And if you press :, it should populate the command-line with :q.

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.