From b57c461014f585655d897abf0e0ac982807396b7 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Mon, 5 Aug 2024 18:41:51 +0800 Subject: Update --- vim/init/keymaps.vim | 71 ++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) (limited to 'vim/init/keymaps.vim') diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim index a423c20..e8cb61d 100644 --- a/vim/init/keymaps.vim +++ b/vim/init/keymaps.vim @@ -3,7 +3,7 @@ "====================================================================== " vim: sw=2 ts=2 foldmethod=marker foldmarker={{{,}}} -" COMMON_MAPPING {{{ +" COMMON {{{ " Space for searching map / @@ -37,9 +37,7 @@ augroup vimrc_CRfix augroup END " Spell -nnoremap \s :set spell!:set spell? -nnoremap ss ]s -nnoremap S [s +nnoremap \sp :set spell!:set spell? " Show full path by default nnoremap 1 @@ -48,6 +46,8 @@ nnoremap 1 vnoremap Tz :!trans -t zh-TW -b vnoremap Te :!trans -t en-US -b +nnoremap q: : + " }}} " WORKING_DIR {{{ @@ -157,6 +157,16 @@ inoremap :tablast " }}} +" }}} +" EDIT {{{ + +" Move one line up and down +nnoremap ddp +nnoremap ddkP + +" Clear current line +nnoremap S S + " }}} " REGISTER {{{ " Paste register 0 @@ -176,7 +186,7 @@ vnoremap Y "+y function! DeleteMark(mark) let mark = nr2char(a:mark) echo mark - if mark =~ '[a-Z]' + if mark =~ '\a' execute "delmarks " . mark endif endfunc @@ -259,7 +269,7 @@ function! ChangeUnfold(downward, count) let foldend -= move endif norm! zd - exe foldstart..","..foldend.."fold" + try | silent! exe foldstart..","..foldend.."fold" | endtry " Get back to origin cursor position norm! '' @@ -268,16 +278,6 @@ nnoremap z> ":\call ChangeUnfold(1,"..v:count..")\" nnoremap z< ":\call ChangeUnfold(0,"..v:count..")\" "}}} -" EDIT {{{ - -" Move one line up and down -nnoremap ddp -nnoremap ddkP - -" Clear current line -nnoremap S S - -" }}} " TERMINAL {{{ " Use z to toggle @@ -285,13 +285,17 @@ let g:alacritty_extra_padding = 0 function! ToggleWinPadding() if g:alacritty_extra_padding !alacritty msg config --window-id $WINDOWID --reset + call SetEmulaterBackground() hi EndOfBuffer None hi MsgArea None else redir => output | hi LineNr | redir END let bg_color = matchstr(output, 'guibg=\zs[^\s]\+\ze') - exe "hi EndOfBuffer guifg="..bg_color.." guibg="..bg_color - exe "hi MsgArea guibg="..bg_color + + try + exe "hi EndOfBuffer guifg="..bg_color.." guibg="..bg_color + exe "hi MsgArea guibg="..bg_color + endtry exe "!alacritty msg config --window-id $WINDOWID window.padding.x=300 'colors.primary.background=\"\\"..bg_color.."\"'" endif @@ -380,24 +384,16 @@ function! CloseBufferSafely() if answer == "" | return | endif endif - let l:bufnr = bufnr() - + let bufnr = bufnr() if len(t:bufs) == 1 " Close tab for last buffer tabclose else " Switch to proper buffer - let l:next_buf = get(t:bufs, bufnr('#')) ? bufnr('#') : filter(t:bufs, 'v:val != '..l:bufnr)[0] - exe "b "..l:next_buf - call filter(t:bufs, 'v:val != '..l:bufnr) + let next_buf = get(t:bufs, bufnr('#')) ? bufnr('#') : filter(t:bufs, 'v:val != '..bufnr)[0] + exe "b "..next_buf + call filter(t:bufs, 'v:val != '..bufnr) endif - - " Delete buffer if every t:buf doesn't have it - for tab in gettabinfo() - if get(tab.variables.bufs, l:bufnr) | return | endif - endfor - exe "bd! "..l:bufnr - endfunction function! Bye() let windows = gettabinfo(tabpagenr())[0]['windows'] @@ -493,10 +489,10 @@ endif " MANAGE_TABS {{{ " Useful mappings for managing tabs -map tn :tabnew -map tc :tabclose -map tm :tabmove -map to :tabonly +nnoremap tn :tabnew +nnoremap tc :tabclose +nnoremap tm :tabmove +nnoremap to :tabonly nnoremap :call Tab_MoveLeft() nnoremap :call Tab_MoveRight() @@ -508,7 +504,7 @@ autocmd TabLeave * let g:lasttab = tabpagenr() " Opens a new tab with the current buffer's path " Super useful when editing files in the same directory -map te :tabedit =expand("%:p:h") +nnoremap te :tabedit =expand("%:p:h") " Tab move functions function! Tvab_MoveLeft() @@ -598,6 +594,11 @@ endfunction " }}} " HIGHLIGHT {{{ +nnoremap \sy exists("g:syntax_on") ? ":syntax off " : ":syntax enable" + +" Toggle conceallevel0/2 +nnoremap \c ":set conceallevel="..(&cole ? 0 : 2)..":set cole?" + " Disable highlight when is pressed nnoremap :noh -- cgit v1.2.3-70-g09d2