Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions modules/editor/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ key_info=(
'Control' '\C-'
'ControlLeft' '\e[1;5D \e[5D \e\e[D \eOd'
'ControlRight' '\e[1;5C \e[5C \e\e[C \eOc'
'ControlPageUp' '\e[5;5~'
'ControlPageDown' '\e[6;5~'
'ControlPageUp' '\e[5;5~ \e[5~'
'ControlPageDown' '\e[6;5~ \e[6~'
'ControlUp' '\e[1;5A \e[A'
'ControlDown' '\e[1;5B \e[B'
'ControlHome' '\e[1;5H \e[1~'
'ControlEnd' '\e[1;5F'
'ControlInsert' '\e[2;5~'
'ControlDelete' '\e[3;5~'
'Escape' '\e'
'Meta' '\M-'
'Backspace' "^?"
Expand Down Expand Up @@ -234,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

Expand Down Expand Up @@ -288,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
#
Expand Down