1
0
Fork 0

Add `pound-toggle` zle widget to work around the buggy built-in `pound-insert`

Refs #1533, #1534
pull/1537/head
Kaleb Elwert 7 years ago
parent 906ac99e20
commit 904eef5fa5

@ -241,6 +241,24 @@ function glob-alias {
}
zle -N glob-alias
# Toggle the comment character at the start of the line. This is meant to work
# around a buggy implementation of pound-insert in zsh.
function pound-toggle {
if [[ "$BUFFER" = '#'* ]]; then
# Because of an oddity in how zsh handles the cursor when the buffer size
# changes, we need to make this check before we modify the buffer and let
# zsh handle moving the cursor back if it's past the end of the line.
if [[ $CURSOR != $#BUFFER ]]; then
(( CURSOR -= 1 ))
fi
BUFFER="${BUFFER:1}"
else
BUFFER="#$BUFFER"
(( CURSOR += 1 ))
fi
}
zle -N pound-toggle
# Reset to default key bindings.
bindkey -d
@ -276,6 +294,10 @@ if (( $+widgets[history-incremental-pattern-search-backward] )); then
history-incremental-pattern-search-forward
fi
# Toggle comment at the start of the line.
bindkey -M emacs "$key_info[Escape];" pound-toggle
#
# Vi Key Bindings
#

Loading…
Cancel
Save