Skip to content

Instantly share code, notes, and snippets.

@clevinson
Created August 30, 2016 15:18
Show Gist options
  • Save clevinson/d6b551248ba680fc2594eeb613a7d64c to your computer and use it in GitHub Desktop.
Save clevinson/d6b551248ba680fc2594eeb613a7d64c to your computer and use it in GitHub Desktop.
# Functions / helpers for setting cursor shape
function print_dcs
{
print -n -- "\EP$1;\E$2\E\\"
}
function set_cursor_shape
{
if [ -n "$TMUX" ]; then
# tmux will only forward escape sequences to the terminal if surrounded by
# a DCS sequence
print_dcs tmux "\E]50;CursorShape=$1\C-G"
else
print -n -- "\E]50;CursorShape=$1\C-G"
fi
}
function zle-keymap-select zle-line-init zle-line-finish {
case $KEYMAP in
vicmd) set_cursor_shape 0;; # block cursor
viins|main) set_cursor_shape 2;; # line cursor
esac
}
zle -N zle-keymap-select
zle -N zle-line-init
zle -N zle-line-finish
zle -N edit-command-line
bindkey -v
# allow v to edit the command line (standard behaviour)
autoload -Uz edit-command-line
bindkey -M vicmd 'v' edit-command-line
# allow ctrl-p, ctrl-n for navigate history (standard behaviour)
bindkey '^P' up-history
bindkey '^N' down-history
bindkey '^r' history-incremental-search-backward
# allow ctrl-a, ctrl-e for shortcuts to beginning & end of line
bindkey '^a' beginning-of-line
bindkey '^e' end-of-line
# allow ctrl-h, ctrl-w, ctrl-?, ctrl-[[3~ for char and word deletion (standard behaviour)
bindkey '^?' backward-delete-char
bindkey '^h' backward-delete-char
bindkey '^w' backward-kill-word
bindkey '[3~' delete-char
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment