Преглед на файлове

Merge pull request #1 from PhilRunninger/add_toggle

Add toggle
Phil Runninger преди 11 години
родител
ревизия
3df06984cb
променени са 3 файла, в които са добавени 23 реда и са изтрити 1 реда
  1. 1 0
      README.md
  2. 3 0
      doc/bufexplorer.txt
  3. 19 1
      plugin/bufexplorer.vim

+ 1 - 0
README.md

@@ -6,6 +6,7 @@ BufExplorer Plugin for Vim
 With bufexplorer, you can quickly and easily switch between buffers by using the one of the default public interfaces:
 
   '\be' (normal open)  or
+  '\bt' (toggle open / close)  or
   '\bs' (force horizontal split open)  or
   '\bv' (force vertical split open)
 

+ 3 - 0
doc/bufexplorer.txt

@@ -42,6 +42,8 @@ USAGE                                                      *bufexplorer-usage*
 
 To start exploring in the current window, use: >
  \be   or   :BufExplorer   or   Your custom key mapping
+To toggle bufexplorer on or off in the current window, use:
+ \bt   or   :ToggleBufExplorer   or   Your custom key mapping
 To start exploring in a newly split horizontal window, use: >
  \bs   or   :BufExplorerHorizontalSplit   or   Your custom key mapping
 To start exploring in a newly split vertical window, use: >
@@ -130,6 +132,7 @@ override bufexplorer's default mappings by setting up something like the
 following in your vimrc file:
 
   nnoremap <silent> <F11> :BufExplorer<CR>
+  nnoremap <silent> <s-F11> :ToggleBufExplorer<CR>
   nnoremap <silent> <m-F11> :BufExplorerHorizontalSplit<CR>
   nnoremap <silent> <c-F11> :BufExplorerVerticalSplit<CR>
 

+ 19 - 1
plugin/bufexplorer.vim

@@ -44,6 +44,7 @@
 "               You may use the default keymappings of
 "
 "                 <Leader>be  - Opens BufExplorer
+"                 <Leader>bt  - Toggles BufExplorer open or closed
 "                 <Leader>bs  - Opens horizontally split window BufExplorer
 "                 <Leader>bv  - Opens vertically split window BufExplorer
 "
@@ -51,12 +52,14 @@
 "               in your vimrc file, for example:
 "
 "                   nnoremap <silent> <F11> :BufExplorer<CR>
+"                   nnoremap <silent> <s-F11> :ToggleBufExplorer<CR>
 "                   nnoremap <silent> <m-F11> :BufExplorerHorizontalSplit<CR>
 "                   nnoremap <silent> <c-F11> :BufExplorerVerticalSplit<CR>
 "
 "               Or you can use
 "
 "                 ":BufExplorer"                - Opens BufExplorer
+"                 ":ToggleBufExplorer"          - Opens/Closes BufExplorer
 "                 ":BufExplorerHorizontalSplit" - Opens horizontally window BufExplorer
 "                 ":BufExplorerVerticalSplit"   - Opens vertically split window BufExplorer
 "
@@ -84,6 +87,7 @@ endif
 
 " Create commands {{{2
 command! BufExplorer :call BufExplorer()
+command! ToggleBufExplorer :call ToggleBufExplorer()
 command! BufExplorerHorizontalSplit :call BufExplorerHorizontalSplit()
 command! BufExplorerVerticalSplit :call BufExplorerVerticalSplit()
 
@@ -339,6 +343,16 @@ function! BufExplorerVerticalSplit()
     execute "BufExplorer"
 endfunction
 
+" ToggleBufExplorer {{{2
+function! ToggleBufExplorer()
+    if exists("s:running") && s:running == 1
+        call BufExplorer()
+        call s:Close()
+    else
+        call BufExplorer()
+    endif
+endfunction
+
 " BufExplorer {{{2
 function! BufExplorer()
     let name = s:name
@@ -914,7 +928,7 @@ function! s:Close()
         " buffers.
         execute "enew"
     else
-        " Since there are buffers left to switch to, swith to the previous and
+        " Since there are buffers left to switch to, switch to the previous and
         " then the current.
         for b in reverse(listed[0:1])
             execute "keepjumps silent b ".b
@@ -1205,6 +1219,10 @@ if !hasmapto('BufExplorer') && g:bufExplorerDisableDefaultKeyMapping == 0
     nnoremap <script> <silent> <unique> <Leader>be :BufExplorer<CR>
 endif
 
+if !hasmapto('ToggleBufExplorer') && g:bufExplorerDisableDefaultKeyMapping == 0
+    nnoremap <script> <silent> <unique> <Leader>bt :ToggleBufExplorer<CR>
+endif
+
 if !hasmapto('BufExplorerHorizontalSplit') && g:bufExplorerDisableDefaultKeyMapping == 0
     nnoremap <script> <silent> <unique> <Leader>bs :BufExplorerHorizontalSplit<CR>
 endif