beane
beane

Reputation: 188

Vim won't take mappings that use the CTRL key in insert mode

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.

Upvotes: 1

Views: 248

Answers (3)

beane
beane

Reputation: 188

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.

Upvotes: 0

mpriscella
mpriscella

Reputation: 381

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

Upvotes: 0

Greg Hurrell
Greg Hurrell

Reputation: 5457

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

Upvotes: 2

Related Questions