Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cursor shape configurale #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions vim.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
bindkey -v
export KEYTIMEOUT=25

if [[ -o menucomplete ]]; then
VICMD=${VICMD:-'\e[1 q'} # defaults to block
VIINS=${VIINS:-'\e[5 q'} # defaults to beam

if [[ -o menucomplete ]]; then
# Use vim keys in tab complete menu:
bindkey -M menuselect '^h' vi-backward-char
bindkey -M menuselect '^k' vi-up-line-or-history
Expand All @@ -16,22 +19,22 @@ bindkey -v '^?' backward-delete-char
# Change cursor shape for different vi modes.
function zle-keymap-select () {
case $KEYMAP in
vicmd) echo -ne '\e[1 q';; # block
viins|main) echo -ne '\e[5 q';; # beam
vicmd) echo -ne ${VICMD};; # block
viins|main) echo -ne ${VIINS};; # beam
esac
}
zle -N zle-keymap-select
zle-line-init() {
zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
echo -ne "\e[5 q"
echo -ne ${VIINS}
}
zle -N zle-line-init
echo -ne '\e[5 q' # Use beam shape cursor on startup.
preexec() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt.
echo -ne ${VIINS} # Use beam shape cursor on startup.
preexec() { echo -ne ${VIINS} ;} # Use beam shape cursor for each new prompt.

# emacs like keybindings
bindkey -M viins '^A' beginning-of-line
bindkey -M viins '^E' end-of-line
bindkey -M viins '^A' beginning-of-line
bindkey -M viins '^E' end-of-line

# Add text objects for quotes and brackets.
autoload -Uz select-bracketed select-quoted
Expand All @@ -58,4 +61,4 @@ bindkey -M visual S add-surround
# escape back into normal mode
if [[ -n "${VI_MODE_ESC_INSERT}" ]] then
bindkey -M viins "${VI_MODE_ESC_INSERT}" vi-cmd-mode
fi
fi