(Change to TipImported template + severe manual clean) |
m (Reverted edits by 96.232.165.38 (talk | block) to last version by 188.192.143.15) |
||
(9 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
− | {{review}} |
||
{{TipImported |
{{TipImported |
||
|id=803 |
|id=803 |
||
|previous=802 |
|previous=802 |
||
|next=804 |
|next=804 |
||
− | |created= |
+ | |created=2004 |
|complexity=basic |
|complexity=basic |
||
− | |author= |
+ | |author= |
|version=6.0 |
|version=6.0 |
||
|rating=7/26 |
|rating=7/26 |
||
+ | |category1= |
||
+ | |category2= |
||
}} |
}} |
||
− | + | 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 |
||
+ | </pre> |
||
− | + | You can save your file (if modified) and exit Vim at the same time with: |
|
+ | <pre> |
||
+ | :x |
||
+ | </pre> |
||
+ | You can save all modified buffers (all open files) with: |
||
<pre> |
<pre> |
||
+ | :wa |
||
− | map <Esc><Esc> :w <CR> |
||
</pre> |
</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: |
||
− | Note: Mapping with a single Esc is somehow causing problems with the Up/Down/Left/Right arrow keys. |
||
+ | <pre> |
||
+ | map <Esc><Esc> :w<CR> |
||
+ | </pre> |
||
+ | |||
+ | 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== |
==Comments== |
||
This would also work. |
This would also work. |
||
− | |||
<pre> |
<pre> |
||
− | ino |
+ | ino <Leader>:w <Esc>:w<CR>a |
</pre> |
</pre> |
||
---- |
---- |
||
I use the following: |
I use the following: |
||
− | |||
<pre> |
<pre> |
||
− | nmap |
+ | nmap <c-s> :w<CR> |
− | vmap |
+ | vmap <c-s> <Esc><c-s>gv |
− | imap |
+ | imap <c-s> <Esc><c-s> |
− | nmap |
+ | nmap <F2> :update<CR> |
− | vmap |
+ | vmap <F2> <Esc><F2>gv |
− | imap |
+ | imap <F2> <c-o><F2> |
</pre> |
</pre> |
||
Line 45: | 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. |
+ | 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
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).