mirror of
https://github.com/dcarrillo/prezto.git
synced 2024-12-22 12:48:01 +00:00
Add pound-toggle
zle widget to work around the buggy built-in pound-insert
Refs #1533, #1534
This commit is contained in:
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…
Reference in New Issue
Block a user