-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzsh-vim-mode.zsh
More file actions
117 lines (101 loc) · 2.86 KB
/
zsh-vim-mode.zsh
File metadata and controls
117 lines (101 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
bindkey -v
DEFAULT_VI_MODE=viins
# set -o emacs
KEYTIMEOUT=1
#######################################
###### keymap in the insert mode ######
#######################################
bindkey '^p' up-history
bindkey '^n' down-history
bindkey '^f' forward-char
bindkey '^b' backward-char
bindkey '^d' delete-char
bindkey '^?' backward-delete-char
bindkey '^h' backward-delete-char
bindkey '^w' backward-kill-word
# if not use fzf, uncomment the following command.
# bindkey '^r' history-incremental-search-backward
bindkey '^a' beginning-of-line
bindkey '^e' end-of-line
# Delete key, alacritty
bindkey '[P' delete-char
#######################################
###### keymap in the normal mode ######
#######################################
bindkey -M vicmd '[P' delete-char
bindkey -M vicmd 'H' beginning-of-line
bindkey -M vicmd 'L' end-of-line
# use '/' to search command history, and '=' to repeat. But fzf is more convenient.
bindkey -M vicmd '/' history-incremental-search-backward
bindkey -M vicmd '=' vi-repeat-search
# if not use fzf, uncomment the following command.
# bindkey -M vicmd '^r' history-incremental-search-backward
# Allows you to open the in-progress command inside of $EDITOR
autoload -Uz edit-command-line
zle -N edit-command-line
bindkey -M vicmd 'v' edit-command-line
# Yank to the system clipboard
function vi-yank-xclip {
zle vi-yank
echo "$CUTBUFFER" | xclip -selection clipboard
}
zle -N vi-yank-xclip
bindkey -M vicmd 'Y' vi-yank-xclip
# Prefer vi shortcuts
__set_cursor() {
local style
case $1 in
reset) style=0;; # The terminal emulator's default
blink-block) style=1;;
block) style=2;;
blink-underline) style=3;;
underline) style=4;;
blink-vertical-line) style=5;;
vertical-line) style=6;;
esac
[ $style -ge 0 ] && print -n -- "\e[${style} q"
}
# Set your desired cursors here...
__set_vi_mode_cursor() {
case $KEYMAP in
vicmd)
__set_cursor block
;;
main|viins)
__set_cursor vertical-line
;;
esac
}
# red black yellow green
# cyan white magenta blue
__get_vi_mode() {
local mode
case $KEYMAP in
vicmd)
mode='%B%F{red}NORMAL'
;;
main|viins)
mode=
;;
esac
print -n -- $mode
}
zle-line-init() {
zle -K $DEFAULT_VI_MODE
}
zle-keymap-select() {
__set_vi_mode_cursor
zle reset-prompt
}
zle-line-finish() {
# Let applications manage their own cursor
__set_cursor reset
}
zle -N zle-line-init
zle -N zle-keymap-select
zle -N zle-line-finish
# PROMPT_SUBST enables functions and variables to re-run everytime the prompt is rendered
# perform parameter expansion/command substitution in prompt
# setopt PROMPT_SUBST
# Single quotes are important so that function is not run immediately and saved in the variable
RPROMPT='$(__get_vi_mode)'