From 270fe43f47c2af14d923bbc8253b5c3792935144 Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Wed, 1 Nov 2017 17:24:20 -0700 Subject: [PATCH] [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 --- modules/editor/init.zsh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/modules/editor/init.zsh b/modules/editor/init.zsh index 2e821b3a..e42d45c7 100644 --- a/modules/editor/init.zsh +++ b/modules/editor/init.zsh @@ -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 #