]> git.rmz.io Git - dotfiles.git/commitdiff
vim: :close windows instead of :quit
authorSamir Benmendil <me@rmz.io>
Wed, 21 Oct 2015 15:57:03 +0000 (16:57 +0100)
committerSamir Benmendil <me@rmz.io>
Wed, 21 Oct 2015 15:57:03 +0000 (16:57 +0100)
vim/plugin/close_another_window.vim [moved from vim/plugin/quit_another_window.vim with 64% similarity]
vim/vimrc

similarity index 64%
rename from vim/plugin/quit_another_window.vim
rename to vim/plugin/close_another_window.vim
index 6453d848b00d5a4abdb6c6982637f0ca3e660cbf..cc36e3a80bf5743c792fc47f61c94e80b7031533 100644 (file)
@@ -1,6 +1,7 @@
 "=============================================================================
-" 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
@@ -26,29 +27,29 @@ function! s:inputtarget()
   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
 
@@ -57,7 +58,7 @@ function! <SID>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! <SID>QuitAnotherWindow(sWincmd, boolBang)
    endif
 
    " close needed window
-   call <SID>QuitWindow(a:boolBang)
+   call <SID>CloseWindow(a:boolBang)
 
    " go to starting window
    while (winnr() != l:iCurWinnr)
@@ -86,25 +87,12 @@ function! <SID>QuitAnotherWindow(sWincmd, boolBang)
    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>
index 145b8ce7de5c10aefed607739cc3f7ff63b9badf..6f5ea2e9f713ceb97549d2d757b765ccaec39c56 100644 (file)
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -436,6 +436,7 @@ nnoremap zx zMzxzt
 
 map <F1> :ls<CR>:b<space>
 
+" move between windows
 nnoremap <C-L> <C-W>w
 nnoremap <C-H> <C-W>W
 
@@ -543,13 +544,13 @@ nmap <silent> cog <Plug>IndentGuidesToggle
 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