aboutsummaryrefslogtreecommitdiffhomepage
path: root/vim/init/keymaps.vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim/init/keymaps.vim')
-rw-r--r--vim/init/keymaps.vim126
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
89function! CdToGitRepo() 89function! 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
93endfunction 93endfunction
94 94
95function! InCaseCdToLatestDir() 95function! InCaseCdToLatestDir()
@@ -256,29 +256,29 @@ function! CloseBufferSafely()
256 endif 256 endif
257endfunction 257endfunction
258func! QuitWithCheck() 258func! QuitWithCheck()
259if g:quitVimWhenPressingCtrlC 259 if g:quitVimWhenPressingCtrlC
260 silent! quit 260 silent! quit
261else 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>"
263endif 263 endif
264endfunc 264endfunc
265function! Bye() 265function! Bye()
266let windows = gettabinfo(tabpagenr())[0]['windows'] 266 let windows = gettabinfo(tabpagenr())[0]['windows']
267try 267 try
268 let bufs = gettabinfo(tabpagenr())[0]['variables']['bufs'] 268 let bufs = gettabinfo(tabpagenr())[0]['variables']['bufs']
269catch 269 catch
270 let bufs = getbufinfo({'buflisted': 1}) 270 let bufs = getbufinfo({'buflisted': 1})
271endtry 271 endtry
272 272
273if len(windows) == 1 && len(bufs) == 1 273 if len(windows) == 1 && len(bufs) == 1
274 call QuitWithCheck() 274 call QuitWithCheck()
275elseif &diff 275 elseif &diff
276 silent call CloseBuffersForDiff() 276 silent call CloseBuffersForDiff()
277elseif len(windows) >1 277 elseif len(windows) >1
278 quit 278 quit
279else 279 else
280 silent! call CloseBufferSafely() 280 silent! call CloseBufferSafely()
281endif 281 endif
282endfunction 282endfunction
283nnoremap <silent> <C-c> :call Bye()<CR> 283nnoremap <silent> <C-c> :call Bye()<CR>
284 284
@@ -291,29 +291,29 @@ function! CloseBuffersForDiff()
291endfunction 291endfunction
292 292
293command! DiffOrig vert new | set buftype=nofile nobuflisted | read ++edit # | 0d_ 293command! 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
297function! s:SwitchDiff() 297function! s:SwitchDiff()
298if &diff 298 if &diff
299 call CloseBuffersForDiff() 299 call CloseBuffersForDiff()
300else 300 else
301 DiffOrig 301 DiffOrig
302endif 302 endif
303endfunction 303endfunction
304com! SwitchDiff call s:SwitchDiff() 304com! SwitchDiff call s:SwitchDiff()
305nnoremap <C-w>d <Cmd>silent! SwitchDiff<CR> 305nnoremap <C-w>d <Cmd>silent! SwitchDiff<CR>
306 306
307function! s:SwitchDiffForGitHEAD() 307function! s:SwitchDiffForGitHEAD()
308norm cdg 308 norm cdg
309if &diff 309 if &diff
310 windo | if &buftype == "nofile" | bdelete | endif 310 windo | if &buftype == "nofile" | bdelete | endif
311 norm! zv 311 norm! zv
312else 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
316endif 316 endif
317endfunction 317endfunction
318command! SwitchDiffForGitHEAD call s:SwitchDiffForGitHEAD() 318command! SwitchDiffForGitHEAD call s:SwitchDiffForGitHEAD()
319nnoremap <C-w>D <Cmd>silent! SwitchDiffForGitHEAD<CR> 319nnoremap <C-w>D <Cmd>silent! SwitchDiffForGitHEAD<CR>
@@ -339,22 +339,22 @@ inoremap <m-J> <esc><c-w>j
339inoremap <m-K> <esc><c-w>k 339inoremap <m-K> <esc><c-w>k
340 340
341if has('terminal') && exists(':terminal') == 2 && has('patch-8.1.1') 341if 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 更改,也要改
345set termwinkey=<c-_> 345 set termwinkey=<c-_>
346tnoremap <m-H> <c-_>h 346 tnoremap <m-H> <c-_>h
347tnoremap <m-L> <c-_>l 347 tnoremap <m-L> <c-_>l
348tnoremap <m-J> <c-_>j 348 tnoremap <m-J> <c-_>j
349tnoremap <m-K> <c-_>k 349 tnoremap <m-K> <c-_>k
350tnoremap <m-q> <c-\><c-n> 350 tnoremap <m-q> <c-\><c-n>
351elseif has('nvim') 351elseif has('nvim')
352" neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式 352 " neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式
353tnoremap <m-H> <c-\><c-n><c-w>h 353 tnoremap <m-H> <c-\><c-n><c-w>h
354tnoremap <m-L> <c-\><c-n><c-w>l 354 tnoremap <m-L> <c-\><c-n><c-w>l
355tnoremap <m-J> <c-\><c-n><c-w>j 355 tnoremap <m-J> <c-\><c-n><c-w>j
356tnoremap <m-K> <c-\><c-n><c-w>k 356 tnoremap <m-K> <c-\><c-n><c-w>k
357tnoremap <m-q> <c-\><c-n> 357 tnoremap <m-q> <c-\><c-n>
358endif 358endif
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
381function! Tvab_MoveLeft() 381function! Tvab_MoveLeft()
382let l:tabnr = tabpagenr() - 2 382 let l:tabnr = tabpagenr() - 2
383if l:tabnr >= 0 383 if l:tabnr >= 0
384 exec 'tabmove '.l:tabnr 384 exec 'tabmove '.l:tabnr
385endif 385 endif
386endfunc 386endfunc
387function! Tab_MoveRight() 387function! Tab_MoveRight()
388let l:tabnr = tabpagenr() + 1 388 let l:tabnr = tabpagenr() + 1
389if l:tabnr <= tabpagenr('$') 389 if l:tabnr <= tabpagenr('$')
390 exec 'tabmove '.l:tabnr 390 exec 'tabmove '.l:tabnr
391endif 391 endif
392endfunc 392endfunc
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>"