For those who want to know more about jasonwryan'a answer
This is the mentioned file:
# function history-search-end {
#
# This implements functions like history-beginning-search-{back,for}ward,
# but takes the cursor to the end of the line after moving in the
# history, like history-search-{back,for}ward. To use them:
# zle -N history-beginning-search-backward-end history-search-end
# zle -N history-beginning-search-forward-end history-search-end
# bindkey '...' history-beginning-search-backward-end
# bindkey '...' history-beginning-search-forward-end
integer cursor=$CURSOR mark=$MARK
if [[ $LASTWIDGET = history-beginning-search-*-end ]]; then
# Last widget called set $MARK.
CURSOR=$MARK
else
MARK=$CURSOR
fi
if zle .${WIDGET%-end}; then
# success, go to end of line
zle .end-of-line
else
# failure, restore position
CURSOR=$cursor
MARK=$mark
return 1
fi
# }
zle -N widget [ function ]
: Create a user-defined widget.
When the new widget is invoked from within the editor, the specified shell function is called.
If no function name is specified, it defaults to the same name as the widget.
It is recommended that user-defined widgets should not have names starting with .
.
# To make history-beginning-search-{back,or}ward-end an alias for history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
# why `history-beginning-search-{back,or}ward-end` is chosen?
# There is widgets named `history-beginning-search-{back,or}ward`,
# so just add 'end' to them, showing their relevance.
I think, (not quite sure), without this line if [[ $LASTWIDGET = history-beginning-search-*-end ]]
in the file above file, the code
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^[[A" history-beginning-search-backward-end
bindkey "^[[B" history-beginning-search-forward-end
can be replaced by:
bindkey "^[[A" history-search-end
bindkey "^[[B" history-search-end
# less word to type
(Just to show the usage of zle
and bindkey
.
Now that we have that if
line, don't use the simplified one.)
zsh's bindkey
command
bindkey -v
: select viins keymap and bind it to main
bindkey -e
: select emacs keymap and bind it to main
-A
: create alias (aka link)
bindkey -A viins main
makes viins
an alias for main
Either emacs
or viins
is linked to the name main
.
If one of the VISUAL
or EDITOR
environment variables contain the string vi
when the shell starts up,
then it will be viins
,
otherwise it will be emacs
.
Create a new keymap from emacs
:
bindkey -N mymapname emacs
To use "mymap":
bindkey -A mymapname main