Skip to content

Commit

Permalink
[sorin-ionescu#127] Add an indicator for overwrite mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sorin-ionescu committed Apr 11, 2012
1 parent a18d31a commit d2f87da
Showing 1 changed file with 66 additions and 9 deletions.
75 changes: 66 additions & 9 deletions modules/editor/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@
#
# zstyle ':omz:module:editor:keymap' primary '>>>'
#
# To indicate when the editor is in the alternate keymap (vicmd), add the
# following to your theme prompt setup function.
# To indicate when the editor is in the primary keymap (emacs or viins) insert
# mode, add the following to your theme prompt setup function.
#
# zstyle ':omz:module:editor:keymap:primary' insert 'I'
#
# To indicate when the editor is in the primary keymap (emacs or viins) overwrite
# mode, add the following to your theme prompt setup function.
#
# zstyle ':omz:module:editor:keymap:primary' overwrite 'O'
#
# To indicate when the editor is in the alternate keymap (vicmd), add the following
# to your theme prompt setup function.
#
# zstyle ':omz:module:editor:keymap' alternate '<<<'
#
Expand All @@ -44,7 +54,7 @@ zle -N edit-command-line

# Use human-friendly identifiers.
zmodload zsh/terminfo
typeset -gA key_info editor_info
typeset -gA key_info
key_info=(
'Control' '\C-'
'Escape' '\e'
Expand Down Expand Up @@ -83,24 +93,71 @@ for key in "$key_info[@]"; do
fi
done

# Displays the current vi mode.
function zle-line-init zle-line-finish zle-keymap-select {
# Displays editor information.
function editor-info {
# Clean up previous $editor_info.
unset editor_info
typeset -gA editor_info

if [[ "$KEYMAP" == 'vicmd' ]]; then
zstyle -s ':omz:module:editor:keymap' alternate 'REPLY'
editor_info[keymap]="$REPLY"
else
zstyle -s ':omz:module:editor:keymap' primary 'REPLY'
editor_info[keymap]="$REPLY"

if [[ "$ZLE_STATE" == *overwrite* ]]; then
zstyle -s ':omz:module:editor:keymap:primary' overwrite 'REPLY'
editor_info[overwrite]="$REPLY"
else
zstyle -s ':omz:module:editor:keymap:primary' insert 'REPLY'
editor_info[overwrite]="$REPLY"
fi
fi

editor_info[keymap]="$REPLY"

unset REPLY

zle reset-prompt
zle -R
}
zle -N zle-line-init
zle -N zle-line-finish
zle -N editor-info

# Updates editor information when the keymap changes.
function zle-keymap-select zle-line-init zle-line-finish {
zle editor-info
}
zle -N zle-keymap-select
zle -N zle-line-finish
zle -N zle-line-init

# Toggles emacs overwrite mode and updates editor information.
function overwrite-mode {
zle .overwrite-mode
zle editor-info
}
zle -N overwrite-mode

# Enters vi insert mode and updates editor information.
function vi-insert {
zle .vi-insert
zle editor-info
}
zle -N vi-insert

# Moves to the first non-blank character then enters vi insert mode and updates
# editor information.
function vi-insert-bol {
zle .vi-insert-bol
zle editor-info
}
zle -N vi-insert-bol

# Enters vi replace mode and updates editor information.
function vi-replace {
zle .vi-replace
zle editor-info
}
zle -N vi-replace

# Expands .... to ../..
function expand-dot-to-parent-directory-path {
Expand Down

0 comments on commit d2f87da

Please sign in to comment.