Vim Tips Wiki
Register
(Add TipProposed + comments + todo (thanks Benshi for the new tip!))
No edit summary
Line 13: Line 13:
 
This tip was tested under Debian with Vim 7.1 (console version).
 
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>
map s :let @x=@" \| let @"=@a \| let @a=@b \| let @b=@x <Return>
+
map s :let @x=@" \| let @"=@a \| let @a=@b \| let @b=@x <CR>
 
</pre>
 
</pre>
   
Line 24: Line 28:
 
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>
map s :let @a=@" \| let @"=@+ \| let @+=@a <Return>
+
map 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.
   
 
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>
map s :let @x=@" \| let @"=@a \| let @a=@b \| let @b=@x \| reg "ab <Return>
+
map s :let @x=@" \| let @"=@a \| let @a=@b \| let @b=@x \| reg "ab <CR>
 
</pre>
 
</pre>
   
Line 35: Line 41:
 
*{{help|:let}}
 
*{{help|:let}}
 
*{{help|:reg}}
 
*{{help|:reg}}
  +
*{{help|:registers}} - does not lead to the right place (type :help registers in vim)
*{{help|:reg}}
 
 
*{{help|map_bar}}
 
*{{help|map_bar}}
   
 
==Comments==
 
==Comments==
 
{{Todo}}
 
{{Todo}}
*It would be nice to start the tip by describing what we're trying to achieve.
+
*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.
+
*Perhaps replace <tt><Return></tt> with the <tt><CR></tt> which most other tips use. - done

Revision as of 14:52, 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 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:

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>

References

Comments

 TO DO 

  • It would be nice to start the tip by describing what we're trying to achieve. - done
  • Perhaps replace <Return> with the <CR> which most other tips use. - done