From 82ed7d4113c474f309ebeb5133873ccf0a2bcda2 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sun, 21 Jul 2024 18:49:31 +0800 Subject: Update --- vim/init/keymaps.vim | 126 +++++++++++++++++++++++++-------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) (limited to 'vim/init') 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 :call InCaseCdToLatestDir() " Switch CWD to root git directory function! CdToGitRepo() - let l:git_dir = finddir('.git', escape(expand('%:p:h'), ' ') . ';') - let l:repo = fnameescape(fnamemodify(l:git_dir, ':h')) - execute "cd" l:repo + let l:git_dir = finddir('.git', escape(expand('%:p:h'), ' ') . ';') + let l:repo = fnameescape(fnamemodify(l:git_dir, ':h')) + execute "cd" l:repo endfunction function! InCaseCdToLatestDir() @@ -256,29 +256,29 @@ function! CloseBufferSafely() endif endfunction func! QuitWithCheck() -if g:quitVimWhenPressingCtrlC - silent! quit -else - echo "Press gl to allow quit with " -endif + if g:quitVimWhenPressingCtrlC + silent! quit + else + echo "Press gl to allow quit with " + endif endfunc function! Bye() -let windows = gettabinfo(tabpagenr())[0]['windows'] -try - let bufs = gettabinfo(tabpagenr())[0]['variables']['bufs'] -catch - let bufs = getbufinfo({'buflisted': 1}) -endtry - -if len(windows) == 1 && len(bufs) == 1 - call QuitWithCheck() -elseif &diff - silent call CloseBuffersForDiff() -elseif len(windows) >1 - quit -else - silent! call CloseBufferSafely() -endif + let windows = gettabinfo(tabpagenr())[0]['windows'] + try + let bufs = gettabinfo(tabpagenr())[0]['variables']['bufs'] + catch + let bufs = getbufinfo({'buflisted': 1}) + endtry + + if len(windows) == 1 && len(bufs) == 1 + call QuitWithCheck() + elseif &diff + silent call CloseBuffersForDiff() + elseif len(windows) >1 + quit + else + silent! call CloseBufferSafely() + endif endfunction nnoremap :call Bye() @@ -291,29 +291,29 @@ function! CloseBuffersForDiff() endfunction command! DiffOrig vert new | set buftype=nofile nobuflisted | read ++edit # | 0d_ -\ | diffthis | wincmd p | diffthis + \ | diffthis | wincmd p | diffthis " Uset d to toggle Diff mode function! s:SwitchDiff() -if &diff - call CloseBuffersForDiff() -else - DiffOrig -endif + if &diff + call CloseBuffersForDiff() + else + DiffOrig + endif endfunction com! SwitchDiff call s:SwitchDiff() nnoremap d silent! SwitchDiff function! s:SwitchDiffForGitHEAD() -norm cdg -if &diff - windo | if &buftype == "nofile" | bdelete | endif - norm! zv -else - vert new | set buftype=nofile nobuflisted - read !git show HEAD:# - 0d_ | diffthis | wincmd p | diffthis -endif + norm cdg + if &diff + windo | if &buftype == "nofile" | bdelete | endif + norm! zv + else + vert new | set buftype=nofile nobuflisted + read !git show HEAD:# + 0d_ | diffthis | wincmd p | diffthis + endif endfunction command! SwitchDiffForGitHEAD call s:SwitchDiffForGitHEAD() nnoremap D silent! SwitchDiffForGitHEAD @@ -339,22 +339,22 @@ inoremap j inoremap k if has('terminal') && exists(':terminal') == 2 && has('patch-8.1.1') -" vim 8.1 支持 termwinkey ,不需要把 terminal 切换成 normal 模式 -" 设置 termwinkey 为 CTRL 加减号(GVIM),有些终端下是 CTRL+? -" 后面四个键位是搭配 termwinkey 的,如果 termwinkey 更改,也要改 -set termwinkey= -tnoremap h -tnoremap l -tnoremap j -tnoremap k -tnoremap + " vim 8.1 支持 termwinkey ,不需要把 terminal 切换成 normal 模式 + " 设置 termwinkey 为 CTRL 加减号(GVIM),有些终端下是 CTRL+? + " 后面四个键位是搭配 termwinkey 的,如果 termwinkey 更改,也要改 + set termwinkey= + tnoremap h + tnoremap l + tnoremap j + tnoremap k + tnoremap elseif has('nvim') -" neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式 -tnoremap h -tnoremap l -tnoremap j -tnoremap k -tnoremap + " neovim 没有 termwinkey 支持,必须把 terminal 切换回 normal 模式 + tnoremap h + tnoremap l + tnoremap j + tnoremap k + tnoremap endif " }}} " MANAGE_TABS ----------------{{{ @@ -379,16 +379,16 @@ map te :tabedit =expand("%:p:h") " Tab move functions function! Tvab_MoveLeft() -let l:tabnr = tabpagenr() - 2 -if l:tabnr >= 0 - exec 'tabmove '.l:tabnr -endif + let l:tabnr = tabpagenr() - 2 + if l:tabnr >= 0 + exec 'tabmove '.l:tabnr + endif endfunc function! Tab_MoveRight() -let l:tabnr = tabpagenr() + 1 -if l:tabnr <= tabpagenr('$') - exec 'tabmove '.l:tabnr -endif + let l:tabnr = tabpagenr() + 1 + if l:tabnr <= tabpagenr('$') + exec 'tabmove '.l:tabnr + endif endfunc " }}} " FOLD ----------------{{{ @@ -516,7 +516,7 @@ function! AddSpaceForSelection() '< norm! O '> norm! o exe "norm! "..(line("'<")-1).."GV"..(line("'>")+1).."G" - " Otherwise, add space at start and end column + " Otherwise, add space at start and end column else call cursor('.', col("'<")) execute "norm! i\" -- cgit v1.2.3-70-g09d2