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
.
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 .
Ctrl - Q is indeed the answer.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With