Can I set something like ctrl+s to save the file?

I don't want to use :w every time.


2 Answers 2


First of all stop using :w to save. Use :update instead. :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 <C-S> to :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 insert mode.

So, that is how you remap a key. But I have :update mapped to zz in my vimrc file. 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>
  • 2
    The second mapping does not always leave your cursor in the same place! What if you're on the first column? Use gi instead of a, or better yet, use <C-o> instead of <esc>.
    – DJMcMayhem
    Jul 22, 2016 at 5:10
  • 2
    Except on the vast majority of UNIX terminals Ctrl-S is the stop character. You can use stty to disable it, but then you won't be able to pause a program's output. Remapping Ctrl-S and Ctrl-Q is a really bad idea, about as bad as remapping Esc. Jul 22, 2016 at 6:19
  • @SatoKatsura Yeah. That's why I don't use Ctrl - S. I use zz for saving. Jul 22, 2016 at 8:18
  • @DJMcMayhem Thanks for pointing that. I changed a to gi. But I am not really sure what <C-o> does. Can you explain why that is better than <Esc> ? Jul 22, 2016 at 8:20
  • 1
    @DurgaSwaroop Yes, sure! <C-o> is extremely useful for mappings. It means "Leave insert command to do a single normal mode command".
    – DJMcMayhem
    Jul 22, 2016 at 14:20

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.

  • 1
    what's with the down votes on the answers?
    – Herb
    Jul 23, 2016 at 4:19
  • It happens to me as well. I upvoted your comment and answer. Not sure why folks downvote a good answer.
    – netskink
    May 25 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.