Saving a file

To save a file, you would normally first leave insert mode by hitting the Esc key one or more times. Then you type the following (and press Enter):

:w

You can save your file (if modified) and exit Vim at the same time with:

:x

You can save all modified buffers (all open files) with:

:wa

For a tweak, you can set Vim to automatically save the current buffer when you hit Esc twice. This can be done by simply adding the following line to your vimrc:

map <Esc><Esc> :w<CR>

Note: In a console, mapping with a single Esc interferes with the Up/Down/Left/Right arrow keys, since these are actually escape sequences and send an Esc followed by a key id. (The reason that hitting Esc in Vim does not always give an immediate response is that Vim first waits a little to see if a key id is following the Esc.)

Control-S always saves the file, and, if called from visual mode, restores the visual selection when done. It does not re-enter insert mode, though, so I use it as my quit-insert-mode-and-save macro.

F2 only saves if necessary, and returns the user to insert mode (or restores their visual selection), as needed.

Under UNIX/Linux, in a console or terminal, CTRL-S sends the signal SIGSTOP, which stops the process in foreground until SIGCONT is sent; this is done by CTRL-Q. This behaviour can usually be disabled by executing

stty -ixon

(add it to your shell's profile or rc file so it will be executed whenever you log in).