diff options
Diffstat (limited to 'vim/init/keymaps.vim')
-rw-r--r-- | vim/init/keymaps.vim | 126 |
1 files changed, 63 insertions, 63 deletions
diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim index 15bf356..81ce508 100644 --- a/vim/init/keymaps.vim +++ b/vim/init/keymaps.vim | |||
@@ -87,9 +87,9 @@ noremap <C-]> :call InCaseCdToLatestDir()<CR> | |||
87 | 87 | ||
88 | " Switch CWD to root git directory | 88 | " Switch CWD to root git directory |
89 | function! CdToGitRepo() | 89 | function! CdToGitRepo() |
90 | let l:git_dir = finddir('.git', escape(expand('%:p:h'), ' ') . ';') | 90 | let l:git_dir = finddir('.git', escape(expand('%:p:h'), ' ') . ';') |
91 | let l:repo = fnameescape(fnamemodify(l:git_dir, ':h')) | 91 | let l:repo = fnameescape(fnamemodify(l:git_dir, ':h')) |
92 | execute "cd" l:repo | 92 | execute "cd" l:repo |
93 | endfunction | 93 | endfunction |
94 | 94 | ||
95 | function! InCaseCdToLatestDir() | 95 | function! InCaseCdToLatestDir() |
@@ -256,29 +256,29 @@ function! CloseBufferSafely() | |||
256 | endif | 256 | endif |
257 | endfunction | 257 | endfunction |
258 | func! QuitWithCheck() | 258 | func! QuitWithCheck() |
259 | if g:quitVimWhenPressingCtrlC | 259 | if g:quitVimWhenPressingCtrlC |
260 | silent! quit | 260 | silent! quit |
261 | else | 261 | else |
262 | echo "Press <leader><leader>gl to allow quit with <C-c>" | 262 | echo "Press <leader><leader>gl to allow quit with <C-c>" |
263 | endif | 263 | endif |
264 | endfunc | 264 | endfunc |
265 | function! Bye() | 265 | function! Bye() |
266 | let windows = gettabinfo(tabpagenr())[0]['windows'] | 266 | let windows = gettabinfo(tabpagenr())[0]['windows'] |
267 | try | 267 | try |
268 | let bufs = gettabinfo(tabpagenr())[0]['variables']['bufs'] | 268 | let bufs = gettabinfo(tabpagenr())[0]['variables']['bufs'] |
269 | catch | 269 | catch |
270 | let bufs = getbufinfo({'buflisted': 1}) | 270 | let bufs = getbufinfo({'buflisted': 1}) |
271 | endtry | 271 | endtry |
272 | 272 | ||
273 | if len(windows) == 1 && len(bufs) == 1 | 273 | if len(windows) == 1 && len(bufs) == 1 |
274 | call QuitWithCheck() | 274 | call QuitWithCheck() |
275 | elseif &diff | 275 | elseif &diff |
276 | silent call CloseBuffersForDiff() | 276 | silent call CloseBuffersForDiff() |
277 | elseif len(windows) >1 | 277 | elseif len(windows) >1 |
278 | quit | 278 | quit |
279 | else | 279 | else |
280 | silent! call CloseBufferSafely() | 280 | silent! call CloseBufferSafely() |
281 | endif | 281 | endif |
282 | endfunction | 282 | endfunction |
283 | nnoremap <silent> <C-c> :call Bye()<CR> | 283 | nnoremap <silent> <C-c> :call Bye()<CR> |
284 | 284 | ||
@@ -291,29 +291,29 @@ function! CloseBuffersForDiff() | |||
291 | endfunction | 291 | endfunction |
292 | 292 | ||
293 | command! DiffOrig vert new | set buftype=nofile nobuflisted | read ++edit # | 0d_ | 293 | command! DiffOrig vert new | set buftype=nofile nobuflisted | read ++edit # | 0d_ |
294 | \ | diffthis | wincmd p | diffthis | 294 | \ | diffthis | wincmd p | diffthis |
295 | 295 | ||
296 | " Uset <C-w>d to toggle Diff mode | 296 | " Uset <C-w>d to toggle Diff mode |
297 | function! s:SwitchDiff() | 297 | function! s:SwitchDiff() |
298 | if &diff | 298 | if &diff |
299 | call CloseBuffersForDiff() | 299 | call CloseBuffersForDiff() |
300 | else | 300 | else |
301 | DiffOrig | 301 | DiffOrig |
302 | endif | 302 | endif |
303 | endfunction | 303 | endfunction |
304 | com! SwitchDiff call s:SwitchDiff() | 304 | com! SwitchDiff call s:SwitchDiff() |
305 | nnoremap <C-w>d <Cmd>silent! SwitchDiff<CR> | 305 | nnoremap <C-w>d <Cmd>silent! SwitchDiff<CR> |
306 | 306 | ||
307 | function! s:SwitchDiffForGitHEAD() | 307 | function! s:SwitchDiffForGitHEAD() |
308 | norm cdg | 308 | norm cdg |
309 | if &diff | 309 | if &diff |
310 | windo | if &buftype == "nofile" | bdelete | endif | 310 | windo | if &buftype == "nofile" | bdelete | endif |
311 | norm! zv | 311 | norm! zv |
312 | else | 312 | else |
313 | vert new | set buftype=nofile nobuflisted | 313 | vert new | set buftype=nofile nobuflisted |
314 | read !git show HEAD:# | 314 | read !git show HEAD:# |
315 | 0d_ | diffthis | wincmd p | diffthis | 315 | 0d_ | diffthis | wincmd p | diffthis |
316 | endif | 316 | endif |
317 | endfunction | 317 | endfunction |
318 | command! SwitchDiffForGitHEAD call s:SwitchDiffForGitHEAD() | 318 | command! SwitchDiffForGitHEAD call s:SwitchDiffForGitHEAD() |
319 | nnoremap <C-w>D <Cmd>silent! SwitchDiffForGitHEAD<CR> | 319 | nnoremap <C-w>D <Cmd>silent! SwitchDiffForGitHEAD<CR> |
@@ -339,22 +339,22 @@ inoremap <m-J> <esc><c-w>j | |||
339 | inoremap <m-K> <esc><c-w>k | 339 | inoremap <m-K> <esc><c-w>k |
340 | 340 | ||
341 | if has('terminal') && exists(':terminal') == 2 && has('patch-8.1.1') | 341 | if has('terminal') && exists(':terminal') == 2 && has('patch-8.1.1') |
342 | " vim 8.1 支持 termwinkey ,不需要把 terminal 切换成 normal 模式 | 342 | " vim 8.1 支持 termwinkey ,不需要把 terminal 切换成 normal 模式 |
343 | " 设置 termwinkey 为 CTRL 加减号(GVIM),有些终端下是 CTRL+? | 343 | " 设置 termwinkey 为 CTRL 加减号(GVIM),有些终端下是 CTRL+? |
344 | " 后面四个键位是搭配 termwinkey 的,如果 termwinkey 更改,也要改 | 344 | " 后面四个键位是搭配 termwinkey 的,如果 termwinkey 更改,也要改 |
345 | set termwinkey=<c-_> | 345 | set termwinkey=<c-_> |
346 | tnoremap <m-H> <c-_>h | 346 | tnoremap <m-H> <c-_>h |
347 | tnoremap <m-L> <c-_>l | 347 | tnoremap <m-L> <c-_>l |
348 | tnoremap <m-J> <c-_>j | 348 | tnoremap <m-J> <c-_>j |
349 | tnoremap <m-K> <c-_>k | 349 | tnoremap <m-K> <c-_>k |
350 | tnoremap <m-q> <c-\><c-n> | 350 | tnoremap <m-q> <c-\><c-n> |
351 | elseif has('nvim') | 351 | elseif has('nvim') |
352 | " neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式 | 352 | " neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式 |
353 | tnoremap <m-H> <c-\><c-n><c-w>h | 353 | tnoremap <m-H> <c-\><c-n><c-w>h |
354 | tnoremap <m-L> <c-\><c-n><c-w>l | 354 | tnoremap <m-L> <c-\><c-n><c-w>l |
355 | tnoremap <m-J> <c-\><c-n><c-w>j | 355 | tnoremap <m-J> <c-\><c-n><c-w>j |
356 | tnoremap <m-K> <c-\><c-n><c-w>k | 356 | tnoremap <m-K> <c-\><c-n><c-w>k |
357 | tnoremap <m-q> <c-\><c-n> | 357 | tnoremap <m-q> <c-\><c-n> |
358 | endif | 358 | endif |
359 | " }}} | 359 | " }}} |
360 | " MANAGE_TABS ----------------{{{ | 360 | " MANAGE_TABS ----------------{{{ |
@@ -379,16 +379,16 @@ map <leader>te :tabedit <C-r>=expand("%:p:h")<CR> | |||
379 | 379 | ||
380 | " Tab move functions | 380 | " Tab move functions |
381 | function! Tvab_MoveLeft() | 381 | function! Tvab_MoveLeft() |
382 | let l:tabnr = tabpagenr() - 2 | 382 | let l:tabnr = tabpagenr() - 2 |
383 | if l:tabnr >= 0 | 383 | if l:tabnr >= 0 |
384 | exec 'tabmove '.l:tabnr | 384 | exec 'tabmove '.l:tabnr |
385 | endif | 385 | endif |
386 | endfunc | 386 | endfunc |
387 | function! Tab_MoveRight() | 387 | function! Tab_MoveRight() |
388 | let l:tabnr = tabpagenr() + 1 | 388 | let l:tabnr = tabpagenr() + 1 |
389 | if l:tabnr <= tabpagenr('$') | 389 | if l:tabnr <= tabpagenr('$') |
390 | exec 'tabmove '.l:tabnr | 390 | exec 'tabmove '.l:tabnr |
391 | endif | 391 | endif |
392 | endfunc | 392 | endfunc |
393 | " }}} | 393 | " }}} |
394 | " FOLD ----------------{{{ | 394 | " FOLD ----------------{{{ |
@@ -516,7 +516,7 @@ function! AddSpaceForSelection() | |||
516 | '< norm! O | 516 | '< norm! O |
517 | '> norm! o | 517 | '> norm! o |
518 | exe "norm! "..(line("'<")-1).."GV"..(line("'>")+1).."G" | 518 | exe "norm! "..(line("'<")-1).."GV"..(line("'>")+1).."G" |
519 | " Otherwise, add space at start and end column | 519 | " Otherwise, add space at start and end column |
520 | else | 520 | else |
521 | call cursor('.', col("'<")) | 521 | call cursor('.', col("'<")) |
522 | execute "norm! i\<space>" | 522 | execute "norm! i\<space>" |