Vim Tips Wiki
Register
No edit summary
(Clean out todo)
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 was tested under Debian with Vim 7.1 (console version).
 
 
==Description==
 
This Tip explains how to cycle between several registers, while accessing their content through the standard register.
 
   
==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>
Line 37: Line 33:
 
map s :let @x=@" \| let @"=@a \| let @a=@b \| let @b=@x \| reg "ab <CR>
 
map s :let @x=@" \| let @"=@a \| let @a=@b \| let @b=@x \| reg "ab <CR>
 
</pre>
 
</pre>
  +
 
This tip was tested under Debian with Vim 7.1 (console version).
   
 
==References==
 
==References==
 
*{{help|:let}}
 
*{{help|:let}}
 
*{{help|:reg}}
 
*{{help|:reg}}
*{{help|:registers}} - does not lead to the right place (type :help registers in vim)
+
*{{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
 

Revision as of 23:30, 30 April 2008

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created April 29, 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:

map s :let @x=@" \| let @"=@a \| let @a=@b \| let @b=@x <CR>

Now you can cycle between the registers "", "a, "b by pressing s.

  • :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:

map 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:

map s :let @x=@" \| let @"=@a \| let @a=@b \| let @b=@x \| reg "ab <CR>

This tip was tested under Debian with Vim 7.1 (console version).

References

Comments