Configure shortcut on Vim to save file

vivimvimrc

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?

Thanks!

Best Answer

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>
Related Question