Vim Tips Wiki

Comfortable handling of registers

1,624pages on
this wiki
Add New Page
Talk0 Share
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>



Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki