[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
This commit is contained in:
parent
ae85d3a1ac
commit
270fe43f47
1 changed files with 29 additions and 0 deletions
|
@ -240,6 +240,26 @@ function 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.
|
||||
bindkey -d
|
||||
|
||||
|
@ -294,6 +314,15 @@ else
|
|||
bindkey -M vicmd "/" history-incremental-search-forward
|
||||
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
|
||||
#
|
||||
|
|
Loading…
Add table
Reference in a new issue