1

I often accidentally open cmdline-window during editing and want to disable the key mappings used to open it in normal mode: q:, q/, q? I tried mapping as such:

nmap q: <Nop>

This works when the keys are executed under a second or so but doesn't if there is an extended pause between q and :. Until recently I was using this to solve the problem:

nmap q <Nop>

This works for all three mappings but I've discovered I can no longer record macros. How can I disable the cmdline-window mappings and still be able to use q to record macros?

  • You'll probably need to tweak the delay of the mappings see :h 'ttimeout' and :h 'ttimeoutlen'. Also for what it's worth I use the following: nnoremap Q q nnoremap q <Nop> this way q is disabled and I record my macros with <S-q>. – statox Aug 18 '17 at 14:06
  • @statox I have the default timeout options set. After reading the timeout documentation, my understanding is a key mapping such as q: should timeout if I press q, let timeoutlen elapse, then press :. But that doesn't happen. Am I misunderstanding the documentation? – AdamC Aug 23 '17 at 20:37
  • After searching more I found that default commands are not handled the same as mappings. Therefore, timeout options are irrelevant in this case. I'm happy with the suggestion from @statox. Thanks. – AdamC Aug 24 '17 at 15:51
2

I doubt this is the answer you want to hear, but you probably need more practice with Vim. Unless you are having key timeout issues all the time then you probably are just not accustom to the commands you are trying to execute. We all fat finger (or at least I do) commands sometime or another. The best way to get better is practice and take each failure as a reminder to keep practicing. I used to hit q: on accident all the time. I didn't remap q: to <nop> instead I got better at typing, or at least better at typing :q.

Now opening the command-line window can be annoying, but you can make it easier to close. Add the following to your vimrc file:

augroup CommandLineWindow
    autocmd!
    autocmd CmdwinEnter * nnoremap <buffer> <esc> :q<cr>
augroup END

This will allow you to use <esc> form normal mode to easily close the command-line window. I find this feels natural.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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