Vim Tips Wiki
(Move categories to tip template)
m (Reverted edits by 96.232.165.38 (talk | block) to last version by 188.192.143.15)
(5 intermediate revisions by 4 users not shown)
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 11: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
To save a file, you would normally first leave insert mode by hitting the Esc key one or more times.
+
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):
  +
<pre>
 
  +
:w
Then you type the following (and press Enter):
 
<pre>:w</pre>
+
</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 &lt;Esc&gt;&lt;Esc&gt; :w&lt;CR&gt;
+
map <Esc><Esc> :w<CR>
 
</pre>
 
</pre>
   
Line 32: Line 35:
 
==Comments==
 
==Comments==
 
This would also work.
 
This would also work.
 
 
<pre>
 
<pre>
ino &lt;leader&gt;:w &lt;esc&gt;:w&lt;cr&gt;a
+
ino <Leader>:w <Esc>:w<CR>a
 
</pre>
 
</pre>
   
 
----
 
----
 
I use the following:
 
I use the following:
 
 
<pre>
 
<pre>
nmap &lt;c-s&gt; :w&lt;CR&gt;
+
nmap <c-s> :w<CR>
vmap &lt;c-s&gt; &lt;esc&gt;&lt;c-s&gt;gv
+
vmap <c-s> <Esc><c-s>gv
imap &lt;c-s&gt; &lt;esc&gt;&lt;c-s&gt;
+
imap <c-s> <Esc><c-s>
   
nmap &lt;f2&gt; :update&lt;cr&gt;
+
nmap <F2> :update<CR>
vmap &lt;f2&gt; &lt;esc&gt;&lt;f2&gt;gv
+
vmap <F2> <Esc><F2>gv
imap &lt;f2&gt; &lt;c-o&gt;&lt;f2&gt;
+
imap <F2> <c-o><F2>
 
</pre>
 
</pre>
   
Line 55: Line 56:
   
 
----
 
----
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.
+
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 <pre>stty -ixon</pre> (add it to your shell's profile or rc file so it will be executed whenever you log in).

Revision as of 14:36, 29 July 2015

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