Skip to content

Commit

Permalink
Workaround for bug in zsh's vi mode
Browse files Browse the repository at this point in the history
Found here: hchbaw/opp.zsh#1
Config borrowed from here: ryanpetrello/dotfiles:ddfdcc95
Additionally, it allows for the cursor shape to change based on which
mode you are in (huzzah!)
  • Loading branch information
zhimsel committed Mar 3, 2015
1 parent dd6ee63 commit ac56d97
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions .zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,41 @@ compinit -u
# prompt settings
PROMPT="${user_host} ${current_dir} ${rvm_ruby} ${git_branch}
%B$%b "
precmd() {
RPROMPT=""
}
zle-keymap-select() {
RPROMPT=""
[[ $KEYMAP = vicmd ]] && RPROMPT="(CMD)"
() { return $__prompt_status }
zle reset-prompt

# Show a different cursor for different vim modes
function zle-keymap-select zle-line-init
{
# change cursor shape in iTerm2
if [[ $TMUX != "" ]]
then
case $KEYMAP in
vicmd) print -n -- "\033Ptmux;\033\E]50;CursorShape=0\C-G\033\\";; # block cursor
viins|main) print -n -- "\033Ptmux;\033\E]50;CursorShape=1\C-G\033\\";; # line cursor
esac
else
case $KEYMAP in
vicmd) print -n -- "\E]50;CursorShape=0\C-G";; # block cursor
viins|main) print -n -- "\E]50;CursorShape=1\C-G";; # line cursor
esac
fi

zle reset-prompt
zle -R
}
zle-line-init() {
typeset -g __prompt_status="$?"

function zle-line-finish
{
if [[ $TMUX != "" ]]
then
print -n -- "\033Ptmux;\033\E]50;CursorShape=0\C-G\033\\"
else
print -n -- "\E]50;CursorShape=0\C-G"
fi
}
zle -N zle-keymap-select

zle -N zle-line-init
zle -N zle-line-finish
zle -N zle-keymap-select

# load machine-specific options
if [ -f ~/.zshrc-local ]; then
Expand Down

0 comments on commit ac56d97

Please sign in to comment.