# Marks
declare-user-mode set-mark
map global normal M ': enter-user-mode set-mark<ret>'
map global set-mark a ': set-mark a<ret>'
define-command set-mark -docstring "set-mark [<register>]: save selection to <register>" -params 1 %{
execute-keys %sh{ echo '"'"$1"Z }
}
declare-user-mode restore-mark
map global normal m ': enter-user-mode restore-mark<ret>'
map global restore-mark a ': restore-mark a<ret>'
define-command restore-mark -docstring "restore-mark [<register>]: restore selection from <register>" -params 1 %{
execute-keys %sh{ echo '"'"$1"z }
}
The basic idea is I can type Ma to create a selection and ma to restore it. However, the only way I know how to pass the register into the set-mark and restore-mark commands is by creating a user-mode mapping for every single register. Is there a less hacky way to do it?
Bonus question: is there a less hacky way to run execute keys "%opt{1}Z? I can’t get the escaping right unless I use %sh{}
If I understand well, you want a way to mark a place in your buffer so that you can go back to it easily later. The default bindings I find horrible, with " which is already hard to reach on my keyboard, plus Z which is hard to reach too. To solve the issue, I have mapped easier keys to the following two commands:
define-command \
-hidden \
mark-place %{
info 'Mark place with <letter>'
on-key %{
try %{
evaluate-commands %sh{
! expr "$kak_key" : '[a-z]' >/dev/null && printf %s\\n fail
}
execute-keys %{"} %val(key) Z
echo "Marked place as %val(key)"
} \
catch %{
echo 'Nothing marked'
}
}
}
define-command \
-hidden \
goto-place %{
info 'Go to place <letter>'
on-key %{
try %{
execute-keys %{"} %val(key) z v c
echo "Back to %val(key)"
}
}
}
These commands allow me to mark a place with a letter from a to z, and come back to it easily.