0

I'm trying to make Ctrl+Q quit vim automatically without saving. I thought this would be a very simple task but am stumped on why it's not working...

I have the two following mappings at the end of my vimrc...

nmap q :q! <Enter>
imap <C-q> <esc>:q!<CR>

but when I press control+q vim toggles visual-block mode instead of quitting. Why? How do I get those keybindings to work?

9
  • 1
    Why do you use q and <ENTER> for the first instead of <C-q> and <CR>?
    – Quasímodo
    Oct 23 '20 at 21:39
  • 1
    In which modes does your map fails?
    – Quasímodo
    Oct 23 '20 at 21:40
  • 1
    You might want to think about preferring nnoremap. Control-q is an alternative for visual-block, but you should still be able to override it. Note, however, that (like for C-s) you may have to disable tty pausing, which (afaik) uses those keys. (There’s a magic incantation of stty stty -ixon -ixoff)
    – D. Ben Knoble
    Oct 23 '20 at 23:49
  • 1
    @alec yes. But if the mapping worked, i suppose it’s all sorted. I’ll write up an answer unless you want to
    – D. Ben Knoble
    Oct 24 '20 at 2:48
  • 1
    @alec there should not be
    – D. Ben Knoble
    Oct 24 '20 at 13:44
2

Since OP said it helped: Prefer nnoremap unless you need recursive mappings (:*map) or insert-mode mappings (:i*map). I would write

nnoremap <C-q> :quit!<CR>

(No <esc> necessary, and I find it nice to spell things out.)

<C-q> is an alternative for visual-block, but you should still be able to override it. Note, however, that (like for <C-s>) you may have to disable tty pausing, which (afaik) uses those keys. (There’s a magic incantation of stty stty -ixon -ixoff.)

3
  • 1
    Also consider silent !stty -ixon to .vimrc to deactivate that pre-historic freezing feature.
    – Quasímodo
    Oct 24 '20 at 18:11
  • @Quasímodo i put in shell files, but fair enough
    – D. Ben Knoble
    Oct 24 '20 at 18:24
  • 2
    Indeed, also good, only I prefer .vimrc because Vim can be invoked without a shell, e.g. xterm -e vim.
    – Quasímodo
    Oct 24 '20 at 18:25

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.