I was wondering is it possible to create a custom shortcut in
vi to save open file?
For example, CtrlS instead of typing each time
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Vim comes with a file providing some mappings intended to match Windows files. This is usually in
:echo $VIMRUNTIME to see what it is for you). You can just do:
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>
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