Small snippet if you are missing vim's marks

I was missing vim’s way to quickly mark a spot and jump to it right after. So I created a small snippet to do it:

define-command create-mark -docstring 'create a mark' %{
    on-key %{
        execute-keys  """%val{key}Z"
define-command goto-mark -docstring 'goto a mark' %{
    on-key %{
        execute-keys  """%val{key}z"
map global normal <a-'> ":create-mark<ret>"
map global normal \'    ":goto-mark<ret>"

You might want to add vv at the end of the execute-keys if you want to center the window after moving.


I like the new order. "{register}<command> is difficult to reach. <command>{register} is much easier.

How about mapping them to z and Z?

map global normal -docstring 'Restore selections from register' z ': restore-selections<ret>'
map global normal -docstring 'Save selections to register' Z ': save-selections<ret>'

Hmm I didn’t realise I switched the oreder :0 , is not very orthodox :slight_smile: !

If I understand you well, I see one problem : you will loose the default register feature: pressing z or Z is a shortcut for "^z or "^Z respectively.

So it’s a tread off : having to always press 2 keystrokes ( z + {register} ) , or having to press 1 keystroke in most cases and 3 keystoke from time to time ( z or "{register}z )

I guess it depend on how you use it.

In the first case you can also use z as a register, so you have to press zz which is close to pressing one keystroke.

I would have naturally pressed zz and ZZ. Not sure if they are same. :thinking: