-
Notifications
You must be signed in to change notification settings - Fork 3
/
mappings.vim
276 lines (241 loc) · 8.75 KB
/
mappings.vim
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
"-----------------------------------------------------------------------------
" hotkeys
"-----------------------------------------------------------------------------
vmap < <gv
vmap > >gv
" CTRL-X and SHIFT-Del are Cut
vnoremap <C-X> "+x
" vnoremap <S-Del> "+x
" CTRL-C and CTRL-Insert are Copy
vnoremap <c-c> "+y
" vnoremap <c-insert> "+y
" CTRL-V and SHIFT-Insert are Paste
"map <c-v> "+gP
" map <s-insert> "+gP
"cmap <c-v> <c-r>+
" cmap <s-insert> <c-r>+
" Pasting blockwise and linewise selections is not possible in Insert and
" Visual mode without the +virtualedit feature. They are pasted as if they
" were characterwise instead.
" Uses the paste.vim autoload script.
exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']
"imap <s-insert> <c-v>
"vmap <s-insert> <c-v>
" nmap <a-v> <c-v>
" vmap <a-v> <c-v>
"imap <c-v> <space><esc>"+gP<del>i
" movement
vmap <c-k> 10k
nmap <c-k> 10k
vmap <c-j> 10j
nmap <c-j> 10j
" up
nmap k gk
vmap k gk
imap <c-k> <up>
cmap <c-k> <up>
" down
nmap j gj
vmap j gj
imap <c-j> <down>
cmap <c-j> <down>
" left
nmap h <left>
vmap h <left>
imap <c-h> <left>
imap <c-b> <left>
imap <c-f> <righT>
cmap <c-h> <left>
" right
nmap l <right>
vmap l <right>
imap <c-l> <right>
cmap <c-l> <right>
" ESC button
imap jj <Esc><right>
" arrows
nmap <down> gj
nmap <up> gk
vmap <down> gj
vmap <up> gk
imap <down> <c-O>gj
imap <up> <c-O>gk
" save position while page up/down
nmap <pageup> <c-U><c-U>
nmap <pagedown> <c-D><c-D>
imap <pageup> <c-O><c-U><c-O><c-U>
imap <pagedown> <c-O><c-D><c-O><c-D>
vmap <pageup> <c-U><c-U>
vmap <pagedown> <c-D><c-D>
" CamelCase movement
map <silent> w <plug>CamelCaseMotion_w
map <silent> b <plug>CamelCaseMotion_b
map <silent> e <plug>CamelCaseMotion_e
" Bubble single lines
" nmap <c-up> [e
" nmap <c-down> ]e
" Bubble multiple lines
" vmap <c-up> [egv
" vmap <c-down> ]egv
" move with shift
imap <s-k4> <esc>Bi
vmap <s-k4> B
nmap <s-k4> B
imap <s-k6> <esc>Ea
vmap <s-k6> E
nmap <s-k6> E
map <s-k8> <pageup>
map <s-k2> <pagedown>
" set ctrl+c to behave like esc
inoremap <c-c> <esc>
" insert newline after current line
nmap <silent> <cr> o<Esc>
" insert newline before current line
nmap <silent> <s-cr> O<Esc>
" turn off highlighting and clear messages
nmap <silent> <space> :nohlsearch<Bar>:echo<cr>
" quit
nmap <c-q> :q!<cr>
vmap <c-q> <esc>:q!<cr>i
imap <c-q> <esc>:q!<cr>i
" unmap annoying script
map <S-k> <Nop>
" sort
vmap <c-s> :sor<cr>
" Tags
"nnoremap <f10> :TagbarToggle<cr>
"inoremap <f10> <c-O>:TagbarToggle<cr>
"vnoremap <f10> <esc>:TagbarToggle<cr>
"nnoremap <f12> :emenu Tags.<tab>
"inoremap <f12> <c-O>:emenu Tags.<tab>
"vnoremap <f12> <esc>:emenu Tags.<tab>
" ruby debugger
" vimrc edit
" imap {<cr> {<cr>}<Esc>O
" imap <% <% %><left><left><left>
" imap <%= <%= %><left><left><left>
" 'Control + \' - Open a new tab and tag into the function/variable currently under cursor
"map <c-\> :tab split<cr>:exec("tag ".expand("<cword>"))<cr>
" чтобы не копировать выделенный текст в дефолтный регистр при вставке
vnoremap p "_dp
nnoremap <f12> :bd<cr>
nnoremap <leader>w :bd<cr>
" ˙ = ⌥+w on OSX
" nnoremap ˙ :bd<cr>
"-----------------------------------------------------------------------------
" open vim config
"-----------------------------------------------------------------------------
map ,v :e ~/.vim/vimrc<CR>
"-----------------------------------------------------------------------------
" autocomplete
"-----------------------------------------------------------------------------
" imap <tab> <c-r>=InsertTabWordWrapper()<cr>
" imap <c-tab> <c-r>=InsertTabLineWrapper()<cr>
" imap <s-tab> <c-n>
" function! InsertTabWordWrapper()
" let col = col('.') - 1
" if !col || getline('.')[col - 1] !~ '\k'
" return "\<tab>"
" else
" return "\<c-p>"
" endif
" endfunction
" function! InsertTabLineWrapper()
" let col = col('.') - 1
" if !col || getline('.')[col - 1] !~ '\k'
" return "\<tab>"
" else
" return "\<c-x>\<c-l>"
" endif
" endfunction
"-----------------------------------------------------------------------------
" VisualSearch
" search selected text
"-----------------------------------------------------------------------------
" vmap <silent>* <esc>:call VisualSearch('/')<cr>/<c-R>/<cr>
" vmap <silent># <esc>:call VisualSearch('?')<cr>?<c-R>/<cr>
" function! VisualSearch(cmd)
" let l:old_reg=getreg('"')
" let l:old_regtype=getregtype('"')
" normal! gvy
" let @/='\V'.substitute(substitute(substitute(escape(@@, a:cmd.'\'), '^\_s\+', '\\s\\+', ''), '\_s\+$', '\\s\\*', ''), '\_s\+', '\\_s\\+', 'g')
" normal! gV
" call setreg('"', l:old_reg, l:old_regtype)
" endfunction
" vmap * :<C-u>call <SID>VSetSearch()<CR>//<CR>
" vmap # :<C-u>call <SID>VSetSearch()<CR>??<CR>
" "visual search mappings
" function! s:VSetSearch()
" let temp = @@
" norm! gvy
" let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
" let @@ = temp
" endfunction
"-----------------------------------------------------------------------------
" RemoveTrailingSpaces
"-----------------------------------------------------------------------------
nmap <silent>,t :call RemoveTrailingSpaces()<cr>:echo 'trailing spaces have been removed'<cr>
function! RemoveTrailingSpaces()
normal! mzHmy
execute '%s/\t/ /ge'
execute '%s/\s\+$//ge'
normal! 'yzt`z
endfunction
"-----------------------------------------------------------------------------
" tabmove
"-----------------------------------------------------------------------------
nmap <silent><a-S-left> :tabmove -1<cr>
imap <silent><a-S-left> <c-O>:tabmove -1<cr>
nmap <silent><a-S-right> :tabmove +1<cr>
imap <silent><a-S-right> <c-O>:tabmove +1<cr>
"-----------------------------------------------------------------------------
" switch and remember colorschemes
"-----------------------------------------------------------------------------
" nmap <f8> :colors ir_black_morr<cr>
" nmap <f9> :colors papercolor<cr>:set background=dark<cr>
" nmap <f10> :colors papercolor<cr>:set background=light<cr>
" nmap <f11> :colors solarized<cr>:set background=dark<cr>
" nmap <f12> :colors solarized<cr>:set background=light<cr>
nmap ,cd1 :call <SID>InstallColor("colors solarized\\nset background=dark")<cr>
nmap ,cd2 :call <SID>InstallColor("colors papercolor\\nset background=dark")<cr>
nmap ,cd3 :call <SID>InstallColor("colors one\\nset background=dark\\nlet g:airline_theme='one'")<cr>
nmap ,cd4 :call <SID>InstallColor("colors ir_black_morr")<cr>
nmap ,cd5 :call <SID>InstallColor("colors vim-material\\nlet g:airline_theme='material'")<cr>
nmap ,cd6 :call <SID>InstallColor("colors spring-night\\nlet g:airline_theme='spring_night'")<cr>
nmap ,cl1 :call <SID>InstallColor("colors solarized\\nset background=light")<cr>
nmap ,cl2 :call <SID>InstallColor("colors papercolor\\nset background=light")<cr>
nmap ,cl3 :call <SID>InstallColor("colors one\\nset background=light\\nlet g:airline_theme='one'")<cr>
nmap ,c01 :call <SID>InstallColor("colors sialoquent")<cr>
nmap ,c02 :call <SID>InstallColor("colors SerialExperimentsLain")<cr>
nmap ,c03 :call <SID>InstallColor("colors basic-dark")<cr>
nmap ,c04 :call <SID>InstallColor("colors basic-light")<cr>
nmap ,c05 :call <SID>InstallColor("colors smyck")<cr>
nmap ,c06 :call <SID>InstallColor("colors carbonized-light")<cr>
nmap ,c07 :call <SID>InstallColor("colors carbonized-dark")<cr>
nmap ,c08 :call <SID>InstallColor("colors macvim-light")<cr>
nmap ,c11 :call <SID>InstallColor("colors greygull")<cr>
nmap ,c12 :call <SID>InstallColor("colors petrel")<cr>
nmap ,c13 :call <SID>InstallColor("colors seagull")<cr>
nmap ,c14 :call <SID>InstallColor("colors stormpetrel")<cr>
function! s:InstallColor(cmd)
echo split(a:cmd, "\\")[0]
silent exe "!echo \"".a:cmd."\" > $HOME/.vim/colorscheme.vim"
source $HOME/.vim/colorscheme.vim
endfunction
"-----------------------------------------------------------------------------
" rebuild syntax
"-----------------------------------------------------------------------------
map <F10> :syntax sync fromstart<cr>
map zz :syntax sync fromstart<cr>
"-----------------------------------------------------------------------------
" Show the active syntax highlighting groups under the cursor
"-----------------------------------------------------------------------------
nnoremap zS :echo join(reverse(map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")')),' ')<cr>
nnoremap zZ :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>"
"-----------------------------------------------------------------------------
" Copy path to current file into buffer
"-----------------------------------------------------------------------------
nnoremap <Leader>z :let @+=expand('%:p')<CR>