From 9b564fcfeec95ed965252ef4acc6ee42702ded88 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sun, 28 Jul 2024 21:01:19 +0800 Subject: Update --- vim/init/keymaps.vim | 115 +++++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 55 deletions(-) (limited to 'vim/init/keymaps.vim') diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim index f13756b..1eb2b20 100644 --- a/vim/init/keymaps.vim +++ b/vim/init/keymaps.vim @@ -21,15 +21,15 @@ nnoremap W :set wrap! function! s:WriteOrEnterFileName() if !empty(expand('%')) | write! | else | call feedkeys(":w ") | endif endfunction -nmap w :call WriteOrEnterFileName() +nnoremap w :call WriteOrEnterFileName() " :W sudo saves the file " (useful for handling the permission-denied error) command! W execute 'w !sudo -S tee %' edit! " Quit -nmap q :q -nmap cq :cq +nnoremap q :q +nnoremap cq :cq " Remap in Quickfix, Cmdwin Location list augroup vimrc_CRfix @@ -57,7 +57,7 @@ augroup END " execute "set =\eh" " Spell -nnoremap sp :set spell!:set spell? +nnoremap \s :set spell!:set spell? nnoremap ss ]s nnoremap S [s @@ -68,6 +68,7 @@ nnoremap 1 vnoremap Tz :!trans -t zh-TW -b vnoremap Te :!trans -t en-US -b + " }}} " WORKING_DIR ----------------{{{ @@ -82,8 +83,8 @@ nnoremap cd :cd %:p:h:pwd nnoremap cd :cd nnoremap cdg :call CdToGitRepo():pwd -noremap :cd ..:pwd -noremap :call InCaseCdToLatestDir() +nnoremap :cd ..:pwd +nnoremap :call InCaseCdToLatestDir() " Switch CWD to root git directory function! CdToGitRepo() @@ -105,17 +106,21 @@ endfunction " MOTION ----------------{{{ " j/k will move virtual lines (lines that wrap) -noremap j (v:count == 0 ? 'gj' : 'j') -noremap k (v:count == 0 ? 'gk' : 'k') +nnoremap j (v:count == 0 ? 'gj' : 'j') +nnoremap k (v:count == 0 ? 'gk' : 'k') " Quick move in a line -noremap 30h -noremap 30l +nnoremap 30h +nnoremap 30l " File under the cursor nnoremap gf nnoremap gF :e +xnoremap iq i" +xnoremap aq a" + + " READLINE_FEATURES ----------------{{{ inoremap @@ -145,22 +150,22 @@ cnoremap d$ cnoremap de " Moving with wrap -noremap gj -noremap gk +nnoremap gj +nnoremap gk inoremap gj inoremap gk " }}} " JUMP_TO_TABS_WITH_ALT ----------------{{{ -noremap :tabn 1 -noremap :tabn 2 -noremap :tabn 3 -noremap :tabn 4 -noremap :tabn 5 -noremap :tabn 6 -noremap :tabn 7 -noremap :tabn 8 -noremap :tablast +nnoremap :tabn 1 +nnoremap :tabn 2 +nnoremap :tabn 3 +nnoremap :tabn 4 +nnoremap :tabn 5 +nnoremap :tabn 6 +nnoremap :tabn 7 +nnoremap :tabn 8 +nnoremap :tablast inoremap :tabn 1 inoremap :tabn 2 inoremap :tabn 3 @@ -211,23 +216,25 @@ nnoremap ee :edit $MYVIMRC " MANAGE_BUFFERS ----------------{{{ " Set options -noremap st :set -noremap ft :e'set filetype='..&filetype -noremap li :set list! -noremap sw :e'set shiftwidth='..&shiftwidth -noremap nu :set number! -noremap ru :set relativenumber! +nnoremap so :set +nnoremap ft :e'set filetype='..&filetype +nnoremap sw :e'set shiftwidth='..&shiftwidth +nnoremap ts :e'set tabstop='..&tabstop +nnoremap \e :set expandtab!:set expandtab? +nnoremap \l :set list!:set list? +nnoremap \n :set nu!:set nu? +nnoremap \r :set relativenumber!:set rnu? " Open a new buffer -nmap B :enew -nmap O :e /tmp/buffer +nnoremap B :enew +nnoremap O :e /tmp/buffer " Let l toggle between this and the last accessed buffer augroup SaveLastBuffer let g:lastbuffer = 1 - au BufLeave * let g:lastbuffer = bufnr() + au BufLeave * if &buflisted | let g:lastbuffer = expand('') | endif augroup END -noremap l :exe "buffer ".g:lastbuffer +nnoremap l :exe "buffer ".g:lastbuffer " Use Ctrl-C for buffer delete or quit vim ----------------{{{ @@ -238,9 +245,11 @@ function! ToggleQuit() let message = g:quitVimWhenPressingCtrlC ? "Unlock" : "Lock" echo message endfunction -nnoremap gl :call ToggleQuit() +nnoremap \q :call ToggleQuit() function! CloseBufferSafely() + let l:bufnr = bufnr() + " Ask Saving if &modified let answer = confirm("Save changes?", "&Yes\n&No\n&Cancel") if answer == 1 | write | endif @@ -248,27 +257,22 @@ function! CloseBufferSafely() if answer == "" | return | endif endif - let bufs = getbufinfo({'buflisted': 1}) - if len(bufs) == 1 - bdelete! + if g:tab_group[tabpagenr()] == [l:bufnr] + bdelete else - b# | bd! # + bprevious | bd # endif endfunction func! QuitWithCheck() if g:quitVimWhenPressingCtrlC silent! quit else - echo "Press gl to allow quit with " + echo "Press \\q 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 + let bufs = getbufinfo({'buflisted': 1}) if len(windows) == 1 && len(bufs) == 1 call QuitWithCheck() @@ -282,8 +286,8 @@ function! Bye() endfunction nnoremap :call Bye() - -" Diff Mode ---------------- +" }}} +" Diff Mode {{{ function! CloseBuffersForDiff() windo | if &diff && &buftype == "nofile" | bdelete | endif @@ -329,10 +333,10 @@ nnoremap sb :windo set scrollbind! " 传统的 CTRL+hjkl 移动窗口不适用于 vim 8.1 的终端模式,CTRL+hjkl 在 " bash/zsh 及带文本界面的程序中都是重要键位需要保留,不能 tnoremap 的 "---------------------------------------------------------------------- -noremap h -noremap l -noremap j -noremap k +nnoremap h +nnoremap l +nnoremap j +nnoremap k inoremap h inoremap l inoremap j @@ -365,12 +369,12 @@ map tc :tabclose map tm :tabmove map to :tabonly -noremap :call Tab_MoveLeft() -noremap :call Tab_MoveRight() +nnoremap :call Tab_MoveLeft() +nnoremap :call Tab_MoveRight() " Let tl toggle between this and the last accessed tab let g:lasttab = 1 -nmap tl :exe "tabn ".g:lasttab +nnoremap tl :exe "tabn ".g:lasttab autocmd TabLeave * let g:lasttab = tabpagenr() " Opens a new tab with the current buffer's path @@ -394,8 +398,8 @@ endfunc " FOLD ----------------{{{ " Set fold options -noremap fm :e'set foldmethod='..&foldmethod -noremap fc :e'set foldcolumn='..&foldcolumn +nnoremap fm :e'set foldmethod='..&foldmethod +nnoremap fc :e'set foldcolumn='..&foldcolumn nnoremap zi zizz @@ -463,7 +467,7 @@ endfunction " HIGHLIGHT ----------------{{{ " Disable highlight when is pressed -noremap :noh +nnoremap :noh function! HiFile() let i = 1 @@ -501,7 +505,6 @@ inoremap ( () inoremap [ [] inoremap { {} -vnoremap S sa vnoremap ' ``>la' vnoremap q ``>la" vnoremap ( ``>la) @@ -591,6 +594,8 @@ vnoremap call SubstituteBySearch() " }}} " SIGN ----------------{{{ +nnoremap sc :e'set signcolumn='..&signcolumn + nnoremap si :exe ":sign place " .. line('.') .. " line=" .. line('.') .. " name=piet file=" .. expand("%:p") nnoremap sI :exe ":sign unplace * file=" .. expand("%:p") -- cgit v1.2.3-70-g09d2