"=============================================================================
-" File: quit_another_window.vim
-" Author: Dmitry Frank (dimon.frank@gmail.com)
+" File: close_another_window.vim
+" Author: Samir Benmendil <me [at] rmz [dot] io>
+" Contributor: Dmitry Frank (dimon.frank@gmail.com)
" Version: 1.04
"=============================================================================
" See documentation in accompanying help file
return c
endfunction
-function! <SID>QuitWindow(boolBang)
+function! <SID>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! <SID>QuitAnotherWindow(sWincmd, boolBang)
+function! <SID>CloseAnotherWindow(sWincmd, boolBang)
if empty(a:sWincmd)
- call <SID>QuitWindow(a:boolBang)
+ call <SID>CloseWindow(a:boolBang)
return
endif
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]
endif
" close needed window
- call <SID>QuitWindow(a:boolBang)
+ call <SID>CloseWindow(a:boolBang)
" go to starting window
while (winnr() != l:iCurWinnr)
endwhile
endfunction
-
-
" define plugin's commands
-command! -nargs=? -bang -complete=file Qh call <SID>QuitAnotherWindow('h', <bang>0)
-command! -nargs=? -bang -complete=file Qj call <SID>QuitAnotherWindow('j', <bang>0)
-command! -nargs=? -bang -complete=file Qk call <SID>QuitAnotherWindow('k', <bang>0)
-command! -nargs=? -bang -complete=file Ql call <SID>QuitAnotherWindow('l', <bang>0)
-
-command! -nargs=? -bang -complete=file Q call <SID>QuitAnotherWindow("<args>", <bang>0)
-
-nnoremap <silent> <Plug>QAnotherWin :<C-U>call <SID>QuitAnotherWindow(<SID>inputtarget(), 0)<CR>
-
-" 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 <SID>CloseAnotherWindow('h', <bang>0)
+command! -nargs=? -bang -complete=file CloseBelowWindow call <SID>CloseAnotherWindow('j', <bang>0)
+command! -nargs=? -bang -complete=file CloseAboveWindow call <SID>CloseAnotherWindow('k', <bang>0)
+command! -nargs=? -bang -complete=file CloseRightWindow call <SID>CloseAnotherWindow('l', <bang>0)
- call CmdAlias('q', 'Q')
-endif
+command! -nargs=? -bang -complete=file CloseAnotherWindow call <SID>CloseAnotherWindow("<args>", <bang>0)
+nnoremap <silent> <Plug>CloseAnotherWindow :<C-U>call <SID>CloseAnotherWindow(<SID>inputtarget(), 0)<CR>
map <F1> :ls<CR>:b<space>
+" move between windows
nnoremap <C-L> <C-W>w
nnoremap <C-H> <C-W>W
nmap <silent> [og <Plug>IndentGuidesEnable
nmap <silent> ]og <Plug>IndentGuidesDisable
-" quit-another-window {{{2
+" close-another-window {{{2
nnoremap <silent> <C-W>c <NOP>
nnoremap <silent> <C-W>cc <C-W>c
-nnoremap <silent> <C-W>ch :Qh<CR>
-nnoremap <silent> <C-W>cl :Ql<CR>
-nnoremap <silent> <C-W>cj :Qj<CR>
-nnoremap <silent> <C-W>ck :Qk<CR>
+nnoremap <silent> <C-W>ch :CloseLeftWindow<CR>
+nnoremap <silent> <C-W>cl :CloseRightWindow<CR>
+nnoremap <silent> <C-W>cj :CloseBelowWindow<CR>
+nnoremap <silent> <C-W>ck :CloseAboveWindow<CR>
" python-mode {{{2