Skip to content

Instantly share code, notes, and snippets.

@danr
Created September 19, 2017 08:15
Show Gist options
  • Save danr/3556a7d817d84a1abb0cbcfaed23e240 to your computer and use it in GitHub Desktop.
Save danr/3556a7d817d84a1abb0cbcfaed23e240 to your computer and use it in GitHub Desktop.
Selecting and wrapping with xml tags in kakoune
def div -params 0..1 -docstring %{Wraps selected text with a tag and indents it.
The parameter can be omitted and then defaults to div.} %{
eval -itersel %{
exec <a-:><a-x>H Zo< / %sh{[ -n "$1" ] && echo "$1" || echo "div"} ><esc><a-x>yz<A-P>s/<ret>dz>
}
}
def select-tag -docstring %{Selects xml tag from start to end.
Assumptions:
- Start tag begins on an own line
- Closing tag has the same indentation as start tag or tag is self-closing} %{
eval -itersel %{
try %{
exec <a-/> ^(\h*) <([\w.]+) <ret> ?<c-r>1 < / <c-r>2 ><ret>
} catch %{
exec ? /> <ret>
}
}
}
alias global st select-tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment