2

I have tried several things to set the keybinding Ctrl+Q to exit Vim without saving any changes (i.e., what is normally bound to :qa!). I have tried adding:

inoremap <C-q> <esc>:qa!<cr>               " quit discarding changes
nnoremap <C-q> :qa!<cr>

to my ~/.vimrc based on this answer on Unix & Linux StackExchange. This failed as when I pressed Ctrl+Q nothing happened. I have also tried:

map <C-Q> :qa!

and:

map <C-Q> ":qa!

neither worked. Any ideas what I need to do to set this keybinding? If it is at all relevant my platform is Fedora 25 and I installed the latest Vim from my own Open Build Service repository — https://build.opensuse.org/package/show/home:fusion809/vim-redhat.

  • 2
    What do you get when you type i<C-v><C-q>? If nothing shows up, it's something with your terminal. – DJMcMayhem Jan 30 '17 at 4:31
  • i starts insert mode in Vim, so I must admit I'm confused what you're expecting <C-v><C-q> will do afterwards. <C-v> is bound in my ~/.vimrc to paste. – BH2017 Jan 30 '17 at 4:39
  • 2
    In insert mode, <C-v> allows you to insert a literal character with no side effects. It's just a nice way to test whether or not the keystroke ever gets to vim in the first place – DJMcMayhem Jan 30 '17 at 4:40
  • Well I've tested out <C-q> in gvim too with those edits to my Vimrc and it still doesn't quit Vim so it's not due to my terminal that this keybinding doesn't work. – BH2017 Jan 30 '17 at 4:43
  • 1
    This SO answer provides a solution to the problem. – Cows quack Jan 30 '17 at 5:22
2

This is what fixed this problem for me, I unknowingly had bound to something else in my ~/.vimrc, when I removed it and added:

silent !stty -ixon > /dev/null 2>/dev/null
map <C-Q> :qa!<CR>

to my ~/.vimrc file this keybinding worked properly.

  • If your problem was that something else was mapped to <c-q> I don't see why you need the first line (silent !stty...)? – statox Jan 30 '17 at 7:38
  • Note: In my testing, this leaves soft flow control turned off on the terminal even after you exit Vim, so ctrl+s and ctrl+q don't work to pause long outputs afterwards. It might be a good idea to add an autocommand for VimLeave or something to stty ixon. Alternatively, if you never use flow control and it gets in your way, you can do the stty in your bashrc (or equivalent) instead of vimrc, and get the bonus of using ctrl+s for forward-searching your history in bash and other readline shells. – John O'M. Mar 2 '17 at 5:10

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.