Configure shortcut on Vim to save file

Vim comes with a file providing some mappings intended to match Windows files. This is usually in $VIMRUNTIME/mswin.vim (run :echo $VIMRUNTIME to see what it is for you). You can just do:

:source $VIMRUNTIME/mswin.vim

And get a bunch of shortcuts, including CtrlS. See :h mswin.vim for more.

Note that your terminal emulator might use CtrlS for other purposes, but that's outside Vim.

To just create a mapping to test, do:

nnoremap <c-s> :w<cr>

To expound on @muru's caveat about ctrl+s being trapped by the terminal:

By default, a number of terminal-clients (including Cygwin) bind ctrl+s to the freeze output signal, which affects a number of commands such as scp, and incidentally prevents the keypress from being assigned to other things, since the console grabs it before it reaches vim or other applications.

So, for those who want to use ctrl+s for purposes other than freezing output, try adding the following to your ".bashrc" file:

# free up ctrl+s and ctrl+q:
stty stop ''
stty start ''
stty -ixon
stty -ixoff

Tags:

Vi

Vim

Vimrc