Vim Tips Wiki
Register
(Easily circle between registers and access them through the unnamed register.)
 
No edit summary
Line 3: Line 3:
 
To easily swap between different registers in Vim it is convenient to map a sequence to move all in a "circled list". See the following mapping to understand it:
 
To easily swap between different registers in Vim it is convenient to map a sequence to move all in a "circled list". See the following mapping to understand it:
   
map s :let @x=@" <Return> :let @"=@a <Return> :let @a=@b <Return> :let @b=@x <Return>
+
''map s :let @x=@" <Return> :let @"=@a <Return> :let @a=@b <Return> :let @b=@x <Return>''
   
 
Now you can circle between the registers "", "a, "b with s.
 
Now you can circle between the registers "", "a, "b with s.
(:let @a=@b copies register "b to register "a)
+
('':let @a=@b'' copies register "b to register "a)
   
 
This is also usefull if you want to copy between xclipboard and the unnamed standard register of Vim:
 
This is also usefull if you want to copy between xclipboard and the unnamed standard register of Vim:
map s :let @a=@" <Return> :let @"=@+ <Return> :let @+=@a <Return>
+
''map s :let @a=@" <Return> :let @"=@+ <Return> :let @+=@a <Return>''
   
 
To see, what ist changing, you could modify the command above like this:
 
To see, what ist changing, you could modify the command above like this:
map s :let @x=@" <Return> :let @"=@a <Return> :let @a=@b <Return> :let @b=@x <Return> :reg "ab <Return>
+
''map s :let @x=@" <Return> :let @"=@a <Return> :let @a=@b <Return> :let @b=@x <Return> :reg "ab <Return>''
   
 
For further Information see:
 
For further Information see:
:help let
+
'':help let''
:help reg
+
'':help reg''
:help registers
+
'':help registers''

Revision as of 11:16, 29 April 2008

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

To easily swap between different registers in Vim it is convenient to map a sequence to move all in a "circled list". See the following mapping to understand it:

map s :let @x=@" <Return> :let @"=@a <Return> :let @a=@b <Return> :let @b=@x <Return>

Now you can circle between the registers "", "a, "b with s. (:let @a=@b copies register "b to register "a)

This is also usefull if you want to copy between xclipboard and the unnamed standard register of Vim: map s :let @a=@" <Return> :let @"=@+ <Return> :let @+=@a <Return>

To see, what ist changing, you could modify the command above like this: map s :let @x=@" <Return> :let @"=@a <Return> :let @a=@b <Return> :let @b=@x <Return> :reg "ab <Return>

For further Information see: :help let :help reg :help registers