-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvim.zsh
183 lines (162 loc) · 4.43 KB
/
nvim.zsh
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
function nvim-toggleterm {
(nvr -c ":${NUMERIC}ToggleTerm" &)
}
zle -N nvim-toggleterm
bindkey -M vicmd ' t' nvim-toggleterm
function nvim-wincmd {
read -k key
nvr -c ":${NUMERIC}wincmd $key"
}
zle -N nvim-wincmd
bindkey -M vicmd "^w" nvim-wincmd
### INSERT
function nvim-set-terminal-insert-mode {
(nvr -c "lua vim.b[$BUFNR].terminal_mode = 'INSERT'" & nvr -c "lua require('lualine').refresh( { place = { 'winbar' }})" &)
}
zle -N nvim-set-terminal-insert-mode
function nvim-set-insert-mode {
zle nvim-set-terminal-insert-mode
case $KEYS in
(a)
zle vi-add-next
;;
(A)
zle vi-add-eol
;;
(i)
zle vi-insert
;;
(C)
zle vi-change-eol
;;
(I)
zle vi-insert-bol
;;
(O)
zle vi-open-line-above
;;
(o)
zle vi-open-line-below
;;
(s)
zle vi-substitute
;;
(S)
zle vi-change-whole-line
;;
esac
}
zle -N nvim-set-insert-mode
bindkey -M vicmd 'a' nvim-set-insert-mode
bindkey -M vicmd 'A' nvim-set-insert-mode
bindkey -M vicmd 'i' nvim-set-insert-mode
bindkey -M vicmd 'C' nvim-set-insert-mode
bindkey -M vicmd 'I' nvim-set-insert-mode
bindkey -M vicmd 'O' nvim-set-insert-mode
bindkey -M vicmd 'o' nvim-set-insert-mode
bindkey -M vicmd 'S' nvim-set-insert-mode
bindkey -M vicmd 's' nvim-set-insert-mode
#### VISUAL
function nvim-set-terminal-visual-mode {
(nvr -c "lua vim.b[$BUFNR].terminal_mode = 'VISUAL'" & nvr -c "lua require('lualine').refresh( { place = { 'winbar' }})" &)
}
zle -N nvim-set-terminal-visual-mode
function nvim-set-visual-mode {
zle nvim-set-terminal-visual-mode
zle visual-mode
}
zle -N nvim-set-visual-mode
bindkey -M vicmd 'v' nvim-set-visual-mode
function nvim-deactivate-region {
zle nvim_set_buffer_terminal_mode_normal
zle deactivate-region
}
zle -N nvim-deactivate-region
bindkey -M visual '^[' nvim-deactivate-region
#### V-LINE (VISUAL-LINE)
function nvim-set-terminal-v-line-mode {
(nvr -c "lua vim.b[$BUFNR].terminal_mode = 'V-LINE'" & nvr -c "lua require('lualine').refresh( { place = { 'winbar' }})" &)
}
zle -N nvim-set-terminal-v-line-mode
function nvim-set-v-line-mode {
zle nvim-set-terminal-v-line-mode
zle visual-line-mode
}
zle -N nvim-set-v-line-mode
bindkey -M vicmd 'V' nvim-set-v-line-mode
#### O-PENDING
function nvim-set-terminal-o-pending-mode {
(nvr -c "lua vim.b[$BUFNR].terminal_mode = 'O-PENDING'" & nvr -c "lua require('lualine').refresh( { place = { 'winbar' }})" &)
}
zle -N nvim-set-terminal-o-pending-mode
function nvim-set-o-pending-mode {
case $KEYS in
(c)
if [[ $REGION_ACTIVE -eq 0 ]]
then
zle nvim-set-terminal-o-pending-mode
zle vi-change
else
zle nvim-set-terminal-insert-mode
zle vi-change
fi
;;
(d)
if [[ $REGION_ACTIVE -eq 0 ]]
then
zle nvim-set-terminal-o-pending-mode
zle vi-delete
else
zle nvim-set-terminal-insert-mode
zle vi-delete
fi
;;
esac
}
zle -N nvim-set-o-pending-mode
bindkey -M vicmd 'c' nvim-set-o-pending-mode
bindkey -M vicmd 'd' nvim-set-o-pending-mode
### NORMAL
function nvim_set_buffer_terminal_mode_normal {
(nvr -c "lua vim.b[$BUFNR].terminal_mode = 'NORMAL'" & nvr -c "lua require('lualine').refresh( { place = { 'winbar' }})" &)
}
zle -N nvim_set_buffer_terminal_mode_normal
function nvim-set-terminal-normal-mode {
zle nvim_set_buffer_terminal_mode_normal
zle vi-cmd-mode
}
zle -N nvim-set-terminal-normal-mode
bindkey -M viins '^[' nvim-set-terminal-normal-mode
bindkey -M viopp '^[' nvim-set-terminal-normal-mode
function nvim-edit-with-oil {
case $KEYS in
(\ o)
nvr -c "e $PWD"
;;
(\ e)
nvr -c "wincmd k | belowright split | e $PWD"
;;
esac
}
zle -N nvim-edit-with-oil
bindkey -M vicmd ' o' nvim-edit-with-oil
bindkey -M vicmd ' e' nvim-edit-with-oil
bindkey -M vicmd " x" execute-named-cmd
bindkey -M vicmd -r ":"
function nvim-cmd-mode {
nvr --remote-send "<C-\><C-n>:"
}
zle -N nvim-cmd-mode
bindkey -M vicmd ":" nvim-cmd-mode
export BUFNR=`nvr --remote-expr "bufnr()"`
# nvr -c "lua vim.b[$BUFNR].terminal_mode = 'INSERT'"
bindkey -rpM vicmd "^["
bindkey -rpM viins "^["
bindkey -M visual -r "^[OA"
bindkey -M visual -r "^[OB"
bindkey -M visual -r "^[[A"
bindkey -M visual -r "^[[B"
bindkey -M viopp -r "^[OA"
bindkey -M viopp -r "^[OB"
bindkey -M viopp -r "^[[A"
bindkey -M viopp -r "^[[B"