Can I set something like
ctrl+s to save the file?
I don't want to use
:w every time.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
First of all stop using
:w to save. Use
:update writes the file to disk only when there are changes. So, it could be really helpful especially if the file is huge.
Now to map
:update here is how you do it
nnoremap <C-S> :update<cr>
You may also want to have this mapping in Insert mode too. For that use this
inoremap <C-S> <Esc>:update<cr>gi
This mapping goes normal mode, executes the
:update command and then leaves you back where you are in
So, that is how you remap a key.
But I have
:update mapped to
zz in my
zz is far more easy to hit than
Ctrl + S. Also, mapping
Ctrl + S can cause issues in Unix terminals as pointed out in the comments by @Sato Katsura.
So if you wish to use
zz, you can add that as follows
nnoremap zz :update<cr>
Yes, that's actually set up in the mswin.vim file that distributed with Vim 6.2 and above for windows.
It contains the following mappings:
" Use CTRL-S for saving, also in Insert mode noremap <C-S> :update<CR> vnoremap <C-S> <C-C>:update<CR> inoremap <C-S> <C-O>:update<CR>
See Vim Wikia page on mapping Ctrl-S for this and other possible mappings.