From d9091ed49cda30b17d41f435c14960f3433fa60b Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 20 Jun 2024 00:26:26 +0800 Subject: Update --- vim/init/basic.vim | 22 +++++++++++----------- vim/init/keymaps.vim | 21 ++++++++++++--------- 2 files changed, 23 insertions(+), 20 deletions(-) (limited to 'vim') diff --git a/vim/init/basic.vim b/vim/init/basic.vim index 09ed985..eb895e2 100644 --- a/vim/init/basic.vim +++ b/vim/init/basic.vim @@ -109,19 +109,19 @@ nnoremap gl :call ToggleQuit() " Simply exit when closing the last buffer function! Bye() - " Delete current buffer if working on special filetype - let specialFileTypes = ['help', 'netrw', 'vim-plug', 'nerdtree'] - if index(specialFileTypes, &filetype) != -1 - :bdelete - " Delete current buffer if more than one buffers - elseif len(getbufinfo(bufnr())[0].windows) == 1 && len(getwininfo()) > 1 - :bdelete - elseif g:quitVimWhenPressingCtrlC - " Otherwise, quit vim - :silent! quit + let specialFileTypes = ['help', 'netrw', 'vim-plug', 'nerdtree'] + let bufIsSpecial = index(specialFileTypes, &filetype) != -1 + let bufInMultipleWindow = len(getbufinfo(bufnr())[0].windows) > 1 + + if len(getbufinfo({'buflisted': 1})) == 1 && len(getwininfo()) == 1 + if g:quitVimWhenPressingCtrlC + :silent! quit else - :echo "Press gl to allow quit with " + :echo "Press gl to allow quit with " endif + else + :bdelete + endif endfunction " Ctrl-C rules!!! diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim index da8ccd0..c57a57c 100644 --- a/vim/init/keymaps.vim +++ b/vim/init/keymaps.vim @@ -3,7 +3,7 @@ " Only for key mapping " " - COMMON_MAPPING -" - LINKS +" - MANAGE_VIMRC " - MOVING_WITH_READLINE " - INSERT_SURROUNDING " - JUMP_TO_TABS_WITH_ALT @@ -51,16 +51,14 @@ nmap q :cq " Switch wrap nmap W :set wrap! +" Show fold level when it changes +nnoremap zm zm:set foldlevel +nnoremap zr zr:set foldlevel + " :W sudo saves the file " (useful for handling the permission-denied error) command! W execute 'w !sudo -S tee %' edit! -" New tab like browser -nmap n :tabnew -nmap c :tabclose -nmap m :tabmove -nmap o :tabonly - " Enter to open file nnoremap gf nnoremap gF :e @@ -126,7 +124,7 @@ vnoremap so :source "---------------------------------------------------------------------- -" => Fast editing and reloading of vimrc configs +" MANAGE_VIMRC "---------------------------------------------------------------------- nnoremap e :edit $MYVIMRC autocmd! bufwritepost $MYVIMRC source $MYVIMRC @@ -205,9 +203,14 @@ inoremap :tablast " Useful mappings for managing tabs map tn :tabnew -map to :tabonly map tc :tabclose map tm :tabmove +map to :tabonly +nmap n :tabnew +nmap c :tabclose +nmap m :tabmove +nmap o :tabonly + noremap :call Tab_MoveLeft() noremap :call Tab_MoveRight() -- cgit v1.2.3-70-g09d2