Skip to content

Commit

Permalink
Show vim mode with a cursor, not a color change.
Browse files Browse the repository at this point in the history
Additionally, work around a zsh + vim mode + opp.zsh bug:
hchbaw/opp.zsh#1
  • Loading branch information
ryanpetrello committed Sep 3, 2014
1 parent 4121f8f commit ddfdcc9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ bind-key -r J resize-pane -D 2
bind-key -r K resize-pane -U 2
bind-key -r H resize-pane -L 10
bind-key -r L resize-pane -R 10

set-option -g terminal-overrides '*88col*:colors=88,*256col*:colors=256,xterm*:XT:Ms=\E]52;%p1%s;%p2%s\007:Cs=\E]12;%p1%s\007:Cr=\E]112\007:Ss=\E]50;CursorShape=%?%p1%{3}%<%t%{0}%e%p1%{2}%-%;%d\007'
6 changes: 6 additions & 0 deletions .vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,9 @@ let g:ctrlp_prompt_mappings = {

" Auto-open a split pane with an applicable diff for git commits
autocmd FileType gitcommit DiffGitCached | wincmd L | wincmd p | vertical resize 83

" Change cursor shape between insert and normal mode in iTerm2.app
if $TERM_PROGRAM =~ "iTerm"
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\" " Vertical bar in insert mode
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\" " Block in normal mode
endif
46 changes: 42 additions & 4 deletions .zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,54 @@ precmd () {
local git='$vcs_info_msg_0_'

# Custom status line
PS1="[`hostname | sed 's/\..*//'`] $(active_virtualenv)${git}${fg_lblue}%~ ${fg_white}$ "
PS1="[`hostname | sed 's/\..*//'`] $(active_virtualenv)${git}${fg_lblue}%~ ${fg_white}"

# 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

# Show a green $ on the status line when vim mode is -- INSERT --
function zle-line-init zle-keymap-select {
PS1="[`hostname | sed 's/\..*//'`] $(active_virtualenv)${git}${fg_lblue}%~ ${fg_lgreen}${${KEYMAP/vicmd/}/(main|viins)/$}${fg_white}${${KEYMAP/vicmd/$}/(main|viins)/}${fg_white} "
zle reset-prompt
zle -R
}

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-line-init
zle -N zle-line-finish
zle -N zle-keymap-select

# # 10ms for key sequences
KEYTIMEOUT=1

# init cursor, apparently only needed for tmux, but left the conditional for consistency
if [[ $TMUX != "" ]]
then
print -n -- "\033Ptmux;\033\E]50;CursorShape=0\C-G\033\\"
else
print -n -- "\E]50;CursorShape=0\C-G"
fi

# -----------------------------------------------
# Set up zsh-specifics
# -----------------------------------------------
Expand Down

0 comments on commit ddfdcc9

Please sign in to comment.