Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In vim how to map "save" to ctrl-s

Tags:

vim

In vim, how can I map "save" (:w) to ctrl-s.

I am trying "map" the command, but xterm freezes when I press ctrl-s.

If I give ctrl-v,ctrl-s still I see only a ^, not ^S.

like image 690
Ratheesh Pai Avatar asked Aug 10 '10 05:08

Ratheesh Pai


People also ask

What does Ctrl S do in Vim?

But hey Ctrl+S has special meaning for Linux terminal, it's a terminal scroll lock - basically it freezes program that wants to write to standard output/error. To unfreeze program you must press Ctrl+Q .

How do you reverse Ctrl S?

Ctrl - Q is indeed the answer.

How do I save a file in Vim?

The command to save a file in Vim is :w . To save the file without exiting the editor, switch back to normal mode by pressing Esc , type :w and hit Enter . There is also an update command :up , which writes the buffer to the file only if there are unsaved changes.

How do I save and quit in Vim?

Save a File and Quit You can also use the :x command. It works similar to :wq but only writes when you've made actual changes.


1 Answers

Ctrl+S is a common command to terminals to stop updating, it was a way to slow the output so you could read it on terminals that didn't have a scrollback buffer. First find out if you can configure your xterm to pass Ctrl+S through to the application. Then these map commands will work:

noremap <silent> <C-S>          :update<CR> vnoremap <silent> <C-S>         <C-C>:update<CR> inoremap <silent> <C-S>         <C-O>:update<CR> 

BTW: if Ctrl+S freezes your terminal, type Ctrl+Q to get it going again.

like image 141
Ned Batchelder Avatar answered Oct 26 '22 08:10

Ned Batchelder