1
0
Fork 0

[editor] Add 'gg' and 'G' to vicmd mode

G Moves to the start of the last line if no numeric argument. Otherwise goes
to the line number. 9G goes to the 9th line. 1G to the 1st line.

By default "gg" is bound to beginning-of-buffer-or-history for viins, which
causes inconsistent things to happen (moving to the first history entry).
Bind move-to-buffer-beginning so it acts more like vim
pull/1502/head
Samantha McVey 7 years ago
parent ae85d3a1ac
commit 270fe43f47
No known key found for this signature in database
GPG Key ID: A68DF012C3881D62

@ -240,6 +240,26 @@ function glob-alias {
} }
zle -N glob-alias zle -N glob-alias
# Moves to the beginning of the buffer (as opposed to beginning of the line)
function zle-move-to-buffer-beginning {
CURSOR=0
}
zle -N zle-move-to-buffer-beginning
# Moves to the specified line number. In vi mode number is supplied first,
# then the bound key
function zle-move-to-line {
if [[ $NUMERIC ]]; then
CURSOR=0
NUMERIC=$(( $NUMERIC - 1 ))
zle down-line
else
CURSOR=$(( ${#BUFFER} - 1 ))
zle vi-beginning-of-line
fi
}
zle -N zle-move-to-line
# Reset to default key bindings. # Reset to default key bindings.
bindkey -d bindkey -d
@ -294,6 +314,15 @@ else
bindkey -M vicmd "/" history-incremental-search-forward bindkey -M vicmd "/" history-incremental-search-forward
fi fi
# G Moves to the start of the last line if no numeric argument. Otherwise goes
# to the line number. 9G goes to the 9th line. 1G to the 1st line.
bindkey -M vicmd "G" zle-move-to-line
# By default "gg" is bound to beginning-of-buffer-or-history for viins, which
# causes inconsistent things to happen (moving to the first history entry).
# Bind move-to-buffer-beginning so it acts more like vim
bindkey -M vicmd "gg" zle-move-to-buffer-beginning
# #
# Emacs and Vi Key Bindings # Emacs and Vi Key Bindings
# #

Loading…
Cancel
Save