Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).
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
- :help :let
- :help :reg
- :help :registers - does not lead to the right place (type :help registers in vim)
- :help map_bar
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