No edit summary |
(Change <tt> to <code>, perhaps also minor tweak.) |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{TipNew |
||
− | {{TipProposed |
||
− | |id= |
+ | |id=1562 |
− | |previous= |
+ | |previous=1561 |
− | |next= |
+ | |next=1563 |
− | |created= |
+ | |created=2008 |
|complexity=basic |
|complexity=basic |
||
|author=[[User:Benshi|Benshi]] |
|author=[[User:Benshi|Benshi]] |
||
|version=7.0 |
|version=7.0 |
||
|subpage=/200804 |
|subpage=/200804 |
||
− | |category1= |
+ | |category1=Registers |
|category2= |
|category2= |
||
}} |
}} |
||
⚫ | |||
− | This tip was tested under Debian with Vim 7.1 (console version). |
||
− | ==Description== |
||
⚫ | |||
− | |||
− | ==Content== |
||
To easily swap between different registers it is convenient to map a key to move the registers in a "circular list". The following mapping illustrates the idea: |
To easily swap between different registers it is convenient to map a key to move the registers in a "circular list". The following mapping illustrates the idea: |
||
<pre> |
<pre> |
||
− | + | :nnoremap <Leader>s :let @x=@" \| let @"=@a \| let @a=@b \| let @b=@x<CR> |
|
</pre> |
</pre> |
||
− | Now you can cycle between the registers < |
+ | Now you can cycle between the registers <code>""</code>, <code>"a</code>, <code>"b</code> by pressing <code>\s</code> (assuming the default backslash for the leader key). |
− | *< |
+ | *<code>:let @a=@b</code> copies register <code>"b</code> to register <code>"a</code>. |
− | *< |
+ | *<code>|</code> separates Ex commands; <code>\</code> escapes the pipe for the map command. |
This is also useful if you want to copy between the xclipboard and the unnamed standard register of Vim: |
This is also useful if you want to copy between the xclipboard and the unnamed standard register of Vim: |
||
<pre> |
<pre> |
||
− | + | :nnoremap <Leader>s :let @a=@" \| let @"=@+ \| let @+=@a<CR> |
|
</pre> |
</pre> |
||
− | Another usage can be found in cycling through the cut/copy history i.e. cycling through the numbered registers. |
+ | Another usage can be found in cycling through the cut/copy history, i.e. cycling through the numbered registers. |
To see what it's changing, you could modify the command like this: |
To see what it's changing, you could modify the command like this: |
||
<pre> |
<pre> |
||
− | + | :nnoremap <Leader>s :let @x=@" \| let @"=@a \| let @a=@b \| let @b=@x \| reg "ab<CR> |
|
</pre> |
</pre> |
||
Line 41: | Line 37: | ||
*{{help|:let}} |
*{{help|:let}} |
||
*{{help|:reg}} |
*{{help|:reg}} |
||
− | *{{help| |
+ | *{{help|registers}} |
*{{help|map_bar}} |
*{{help|map_bar}} |
||
==Comments== |
==Comments== |
||
− | {{Todo}} |
||
− | *It would be nice to start the tip by describing what we're trying to achieve. - done |
||
− | *Perhaps replace <tt><Return></tt> with the <tt><CR></tt> which most other tips use. - done |
Latest revision as of 06:33, 13 July 2012
created 2008 · complexity basic · author Benshi · version 7.0
This tip explains how to cycle between several registers, while accessing their content through the standard "unnamed" register (@"
).
To easily swap between different registers it is convenient to map a key to move the registers in a "circular list". The following mapping illustrates the idea:
:nnoremap <Leader>s :let @x=@" \| let @"=@a \| let @a=@b \| let @b=@x<CR>
Now you can cycle between the registers ""
, "a
, "b
by pressing \s
(assuming the default backslash for the leader key).
:let @a=@b
copies register"b
to register"a
.|
separates Ex commands;\
escapes the pipe for the map command.
This is also useful if you want to copy between the xclipboard and the unnamed standard register of Vim:
:nnoremap <Leader>s :let @a=@" \| let @"=@+ \| let @+=@a<CR>
Another usage can be found in cycling through the cut/copy history, i.e. cycling through the numbered registers.
To see what it's changing, you could modify the command like this:
:nnoremap <Leader>s :let @x=@" \| let @"=@a \| let @a=@b \| let @b=@x \| reg "ab<CR>