From 476e72ba63891dda1a61c426cf9438b990768340 Mon Sep 17 00:00:00 2001 From: yan Date: Thu, 22 Dec 2011 11:55:18 -0800 Subject: [PATCH] Changed 'Q' to intelligently close window or kill buffer if it's the last one --- README.md | 3 +-- vim/plugin/settings/skwp-keymap.vim | 5 ----- vim/plugin/settings/window-killer.vim | 12 ++++++++++++ 3 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 vim/plugin/settings/window-killer.vim diff --git a/README.md b/README.md index 1dd9a72..b0c5a19 100644 --- a/README.md +++ b/README.md @@ -214,8 +214,7 @@ files contain key mappings as well (TODO: probably will move them out to skwp-ke **Window Navigation** * H L I M - to move left, right, up, down between windows - * Q - Quit window, kill buffer (:bw) - * \Q - Quit a window, keep buffer alive (Ctrl-w,c) + * Q - Intelligent Window Killer. Close window (wincmd c) if there are multiple windows to same buffer, or kill the buffer (bwipeout) if this is the last window into it. **Splits** diff --git a/vim/plugin/settings/skwp-keymap.vim b/vim/plugin/settings/skwp-keymap.vim index f080d54..e5bf31a 100644 --- a/vim/plugin/settings/skwp-keymap.vim +++ b/vim/plugin/settings/skwp-keymap.vim @@ -111,11 +111,6 @@ map :tabn 0 nnoremap vv v nnoremap ss s -" Use Q to kill a buffer -nnoremap Q :bw - -" Remap \Q to close a window (leave buffer open in memory) -nnoremap Q c "open the taglist (method browser) using ,t nnoremap ,T :TlistToggle diff --git a/vim/plugin/settings/window-killer.vim b/vim/plugin/settings/window-killer.vim new file mode 100644 index 0000000..71ff415 --- /dev/null +++ b/vim/plugin/settings/window-killer.vim @@ -0,0 +1,12 @@ +" Use Q to intelligently close a window +" (if there are multiple windows into the same buffer) +" or kill the buffer entirely if it's the last window looking into that buffer +function! CloseWindowOrKillBuffer() + if(bufwinnr('%')) > 1 + wincmd c + else + bdelete + endif +endfunction + +nnoremap Q :call CloseWindowOrKillBuffer()