Wikia

Vim Tips Wiki

Changes: Saving a file

Edit

Back to page

(Remove html character entities)
(change "anon" author to blank; trim "created" date; minor manual clean)
Line 3: Line 3:
 
|previous=802
 
|previous=802
 
|next=804
 
|next=804
|created=October 6, 2004
+
|created=2004
 
|complexity=basic
 
|complexity=basic
|author=Anon
+
|author=
 
|version=6.0
 
|version=6.0
 
|rating=7/26
 
|rating=7/26
Line 14: Line 14:
   
 
Then you type the following (and press Enter):
 
Then you type the following (and press Enter):
<pre>:w</pre>
+
<pre>
  +
:w
  +
</pre>
   
 
You can save your file (if modified) and exit Vim at the same time with:
 
You can save your file (if modified) and exit Vim at the same time with:
<pre>:x</pre>
+
<pre>
  +
:x
  +
</pre>
   
 
You can save all modified buffers (all open files) with:
 
You can save all modified buffers (all open files) with:
<pre>:wa</pre>
+
<pre>
  +
:wa
  +
</pre>
   
 
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:
 
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:
 
 
<pre>
 
<pre>
 
map <Esc><Esc> :w<CR>
 
map <Esc><Esc> :w<CR>
Line 32: Line 31:
 
==Comments==
 
==Comments==
 
This would also work.
 
This would also work.
 
 
<pre>
 
<pre>
 
ino <Leader>:w <Esc>:w<CR>a
 
ino <Leader>:w <Esc>:w<CR>a
Line 39: Line 37:
 
----
 
----
 
I use the following:
 
I use the following:
 
 
<pre>
 
<pre>
 
nmap <c-s> :w<CR>
 
nmap <c-s> :w<CR>

Revision as of 02:59, December 4, 2009

Tip 803 Printable Monobook Previous Next

created 2004 · complexity basic · version 6.0


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.)

Comments

This would also work.

ino <Leader>:w <Esc>:w<CR>a

I use the following:

nmap <c-s> :w<CR>
vmap <c-s> <Esc><c-s>gv
imap <c-s> <Esc><c-s>

nmap <F2> :update<CR>
vmap <F2> <Esc><F2>gv
imap <F2> <c-o><F2>

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. I'm not sure whether there exists a workaround, because the system catches the keys before Vim gets them.

Around Wikia's network

Random Wiki