Preloading registers

From Vim Tips Wiki

Jump to: navigation, search
Tip 792 Printable Monobook Previous Next

created 2004 · complexity basic · author zzapper · version 5.7

There never seem to be enough spare keys for maps.

It's possible however to preload Vim's registers in vimrc with your frequent commands, for example:

let @m=":'a,'bs/"
let @s=":%!sort -u"

Here's a twisted one

let @y='yy@"'

The command is executed by doing a @m

You can overwrite them of course when doing a recording or a plain yank; I prefer to leave registers a-q for yanks or recordings and preload the others.

[edit] Comments

> Never seems to be enough keys to map

Why not use prefix and/or virtual keys like gnu-emacs? Then refer to it by the virtual name.

Also I think Gvim supports 5 Xmodifiers as in gnu-emacs, (C-M-S-H-s-A-<key>) = (2^6 * 40) 2500 should be enough?

All your mappings go into ,<key> (personally I like named keys) and in emacs, I can invoke by name with completions, if I forget the mapping.

I already have 96 maps many with two character combinations using , and <Leader>.Preloading registers is just a possible alternative, and maybe avoids some of the syntaxical restrictions of maps,as they contain command sequences just as you would type them ie a recording'.

Personal tools