From: Samir Benmendil Date: Wed, 21 Oct 2015 15:57:03 +0000 (+0100) Subject: vim: :close windows instead of :quit X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/5e613adedc4689fb4f0a58e51b44dd229066ab07 vim: :close windows instead of :quit --- diff --git a/vim/plugin/quit_another_window.vim b/vim/plugin/close_another_window.vim similarity index 64% rename from vim/plugin/quit_another_window.vim rename to vim/plugin/close_another_window.vim index 6453d84..cc36e3a 100644 --- a/vim/plugin/quit_another_window.vim +++ b/vim/plugin/close_another_window.vim @@ -1,6 +1,7 @@ "============================================================================= -" File: quit_another_window.vim -" Author: Dmitry Frank (dimon.frank@gmail.com) +" File: close_another_window.vim +" Author: Samir Benmendil +" Contributor: Dmitry Frank (dimon.frank@gmail.com) " Version: 1.04 "============================================================================= " See documentation in accompanying help file @@ -26,29 +27,29 @@ function! s:inputtarget() return c endfunction -function! QuitWindow(boolBang) +function! CloseWindow(boolBang) if (!a:boolBang) - :q + :close else - :q! + :close! endif endfunction "" function to close other window -" @param sWincmd - window movement command(s). +" @param sWincmd - window movement command(s). " for example, "h" used to close left window, " "j" used to close lower window, " etc. " " You can combine them: -" "jl" used to go to lower window, +" "jl" used to go to lower window, " then go to right window, " then close it. " etc. -function! QuitAnotherWindow(sWincmd, boolBang) +function! CloseAnotherWindow(sWincmd, boolBang) if empty(a:sWincmd) - call QuitWindow(a:boolBang) + call CloseWindow(a:boolBang) return endif @@ -57,7 +58,7 @@ function! QuitAnotherWindow(sWincmd, boolBang) let l:iCurWinnr = winnr() let l:iIndex = 0 - + while (l:iIndex < strlen(a:sWincmd)) " move to window that should be closed and get its winnr exec 'wincmd '.a:sWincmd[l:iIndex] @@ -78,7 +79,7 @@ function! QuitAnotherWindow(sWincmd, boolBang) endif " close needed window - call QuitWindow(a:boolBang) + call CloseWindow(a:boolBang) " go to starting window while (winnr() != l:iCurWinnr) @@ -86,25 +87,12 @@ function! QuitAnotherWindow(sWincmd, boolBang) endwhile endfunction - - " define plugin's commands -command! -nargs=? -bang -complete=file Qh call QuitAnotherWindow('h', 0) -command! -nargs=? -bang -complete=file Qj call QuitAnotherWindow('j', 0) -command! -nargs=? -bang -complete=file Qk call QuitAnotherWindow('k', 0) -command! -nargs=? -bang -complete=file Ql call QuitAnotherWindow('l', 0) - -command! -nargs=? -bang -complete=file Q call QuitAnotherWindow("", 0) - -nnoremap QAnotherWin :call QuitAnotherWindow(inputtarget(), 0) - -" define lowercased aliases if possible -if exists("loaded_cmdalias") && exists("*CmdAlias") - call CmdAlias('qh', 'Qh') - call CmdAlias('qj', 'Qj') - call CmdAlias('qk', 'Qk') - call CmdAlias('ql', 'Ql') +command! -nargs=? -bang -complete=file CloseLeftWindow call CloseAnotherWindow('h', 0) +command! -nargs=? -bang -complete=file CloseBelowWindow call CloseAnotherWindow('j', 0) +command! -nargs=? -bang -complete=file CloseAboveWindow call CloseAnotherWindow('k', 0) +command! -nargs=? -bang -complete=file CloseRightWindow call CloseAnotherWindow('l', 0) - call CmdAlias('q', 'Q') -endif +command! -nargs=? -bang -complete=file CloseAnotherWindow call CloseAnotherWindow("", 0) +nnoremap CloseAnotherWindow :call CloseAnotherWindow(inputtarget(), 0) diff --git a/vim/vimrc b/vim/vimrc index 145b8ce..6f5ea2e 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -436,6 +436,7 @@ nnoremap zx zMzxzt map :ls:b +" move between windows nnoremap w nnoremap W @@ -543,13 +544,13 @@ nmap cog IndentGuidesToggle nmap [og IndentGuidesEnable nmap ]og IndentGuidesDisable -" quit-another-window {{{2 +" close-another-window {{{2 nnoremap c nnoremap cc c -nnoremap ch :Qh -nnoremap cl :Ql -nnoremap cj :Qj -nnoremap ck :Qk +nnoremap ch :CloseLeftWindow +nnoremap cl :CloseRightWindow +nnoremap cj :CloseBelowWindow +nnoremap ck :CloseAboveWindow " python-mode {{{2