I have a slightly modified implementation of this to avoid a minor issue. In the case with multiple cursors where some are already at the first non-blank and others are not, the solution using -itersel
will make each cursor alternate between home and the first non-blank, making it impossible to get every cursor to one or the other.
define-command -hidden -params 1 home-movement %{
try %{
exec -draft <a-h><a-K>\A\h*.\z<ret> # Remove all selections preceeded by whitespace.
exec %arg{1} i # If there are any selections left, go to the first non-blank.
} catch %{
exec %arg{1} h # If every selection was preceeded by whitespace, go home.
}
}
map global normal <home> ': home-movement g<ret>'
map global normal <s-home> ': home-movement G<ret>'
As an aside, I could not figure out how to get this to work in insert mode. Using a mapping like:
map global insert <home> "<a-;>: home-movement g<ret>"
Just caused “gi” characters to be inserted into the document. Is there some way to make the keys specified by exec
run in normal mode when the editor is insert mode?