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

Use `:botright` and `:topleft` to choose split direction.

This avoids the need to modify and restore the global options
'splitbelow' and 'splitright' and prepares for additional split
combinations.
Michael Henry преди 11 месеца
родител
ревизия
fc0b53ce30
променени са 1 файла, в които са добавени 15 реда и са изтрити 16 реда
  1. 15 16
      plugin/bufexplorer.vim

+ 15 - 16
plugin/bufexplorer.vim

@@ -657,24 +657,23 @@ function! BufExplorer(...)
     call s:MRUGarbageCollectBufs()
     call s:MRUGarbageCollectTabs()
 
-    " We may have to split the current window.
-    if action != 'current'
-        " Save off the original settings.
-        let [_splitbelow, _splitright] = [&splitbelow, &splitright]
-
-        " Set the setting to ours.
-        let [&splitbelow, &splitright] = [g:bufExplorerSplitBelow, g:bufExplorerSplitRight]
-        let _size = (action == "split") ? g:bufExplorerSplitHorzSize : g:bufExplorerSplitVertSize
+    " `{ action: [splitMode, botRight] }`.
+    let actionMap = {
+            \ 'split'   : ['split', g:bufExplorerSplitBelow],
+            \ 'vsplit'  : ['vsplit', g:bufExplorerSplitRight],
+            \ 'current' : ['', 0],
+            \}
+    let [splitMode, botRight] = actionMap[action]
 
-        " Split the window either horizontally or vertically.
-        if _size <= 0
-            execute 'keepalt ' . action
-        else
-            execute 'keepalt ' . _size . action
+    " We may have to split the current window.
+    if splitMode != ''
+        let size = splitMode == 'split' ? g:bufExplorerSplitHorzSize : g:bufExplorerSplitVertSize
+        let cmd = 'keepalt ' . (botRight ? 'botright ' : 'topleft ')
+        if size > 0
+            let cmd .= size
         endif
-
-        " Restore the original settings.
-        let [&splitbelow, &splitright] = [_splitbelow, _splitright]
+        let cmd .= splitMode
+        execute cmd
 
         " Remember that a split was triggered
         let s:didSplit = 1