1

I'm trying to get Ctrl-S to save, but vim doesn't seem to be picking up any mappings with the control character. None of these work:

inoremap <C-S> <Esc>:update<Enter>
map <C-S> <Esc>:update<Enter>
nnoremap <C-S> <Esc>:update<Enter>

What's going on with the control key? How can I fix it?

Edit: The answers here don't work for me.

I tried stty stop ^- and stty -ixon, which finally let the signal come through to vim, but the mapping still won't get picked up in insert mode. So now it seems like it's only insert mode that's causing problems.

Other mappings with Ctrl in insert mode also don't work:

inoremap <C-g> <C-O>:update<CR>

Solution: The issue arose because I had set paste in my vimrc. Removing that line solved the problem. Still not sure why.

Community
  • 1
  • 1
beane
  • 158
  • 1
  • 12
  • 2
    Possible duplicate of [In vim how to map "save" to ctrl-s](http://stackoverflow.com/questions/3446320/in-vim-how-to-map-save-to-ctrl-s) – glts Feb 03 '16 at 07:37
  • @glts those solutions didn't work for me. Updated the question to reflect what I tried. – beane Feb 03 '16 at 16:23
  • Also, please don't add a 'solution' to the question, that is not how it works here. – glts Feb 03 '16 at 19:43

3 Answers3

2

Flow control may be active, which would prevent Vim from seeing the <C-s> sequence. If that's the case, you could turn off flow control with something like this in your .bash_profile/.zshrc:

stty -ixon
Greg Hurrell
  • 5,177
  • 23
  • 27
  • that got me half the way there! Vim now recognizes the signal, but it still won't accept any mappings that use `ctrl`. – beane Feb 03 '16 at 16:26
0

Looks like you're trying to save without leaving insert mode. Give this a shot, it's working for me.

inoremap <C-s> <Esc>:update<CR>i

mpriscella
  • 361
  • 3
  • 12
  • That doesn't work for me either. The same mapping works in any of the other modes and I can make mappings in insert mode that use the meta key. I think it's that my insert mode doesn't like ctrl for some reason. – beane Feb 03 '16 at 19:13
0

It's because I had set paste in my vimrc. I still don't understand why, but it looks like removing that line solved it.

No idea how to work around it, though.

beane
  • 158
  • 1
  • 12
  • `paste` should never be set in a vimrc. It's a temporary option that's toggled on and then off again. – glts Feb 03 '16 at 19:37
  • Can you tell me more? I liked having it so I could copy and paste large amounts of text from other sources without thinking. – beane Feb 03 '16 at 19:38
  • 1
    As `:h 'paste'` explains, this option is intended to support quick pasting when Vim is in a terminal. Mappings don't work when `paste` is active. Use the `pastetoggle` functionality to quickly enable/disable `paste` when you need it, see [`:h 'pastetoggle'`](http://vimdoc.sourceforge.net/htmldoc/options.html#'pastetoggle'). – glts Feb 03 '16 at 19:41
  • Better still, set up "Bracketed Paste Mode" and then you won't have to worry about any of this. – Greg Hurrell Feb 04 '16 at 18:01