I was wondering is it possible to create a custom shortcut in vim or vi to save open file?

For example, CtrlS instead of typing each time :w?


2 Answers 2


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>
  • Hi @muru thanks for reply. My mappings are in /usr/share/vim/vim74. And when I list files from there I don't have mswin.vim. I am on Deb8, vim version is 2:7.4.488-7
    – fugitive
    Feb 18, 2017 at 16:03
  • Sorry, didn't saw it on a first sight. Everything is working. Thanks man :)
    – fugitive
    Feb 18, 2017 at 16:08
  • 3
    @fugitive no problem. If you're interested in using Vim better, do check out sister site Vi and Vim
    – muru
    Feb 18, 2017 at 16:41

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .