Vim Tips Wiki
Register
(Adjust previous/next navigation)
(Change <tt> to <code>, perhaps also minor tweak.)
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
 
|previous=1561
 
|previous=1561
 
|next=1563
 
|next=1563
|created=April 29, 2008
+
|created=2008
 
|complexity=basic
 
|complexity=basic
 
|author=[[User:Benshi|Benshi]]
 
|author=[[User:Benshi|Benshi]]
Line 11: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
This tip explains how to cycle between several registers, while accessing their content through the standard "unnamed" register (<tt>@"</tt>).
+
This tip explains how to cycle between several registers, while accessing their content through the standard "unnamed" register (<code>@"</code>).
   
 
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:
Line 18: Line 18:
 
</pre>
 
</pre>
   
Now you can cycle between the registers <tt>""</tt>, <tt>"a</tt>, <tt>"b</tt> by pressing <tt>\s</tt> (assuming the default backslash for the leader key).
+
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).
*<tt>:let @a=@b</tt> copies register <tt>"b</tt> to register <tt>"a</tt>.
+
*<code>:let @a=@b</code> copies register <code>"b</code> to register <code>"a</code>.
*<tt>|</tt> separates Ex commands; <tt>\</tt> escapes the pipe for the map command.
+
*<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:

Latest revision as of 06:33, 13 July 2012

Tip 1562 Printable Monobook Previous Next

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>

References[]

Comments[]