bufexplorer.vim 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. "=============================================================================
  2. " Copyright: Copyright (c) 2001-2014, Jeff Lanzarotta
  3. " All rights reserved.
  4. "
  5. " Redistribution and use in source and binary forms, with or
  6. " without modification, are permitted provided that the
  7. " following conditions are met:
  8. "
  9. " * Redistributions of source code must retain the above
  10. " copyright notice, this list of conditions and the following
  11. " disclaimer.
  12. "
  13. " * Redistributions in binary form must reproduce the above
  14. " copyright notice, this list of conditions and the following
  15. " disclaimer in the documentation and/or other materials
  16. " provided with the distribution.
  17. "
  18. " * Neither the name of the {organization} nor the names of its
  19. " contributors may be used to endorse or promote products
  20. " derived from this software without specific prior written
  21. " permission.
  22. "
  23. " THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  24. " CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  25. " INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  26. " MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. " DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  28. " CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. " SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  30. " NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31. " LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. " HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. " CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  34. " OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  35. " EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. " Name Of File: bufexplorer.vim
  37. " Description: Buffer Explorer Vim Plugin
  38. " Maintainer: Jeff Lanzarotta (delux256-vim at yahoo dot com)
  39. " Last Changed: Monday, 03 November 2014
  40. " Version: See g:bufexplorer_version for version number.
  41. " Usage: This file should reside in the plugin directory and be
  42. " automatically sourced.
  43. "
  44. " You may use the default keymappings of
  45. "
  46. " <Leader>be - Opens BufExplorer
  47. " <Leader>bs - Opens horizontally split window BufExplorer
  48. " <Leader>bv - Opens vertically split window BufExplorer
  49. "
  50. " Or you can override the defaults and define your own mapping
  51. " in your vimrc file, for example:
  52. "
  53. " nnoremap <silent> <F11> :BufExplorer<CR>
  54. " nnoremap <silent> <m-F11> :BufExplorerHorizontalSplit<CR>
  55. " nnoremap <silent> <c-F11> :BufExplorerVerticalSplit<CR>
  56. "
  57. " Or you can use
  58. "
  59. " ":BufExplorer" - Opens BufExplorer
  60. " ":BufExplorerHorizontalSplit" - Opens horizontally window BufExplorer
  61. " ":BufExplorerVerticalSplit" - Opens vertically split window BufExplorer
  62. "
  63. " For more help see supplied documentation.
  64. " History: See supplied documentation.
  65. "=============================================================================
  66. " Plugin Code {{{1
  67. " Exit quickly if already running or when 'compatible' is set. {{{2
  68. if exists("g:bufexplorer_version") || &cp
  69. finish
  70. endif
  71. "2}}}
  72. " Version number
  73. let g:bufexplorer_version = "7.4.6"
  74. " Check for Vim version {{{2
  75. if v:version < 700
  76. echohl WarningMsg
  77. echo "Sorry, bufexplorer ".g:bufexplorer_version." required Vim 7.0 and greater."
  78. echohl None
  79. finish
  80. endif
  81. " Create commands {{{2
  82. command! BufExplorer :call BufExplorer()
  83. command! BufExplorerHorizontalSplit :call BufExplorerHorizontalSplit()
  84. command! BufExplorerVerticalSplit :call BufExplorerVerticalSplit()
  85. " Set {{{2
  86. function! s:Set(var, default)
  87. if !exists(a:var)
  88. if type(a:default)
  89. execute "let" a:var "=" string(a:default)
  90. else
  91. execute "let" a:var "=" a:default
  92. endif
  93. return 1
  94. endif
  95. return 0
  96. endfunction
  97. " Script variables {{{2
  98. let s:MRU_Exclude_List = ["[BufExplorer]","__MRU_Files__"]
  99. let s:MRUList = []
  100. let s:name = '[BufExplorer]'
  101. let s:originBuffer = 0
  102. let s:running = 0
  103. let s:sort_by = ["number", "name", "fullpath", "mru", "extension"]
  104. let s:splitMode = ""
  105. let s:tabSpace = []
  106. let s:types = {"fullname": ':p', "path": ':p:h', "relativename": ':~:.', "relativepath": ':~:.:h', "shortname": ':t'}
  107. " Setup the autocommands that handle the MRUList and other stuff. {{{2
  108. autocmd VimEnter * call s:Setup()
  109. " Setup {{{2
  110. function! s:Setup()
  111. call s:Reset()
  112. " Now that the MRUList is created, add the other autocmds.
  113. augroup BufExplorer
  114. autocmd!
  115. autocmd BufEnter,BufNew * call s:ActivateBuffer()
  116. autocmd BufWipeOut * call s:DeactivateBuffer(1)
  117. autocmd BufDelete * call s:DeactivateBuffer(0)
  118. autocmd BufWinEnter \[BufExplorer\] call s:Initialize()
  119. autocmd BufWinLeave \[BufExplorer\] call s:Cleanup()
  120. autocmd TabEnter * call s:TabEnter()
  121. autocmd SessionLoadPost * call s:Reset()
  122. augroup END
  123. endfunction
  124. " Reset {{{2
  125. function! s:Reset()
  126. " Build initial MRUList. This makes sure all the files specified on the
  127. " command line are picked up correctly.
  128. let s:MRUList = range(1, bufnr('$'))
  129. " Initialize one tab space array, ignore zero-based tabpagenr since all
  130. " tabpagenr's start at 1. -1 signifies this is the first time we are
  131. " referencing this tabpagenr.
  132. "
  133. " If Vim has been loaded with mksession, then it is possible for more tabs
  134. " to exist. So use tabpagenr() to determine how large to make the array. If
  135. " there are 4 tabs, there should be 5 elements in this array.
  136. "
  137. " Each element will hold a CSV list of buffers viewed in that tab. So on
  138. " the 3rd tab, if there user has viewed 4 different buffers in that tab, the
  139. " value would be:
  140. " echo s:tabSpace[3]
  141. " [4, 9, 1, 10]
  142. " echo s:tabSpace
  143. " [[-1], [-1], [-1], [4, 9, 1, 10], [-1]]
  144. let s:tabSpace = []
  145. let i = 0
  146. while(tabpagenr('$') > 0 && i <= tabpagenr('$'))
  147. call add(s:tabSpace, [-1])
  148. let i = i + 1
  149. endwhile
  150. endfunction
  151. " ActivateBuffer {{{2
  152. function! s:ActivateBuffer()
  153. " Verify the current tabpage exists in the
  154. " current s:tabSpace array. This can be missing
  155. " entries when restoring sessions.
  156. let i = 0
  157. while( tabpagenr('$') > 0 && i <= tabpagenr() )
  158. " Number: 0
  159. " String: 1
  160. " Funcref: 2
  161. " List: 3
  162. " Dictionary: 4
  163. " Float: 5
  164. if type(get(s:tabSpace, i)) == 0
  165. call add(s:tabSpace, [-1])
  166. endif
  167. let i = i + 1
  168. endwhile
  169. let _bufnr = bufnr("%")
  170. let list = get(s:tabSpace, tabpagenr(), [-1])
  171. if !empty(list) && list[0] == '-1'
  172. " The first time we add a tab, Vim uses the current buffer
  173. " as it's starting page. Even though we are about to
  174. " edit a new page (BufEnter is triggered after), so
  175. " remove the -1 entry indicating we have covered this case.
  176. let list = []
  177. call add(list, _bufnr)
  178. let s:tabSpace[tabpagenr()] = list
  179. elseif empty(list) || index(list, _bufnr) == -1
  180. " Add new buffer to this tab's buffer list.
  181. call add(list, _bufnr)
  182. let s:tabSpace[tabpagenr()] = list
  183. if g:bufExplorerOnlyOneTab == 1
  184. " If a buffer can only be available in 1 tab page ensure this
  185. " buffer is not present in any other tabs
  186. let tabidx = 1
  187. while tabidx < len(s:tabSpace)
  188. if tabidx != tabpagenr()
  189. let bufidx = index(s:tabSpace[tabidx], _bufnr)
  190. if bufidx != -1
  191. call remove(s:tabSpace[tabidx], bufidx)
  192. endif
  193. endif
  194. let tabidx = tabidx + 1
  195. endwhile
  196. endif
  197. endif
  198. call s:MRUPush(_bufnr)
  199. endfunction
  200. " DeactivateBuffer {{{2
  201. function! s:DeactivateBuffer(remove)
  202. let _bufnr = str2nr(expand("<abuf>"))
  203. call s:MRUPop(_bufnr)
  204. endfunction
  205. " TabEnter {{{2
  206. function! s:TabEnter()
  207. " Make s:tabSpace 1-based
  208. if empty(s:tabSpace) || len(s:tabSpace) < (tabpagenr() + 1)
  209. call add(s:tabSpace, [-1])
  210. endif
  211. endfunction
  212. " MRUPop {{{2
  213. function! s:MRUPop(bufnr)
  214. call filter(s:MRUList, 'v:val != '.a:bufnr)
  215. endfunction
  216. " MRUPush {{{2
  217. function! s:MRUPush(buf)
  218. " Skip temporary buffer with buftype set. Don't add the BufExplorer window
  219. " to the list.
  220. if s:ShouldIgnore(a:buf) == 1
  221. return
  222. endif
  223. " Remove the buffer number from the list if it already exists.
  224. call s:MRUPop(a:buf)
  225. " Add the buffer number to the head of the list.
  226. call insert(s:MRUList, a:buf)
  227. endfunction
  228. " ShouldIgnore {{{2
  229. function! s:ShouldIgnore(buf)
  230. " Ignore temporary buffers with buftype set.
  231. if empty(getbufvar(a:buf, "&buftype") == 0)
  232. return 1
  233. endif
  234. " Ignore buffers with no name.
  235. if empty(bufname(a:buf)) == 1
  236. return 1
  237. endif
  238. " Ignore the BufExplorer buffer.
  239. if fnamemodify(bufname(a:buf), ":t") == s:name
  240. return 1
  241. endif
  242. " Ignore any buffers in the exclude list.
  243. if index(s:MRU_Exclude_List, bufname(a:buf)) >= 0
  244. return 1
  245. endif
  246. " Else return 0 to indicate that the buffer was not ignored.
  247. return 0
  248. endfunction
  249. " Initialize {{{2
  250. function! s:Initialize()
  251. let s:_insertmode = &insertmode
  252. set noinsertmode
  253. let s:_showcmd = &showcmd
  254. set noshowcmd
  255. let s:_cpo = &cpo
  256. set cpo&vim
  257. let s:_report = &report
  258. let &report = 10000
  259. setlocal nonumber
  260. setlocal foldcolumn=0
  261. setlocal nofoldenable
  262. setlocal cursorline
  263. setlocal nospell
  264. setlocal nobuflisted
  265. let s:running = 1
  266. endfunction
  267. " Cleanup {{{2
  268. function! s:Cleanup()
  269. if exists("s:_insertmode")
  270. let &insertmode = s:_insertmode
  271. endif
  272. if exists("s:_showcmd")
  273. let &showcmd = s:_showcmd
  274. endif
  275. if exists("s:_cpo")
  276. let &cpo = s:_cpo
  277. endif
  278. if exists("s:_report")
  279. let &report = s:_report
  280. endif
  281. let s:running = 0
  282. let s:splitMode = ""
  283. delmarks!
  284. endfunction
  285. " BufExplorerHorizontalSplit {{{2
  286. function! BufExplorerHorizontalSplit()
  287. let s:splitMode = "sp"
  288. execute "BufExplorer"
  289. endfunction
  290. " BufExplorerVerticalSplit {{{2
  291. function! BufExplorerVerticalSplit()
  292. let s:splitMode = "vsp"
  293. execute "BufExplorer"
  294. endfunction
  295. " BufExplorer {{{2
  296. function! BufExplorer()
  297. let name = s:name
  298. if !has("win32")
  299. " On non-Windows boxes, escape the name so that is shows up correctly.
  300. let name = escape(name, "[]")
  301. endif
  302. " Make sure there is only one explorer open at a time.
  303. if s:running == 1
  304. " Go to the open buffer.
  305. if has("gui")
  306. execute "drop" name
  307. endif
  308. return
  309. endif
  310. " Add zero to ensure the variable is treated as a number.
  311. let s:originBuffer = bufnr("%") + 0
  312. silent let s:raw_buffer_listing = s:GetBufferInfo(0)
  313. " We may have to split the current window.
  314. if s:splitMode != ""
  315. " Save off the original settings.
  316. let [_splitbelow, _splitright] = [&splitbelow, &splitright]
  317. " Set the setting to ours.
  318. let [&splitbelow, &splitright] = [g:bufExplorerSplitBelow, g:bufExplorerSplitRight]
  319. let _size = (s:splitMode == "sp") ? g:bufExplorerSplitHorzSize : g:bufExplorerSplitVertSize
  320. " Split the window either horizontally or vertically.
  321. if _size <= 0
  322. execute 'keepalt ' . s:splitMode
  323. else
  324. execute 'keepalt ' . _size . s:splitMode
  325. endif
  326. " Restore the original settings.
  327. let [&splitbelow, &splitright] = [_splitbelow, _splitright]
  328. endif
  329. if !exists("b:displayMode") || b:displayMode != "winmanager"
  330. " Do not use keepalt when opening bufexplorer to allow the buffer that
  331. " we are leaving to become the new alternate buffer
  332. execute "silent keepjumps hide edit".name
  333. endif
  334. call s:DisplayBufferList()
  335. " Position the cursor in the newly displayed list on the line representing
  336. " the active buffer. The active buffer is the line with the '%' character
  337. " in it.
  338. execute search("%")
  339. endfunction
  340. " DisplayBufferList {{{2
  341. function! s:DisplayBufferList()
  342. " Do not set bufhidden since it wipes out the data if we switch away from
  343. " the buffer using CTRL-^.
  344. setlocal buftype=nofile
  345. setlocal modifiable
  346. setlocal noswapfile
  347. setlocal nowrap
  348. call s:SetupSyntax()
  349. call s:MapKeys()
  350. " Wipe out any existing lines in case BufExplorer buffer exists and the
  351. " user had changed any global settings that might reduce the number of
  352. " lines needed in the buffer.
  353. silent keepjumps 1,$d _
  354. call setline(1, s:CreateHelp())
  355. call s:BuildBufferList()
  356. call cursor(s:firstBufferLine, 1)
  357. if !g:bufExplorerResize
  358. normal! zz
  359. endif
  360. setlocal nomodifiable
  361. endfunction
  362. " MapKeys {{{2
  363. function! s:MapKeys()
  364. if exists("b:displayMode") && b:displayMode == "winmanager"
  365. nnoremap <buffer> <silent> <tab> :call <SID>SelectBuffer()<CR>
  366. endif
  367. nnoremap <script> <silent> <buffer> <2-leftmouse> :call <SID>SelectBuffer()<CR>
  368. nnoremap <script> <silent> <buffer> <CR> :call <SID>SelectBuffer()<CR>
  369. nnoremap <script> <silent> <buffer> <F1> :call <SID>ToggleHelp()<CR>
  370. nnoremap <script> <silent> <buffer> <s-cr> :call <SID>SelectBuffer("tab")<CR>
  371. nnoremap <script> <silent> <buffer> B :call <SID>ToggleOnlyOneTab()<CR>
  372. nnoremap <script> <silent> <buffer> b :call <SID>SelectBuffer("ask")<CR>
  373. nnoremap <script> <silent> <buffer> d :call <SID>RemoveBuffer("delete")<CR>
  374. xnoremap <script> <silent> <buffer> d :call <SID>RemoveBuffer("delete")<CR>
  375. nnoremap <script> <silent> <buffer> D :call <SID>RemoveBuffer("wipe")<CR>
  376. xnoremap <script> <silent> <buffer> D :call <SID>RemoveBuffer("wipe")<CR>
  377. nnoremap <script> <silent> <buffer> f :call <SID>ToggleFindActive()<CR>
  378. nnoremap <script> <silent> <buffer> m :call <SID>MRUListShow()<CR>
  379. nnoremap <script> <silent> <buffer> o :call <SID>SelectBuffer()<CR>
  380. nnoremap <script> <silent> <buffer> p :call <SID>ToggleSplitOutPathName()<CR>
  381. nnoremap <script> <silent> <buffer> q :call <SID>Close()<CR>
  382. nnoremap <script> <silent> <buffer> r :call <SID>SortReverse()<CR>
  383. nnoremap <script> <silent> <buffer> R :call <SID>ToggleShowRelativePath()<CR>
  384. nnoremap <script> <silent> <buffer> s :call <SID>SortSelect()<CR>
  385. nnoremap <script> <silent> <buffer> S :call <SID>ReverseSortSelect()<CR>
  386. nnoremap <script> <silent> <buffer> t :call <SID>SelectBuffer("tab")<CR>
  387. nnoremap <script> <silent> <buffer> T :call <SID>ToggleShowTabBuffer()<CR>
  388. nnoremap <script> <silent> <buffer> u :call <SID>ToggleShowUnlisted()<CR>
  389. for k in ["G", "n", "N", "L", "M", "H"]
  390. execute "nnoremap <buffer> <silent>" k ":keepjumps normal!" k."<CR>"
  391. endfor
  392. endfunction
  393. " SetupSyntax {{{2
  394. function! s:SetupSyntax()
  395. if has("syntax")
  396. syn match bufExplorerHelp "^\".*" contains=bufExplorerSortBy,bufExplorerMapping,bufExplorerTitle,bufExplorerSortType,bufExplorerToggleSplit,bufExplorerToggleOpen
  397. syn match bufExplorerOpenIn "Open in \w\+ window" contained
  398. syn match bufExplorerSplit "\w\+ split" contained
  399. syn match bufExplorerSortBy "Sorted by .*" contained contains=bufExplorerOpenIn,bufExplorerSplit
  400. syn match bufExplorerMapping "\" \zs.\+\ze :" contained
  401. syn match bufExplorerTitle "Buffer Explorer.*" contained
  402. syn match bufExplorerSortType "'\w\{-}'" contained
  403. syn match bufExplorerBufNbr /^\s*\d\+/
  404. syn match bufExplorerToggleSplit "toggle split type" contained
  405. syn match bufExplorerToggleOpen "toggle open mode" contained
  406. syn match bufExplorerModBuf /^\s*\d\+.\{4}+.*/
  407. syn match bufExplorerLockedBuf /^\s*\d\+.\{3}[\-=].*/
  408. syn match bufExplorerHidBuf /^\s*\d\+.\{2}h.*/
  409. syn match bufExplorerActBuf /^\s*\d\+.\{2}a.*/
  410. syn match bufExplorerCurBuf /^\s*\d\+.%.*/
  411. syn match bufExplorerAltBuf /^\s*\d\+.#.*/
  412. syn match bufExplorerUnlBuf /^\s*\d\+u.*/
  413. syn match bufExplorerInactBuf /^\s*\d\+ \{7}.*/
  414. hi def link bufExplorerBufNbr Number
  415. hi def link bufExplorerMapping NonText
  416. hi def link bufExplorerHelp Special
  417. hi def link bufExplorerOpenIn Identifier
  418. hi def link bufExplorerSortBy String
  419. hi def link bufExplorerSplit NonText
  420. hi def link bufExplorerTitle NonText
  421. hi def link bufExplorerSortType bufExplorerSortBy
  422. hi def link bufExplorerToggleSplit bufExplorerSplit
  423. hi def link bufExplorerToggleOpen bufExplorerOpenIn
  424. hi def link bufExplorerActBuf Identifier
  425. hi def link bufExplorerAltBuf String
  426. hi def link bufExplorerCurBuf Type
  427. hi def link bufExplorerHidBuf Constant
  428. hi def link bufExplorerLockedBuf Special
  429. hi def link bufExplorerModBuf Exception
  430. hi def link bufExplorerUnlBuf Comment
  431. hi def link bufExplorerInactBuf Comment
  432. endif
  433. endfunction
  434. " ToggleHelp {{{2
  435. function! s:ToggleHelp()
  436. let g:bufExplorerDetailedHelp = !g:bufExplorerDetailedHelp
  437. setlocal modifiable
  438. " Save position.
  439. normal! ma
  440. " Remove old header.
  441. if s:firstBufferLine > 1
  442. execute "keepjumps 1,".(s:firstBufferLine - 1) "d _"
  443. endif
  444. call append(0, s:CreateHelp())
  445. silent! normal! g`a
  446. delmarks a
  447. setlocal nomodifiable
  448. if exists("b:displayMode") && b:displayMode == "winmanager"
  449. call WinManagerForceReSize("BufExplorer")
  450. endif
  451. endfunction
  452. " GetHelpStatus {{{2
  453. function! s:GetHelpStatus()
  454. let ret = '" Sorted by '.((g:bufExplorerReverseSort == 1) ? "reverse " : "").g:bufExplorerSortBy
  455. let ret .= ' | '.((g:bufExplorerFindActive == 0) ? "Don't " : "")."Locate buffer"
  456. let ret .= ((g:bufExplorerShowUnlisted == 0) ? "" : " | Show unlisted")
  457. let ret .= ((g:bufExplorerShowTabBuffer == 0) ? "" : " | Show buffers/tab")
  458. let ret .= ((g:bufExplorerOnlyOneTab == 0) ? "" : " | One tab/buffer")
  459. let ret .= ' | '.((g:bufExplorerShowRelativePath == 0) ? "Absolute" : "Relative")
  460. let ret .= ' '.((g:bufExplorerSplitOutPathName == 0) ? "Full" : "Split")." path"
  461. return ret
  462. endfunction
  463. " CreateHelp {{{2
  464. function! s:CreateHelp()
  465. if g:bufExplorerDefaultHelp == 0 && g:bufExplorerDetailedHelp == 0
  466. let s:firstBufferLine = 1
  467. return []
  468. endif
  469. let header = []
  470. if g:bufExplorerDetailedHelp == 1
  471. call add(header, '" Buffer Explorer ('.g:bufexplorer_version.')')
  472. call add(header, '" --------------------------')
  473. call add(header, '" <F1> : toggle this help')
  474. call add(header, '" <enter> or o or Mouse-Double-Click : open buffer under cursor')
  475. call add(header, '" <shift-enter> or t : open buffer in another tab')
  476. call add(header, '" B : toggle if to save/use recent tab or not')
  477. call add(header, '" d : delete buffer')
  478. call add(header, '" D : wipe buffer')
  479. call add(header, '" f : toggle find active buffer')
  480. call add(header, '" p : toggle spliting of file and path name')
  481. call add(header, '" q : quit')
  482. call add(header, '" r : reverse sort')
  483. call add(header, '" R : toggle showing relative or full paths')
  484. call add(header, '" s : cycle thru "sort by" fields '.string(s:sort_by).'')
  485. call add(header, '" S : reverse cycle thru "sort by" fields')
  486. call add(header, '" T : toggle if to show only buffers for this tab or not')
  487. call add(header, '" u : toggle showing unlisted buffers')
  488. else
  489. call add(header, '" Press <F1> for Help')
  490. endif
  491. if (!exists("b:displayMode") || b:displayMode != "winmanager") || (b:displayMode == "winmanager" && g:bufExplorerDetailedHelp == 1)
  492. call add(header, s:GetHelpStatus())
  493. call add(header, '"=')
  494. endif
  495. let s:firstBufferLine = len(header) + 1
  496. return header
  497. endfunction
  498. " GetBufferInfo {{{2
  499. function! s:GetBufferInfo(bufnr)
  500. redir => bufoutput
  501. " Show all buffers including the unlisted ones. [!] tells Vim to show the
  502. " unlisted ones.
  503. buffers!
  504. redir END
  505. if a:bufnr > 0
  506. " Since we are only interested in this specified buffer
  507. " remove the other buffers listed
  508. let bufoutput = substitute(bufoutput."\n", '^.*\n\(\s*'.a:bufnr.'\>.\{-}\)\n.*', '\1', '')
  509. endif
  510. let [all, allwidths, listedwidths] = [[], {}, {}]
  511. for n in keys(s:types)
  512. let allwidths[n] = []
  513. let listedwidths[n] = []
  514. endfor
  515. " Loop over each line in the buffer.
  516. for buf in split(bufoutput, '\n')
  517. let bits = split(buf, '"')
  518. " Use first and last components after the split on '"', in case a
  519. " filename with an embedded '"' is present.
  520. let b = {"attributes": bits[0], "line": substitute(bits[-1], '\s*', '', '')}
  521. let name = bufname(str2nr(b.attributes))
  522. let b["hasNoName"] = empty(name)
  523. if b.hasNoName
  524. let name = "[No Name]"
  525. endif
  526. for [key, val] in items(s:types)
  527. let b[key] = fnamemodify(name, val)
  528. endfor
  529. if getftype(b.fullname) == "dir" && g:bufExplorerShowDirectories == 1
  530. let b.shortname = "<DIRECTORY>"
  531. endif
  532. call add(all, b)
  533. for n in keys(s:types)
  534. call add(allwidths[n], s:StringWidth(b[n]))
  535. if b.attributes !~ "u"
  536. call add(listedwidths[n], s:StringWidth(b[n]))
  537. endif
  538. endfor
  539. endfor
  540. let [s:allpads, s:listedpads] = [{}, {}]
  541. for n in keys(s:types)
  542. let s:allpads[n] = repeat(' ', max(allwidths[n]))
  543. let s:listedpads[n] = repeat(' ', max(listedwidths[n]))
  544. endfor
  545. return all
  546. endfunction
  547. " BuildBufferList {{{2
  548. function! s:BuildBufferList()
  549. let lines = []
  550. " Loop through every buffer.
  551. for buf in s:raw_buffer_listing
  552. " Skip unlisted buffers if we are not to show them.
  553. if !g:bufExplorerShowUnlisted && buf.attributes =~ "u"
  554. " Skip unlisted buffers if we are not to show them.
  555. continue
  556. endif
  557. " Skip "No Name" buffers if we are not to show them.
  558. if g:bufExplorerShowNoName == 0 && buf.hasNoName
  559. continue
  560. endif
  561. " Are we to show only buffer(s) for this tab?
  562. if g:bufExplorerShowTabBuffer
  563. let show_buffer = 0
  564. for bufnr in s:tabSpace[tabpagenr()]
  565. if buf.attributes =~ '^\s*'.bufnr.'\>'
  566. " Only buffers shown on the current tabpagenr
  567. let show_buffer = 1
  568. break
  569. endif
  570. endfor
  571. if show_buffer == 0
  572. continue
  573. endif
  574. endif
  575. let line = buf.attributes." "
  576. " Are we to split the path and file name?
  577. if g:bufExplorerSplitOutPathName
  578. let type = (g:bufExplorerShowRelativePath) ? "relativepath" : "path"
  579. let path = buf[type]
  580. let pad = (g:bufExplorerShowUnlisted) ? s:allpads.shortname : s:listedpads.shortname
  581. let line .= buf.shortname." ".strpart(pad.path, s:StringWidth(buf.shortname))
  582. else
  583. let type = (g:bufExplorerShowRelativePath) ? "relativename" : "fullname"
  584. let path = buf[type]
  585. let line .= path
  586. endif
  587. let pads = (g:bufExplorerShowUnlisted) ? s:allpads : s:listedpads
  588. if !empty(pads[type])
  589. let line .= strpart(pads[type], s:StringWidth(path))." "
  590. endif
  591. let line .= buf.line
  592. call add(lines, line)
  593. endfor
  594. call setline(s:firstBufferLine, lines)
  595. call s:SortListing()
  596. endfunction
  597. " SelectBuffer {{{2
  598. function! s:SelectBuffer(...)
  599. " Sometimes messages are not cleared when we get here so it looks like an
  600. " error has occurred when it really has not.
  601. "echo ""
  602. let _bufNbr = -1
  603. if (a:0 == 1) && (a:1 == "ask")
  604. " Ask the user for input.
  605. call inputsave()
  606. let cmd = input("Enter buffer number to switch to: ")
  607. call inputrestore()
  608. " Clear the message area from the previous prompt.
  609. redraw | echo
  610. if strlen(cmd) > 0
  611. let _bufNbr = str2nr(cmd)
  612. else
  613. call s:Error("Invalid buffer number, try again.")
  614. return
  615. endif
  616. else
  617. " Are we on a line with a file name?
  618. if line('.') < s:firstBufferLine
  619. execute "normal! \<CR>"
  620. return
  621. endif
  622. let _bufNbr = str2nr(getline('.'))
  623. " Check and see if we are running BufferExplorer via WinManager.
  624. if exists("b:displayMode") && b:displayMode == "winmanager"
  625. let _bufName = expand("#"._bufNbr.":p")
  626. if (a:0 == 1) && (a:1 == "tab")
  627. call WinManagerFileEdit(_bufName, 1)
  628. else
  629. call WinManagerFileEdit(_bufName, 0)
  630. endif
  631. return
  632. endif
  633. endif
  634. if bufexists(_bufNbr)
  635. if bufnr("#") == _bufNbr && !exists("g:bufExplorerChgWin")
  636. return s:Close()
  637. endif
  638. " Are we suppose to open the selected buffer in a tab?
  639. if (a:0 == 1) && (a:1 == "tab")
  640. " Yes, we are to open the selected buffer in a tab.
  641. " Restore [BufExplorer] buffer.
  642. execute "keepjumps silent buffer!".s:originBuffer
  643. " Get the tab nmber where this bufer is located in.
  644. let tabNbr = s:GetTabNbr(_bufNbr)
  645. " Was the tab found?
  646. if tabNbr == 0
  647. " _bufNbr is not opened in any tabs. Open a new tab with the selected buffer in it.
  648. execute "999tab split +buffer" . _bufNbr
  649. else
  650. " The _bufNbr is already opened in a tab, go to that tab.
  651. execute tabNbr . "tabnext"
  652. " Focus window.
  653. execute s:GetWinNbr(tabNbr, _bufNbr) . "wincmd w"
  654. endif
  655. else
  656. " No, the user did not ask to open the selected buffer in a tab.
  657. " Are we suppose to move to the tab where the active buffer is?
  658. if exists("g:bufExplorerChgWin")
  659. execute g:bufExplorerChgWin."wincmd w"
  660. elseif bufloaded(_bufNbr) && g:bufExplorerFindActive
  661. if g:bufExplorerFindActive
  662. call s:Close()
  663. endif
  664. " Get the tab number where this buffer is located in.
  665. let tabNbr = s:GetTabNbr(_bufNbr)
  666. " Was the tab found?
  667. if tabNbr != 0
  668. " Yes, the buffer is located in a tab. Go to that tab number.
  669. execute tabNbr . "tabnext"
  670. else
  671. "Nope, the buffer is not in a tab. Simply switch to that
  672. "buffer.
  673. let _bufName = expand("#"._bufNbr.":p")
  674. execute _bufName ? "drop ".escape(_bufName, " ") : "buffer "._bufNbr
  675. endif
  676. endif
  677. " Switch to the selected buffer.
  678. execute "keepalt keepjumps silent b!" _bufNbr
  679. endif
  680. " Make the buffer 'listed' again.
  681. call setbufvar(_bufNbr, "&buflisted", "1")
  682. " Call any associated function references. g:bufExplorerFuncRef may be
  683. " an individual function reference or it may be a list containing
  684. " function references. It will ignore anything that's not a function
  685. " reference.
  686. "
  687. " See :help FuncRef for more on function references.
  688. if exists("g:BufExplorerFuncRef")
  689. if type(g:BufExplorerFuncRef) == 2
  690. keepj call g:BufExplorerFuncRef()
  691. elseif type(g:BufExplorerFuncRef) == 3
  692. for FncRef in g:BufExplorerFuncRef
  693. if type(FncRef) == 2
  694. keepj call FncRef()
  695. endif
  696. endfor
  697. endif
  698. endif
  699. else
  700. call s:Error("Sorry, that buffer no longer exists, please select another")
  701. call s:DeleteBuffer(_bufNbr, "wipe")
  702. endif
  703. endfunction
  704. " RemoveBuffer {{{2
  705. function! s:RemoveBuffer(mode)
  706. " Are we on a line with a file name?
  707. if line('.') < s:firstBufferLine
  708. return
  709. endif
  710. " Do not allow this buffer to be deleted if it is the last one.
  711. if len(s:MRUList) == 1
  712. call s:Error("Sorry, you are not allowed to delete the last buffer")
  713. return
  714. endif
  715. " These commands are to temporarily suspend the activity of winmanager.
  716. if exists("b:displayMode") && b:displayMode == "winmanager"
  717. call WinManagerSuspendAUs()
  718. end
  719. let _bufNbr = str2nr(getline('.'))
  720. if getbufvar(_bufNbr, '&modified') == 1
  721. call s:Error("Sorry, no write since last change for buffer "._bufNbr.", unable to delete")
  722. return
  723. else
  724. " Okay, everything is good, delete or wipe the buffer.
  725. call s:DeleteBuffer(_bufNbr, a:mode)
  726. endif
  727. " Reactivate winmanager autocommand activity.
  728. if exists("b:displayMode") && b:displayMode == "winmanager"
  729. call WinManagerForceReSize("BufExplorer")
  730. call WinManagerResumeAUs()
  731. end
  732. endfunction
  733. " DeleteBuffer {{{2
  734. function! s:DeleteBuffer(buf, mode)
  735. " This routine assumes that the buffer to be removed is on the current line.
  736. try
  737. " Wipe/Delete buffer from Vim.
  738. if a:mode == "wipe"
  739. execute "silent bwipe" a:buf
  740. else
  741. execute "silent bdelete" a:buf
  742. endif
  743. " Delete the buffer from the list on screen.
  744. setlocal modifiable
  745. normal! "_dd
  746. setlocal nomodifiable
  747. " Delete the buffer from the raw buffer list.
  748. call filter(s:raw_buffer_listing, 'v:val.attributes !~ " '.a:buf.' "')
  749. catch
  750. call s:Error(v:exception)
  751. endtry
  752. endfunction
  753. " Close {{{2
  754. function! s:Close()
  755. " Get only the listed buffers.
  756. let listed = filter(copy(s:MRUList), "buflisted(v:val)")
  757. " If we needed to split the main window, close the split one.
  758. if s:splitMode != "" && bufwinnr(s:originBuffer) != -1
  759. execute "wincmd c"
  760. endif
  761. " Check to see if there are anymore buffers listed.
  762. if len(listed) == 0
  763. " Since there are no buffers left to switch to, open a new empty
  764. " buffers.
  765. execute "enew"
  766. else
  767. " Since there are buffers left to switch to, swith to the previous and
  768. " then the current.
  769. for b in reverse(listed[0:1])
  770. execute "keepjumps silent b ".b
  771. endfor
  772. endif
  773. " Clear any messages.
  774. echo
  775. endfunction
  776. " ToggleSplitOutPathName {{{2
  777. function! s:ToggleSplitOutPathName()
  778. let g:bufExplorerSplitOutPathName = !g:bufExplorerSplitOutPathName
  779. call s:RebuildBufferList()
  780. call s:UpdateHelpStatus()
  781. endfunction
  782. " ToggleShowRelativePath {{{2
  783. function! s:ToggleShowRelativePath()
  784. let g:bufExplorerShowRelativePath = !g:bufExplorerShowRelativePath
  785. call s:RebuildBufferList()
  786. call s:UpdateHelpStatus()
  787. endfunction
  788. " ToggleShowTabBuffer {{{2
  789. function! s:ToggleShowTabBuffer()
  790. let g:bufExplorerShowTabBuffer = !g:bufExplorerShowTabBuffer
  791. call s:RebuildBufferList(g:bufExplorerShowTabBuffer)
  792. call s:UpdateHelpStatus()
  793. endfunction
  794. " ToggleOnlyOneTab {{{2
  795. function! s:ToggleOnlyOneTab()
  796. let g:bufExplorerOnlyOneTab = !g:bufExplorerOnlyOneTab
  797. call s:RebuildBufferList()
  798. call s:UpdateHelpStatus()
  799. endfunction
  800. " ToggleShowUnlisted {{{2
  801. function! s:ToggleShowUnlisted()
  802. let g:bufExplorerShowUnlisted = !g:bufExplorerShowUnlisted
  803. let num_bufs = s:RebuildBufferList(g:bufExplorerShowUnlisted == 0)
  804. call s:UpdateHelpStatus()
  805. endfunction
  806. " ToggleFindActive {{{2
  807. function! s:ToggleFindActive()
  808. let g:bufExplorerFindActive = !g:bufExplorerFindActive
  809. call s:UpdateHelpStatus()
  810. endfunction
  811. " RebuildBufferList {{{2
  812. function! s:RebuildBufferList(...)
  813. setlocal modifiable
  814. let curPos = getpos('.')
  815. if a:0 && a:000[0] && (line('$') >= s:firstBufferLine)
  816. " Clear the list first.
  817. execute "silent keepjumps ".s:firstBufferLine.',$d _'
  818. endif
  819. let num_bufs = s:BuildBufferList()
  820. call setpos('.', curPos)
  821. setlocal nomodifiable
  822. return num_bufs
  823. endfunction
  824. " UpdateHelpStatus {{{2
  825. function! s:UpdateHelpStatus()
  826. setlocal modifiable
  827. let text = s:GetHelpStatus()
  828. call setline(s:firstBufferLine - 2, text)
  829. setlocal nomodifiable
  830. endfunction
  831. " MRUCmp {{{2
  832. function! s:MRUCmp(line1, line2)
  833. return index(s:MRUList, str2nr(a:line1)) - index(s:MRUList, str2nr(a:line2))
  834. endfunction
  835. " SortReverse {{{2
  836. function! s:SortReverse()
  837. let g:bufExplorerReverseSort = !g:bufExplorerReverseSort
  838. call s:ReSortListing()
  839. endfunction
  840. " SortSelect {{{2
  841. function! s:SortSelect()
  842. let g:bufExplorerSortBy = get(s:sort_by, index(s:sort_by, g:bufExplorerSortBy) + 1, s:sort_by[0])
  843. call s:ReSortListing()
  844. endfunction
  845. " ReverseSortSelect {{{2
  846. function! s:ReverseSortSelect()
  847. let g:bufExplorerSortBy = get(s:sort_by, index(s:sort_by, g:bufExplorerSortBy) - 1, s:sort_by[-1])
  848. call s:ReSortListing()
  849. endfunction
  850. " ReSortListing {{{2
  851. function! s:ReSortListing()
  852. setlocal modifiable
  853. let curPos = getpos('.')
  854. call s:SortListing()
  855. call s:UpdateHelpStatus()
  856. call setpos('.', curPos)
  857. setlocal nomodifiable
  858. endfunction
  859. " SortListing {{{2
  860. function! s:SortListing()
  861. let sort = s:firstBufferLine.",$sort".((g:bufExplorerReverseSort == 1) ? "!": "")
  862. if g:bufExplorerSortBy == "number"
  863. " Easiest case.
  864. execute sort 'n'
  865. elseif g:bufExplorerSortBy == "name"
  866. if g:bufExplorerSplitOutPathName
  867. execute sort 'ir /\d.\{7}\zs\f\+\ze/'
  868. else
  869. execute sort 'ir /\zs[^\/\\]\+\ze\s*line/'
  870. endif
  871. elseif g:bufExplorerSortBy == "fullpath"
  872. if g:bufExplorerSplitOutPathName
  873. " Sort twice - first on the file name then on the path.
  874. execute sort 'ir /\d.\{7}\zs\f\+\ze/'
  875. endif
  876. execute sort 'ir /\zs\f\+\ze\s\+line/'
  877. elseif g:bufExplorerSortBy == "extension"
  878. execute sort 'ir /\.\zs\w\+\ze\s/'
  879. elseif g:bufExplorerSortBy == "mru"
  880. let l = getline(s:firstBufferLine, "$")
  881. call sort(l, "<SID>MRUCmp")
  882. if g:bufExplorerReverseSort
  883. call reverse(l)
  884. endif
  885. call setline(s:firstBufferLine, l)
  886. endif
  887. endfunction
  888. " MRUListShow {{{2
  889. function! s:MRUListShow()
  890. echomsg "MRUList=".string(s:MRUList)
  891. endfunction
  892. " Error {{{2
  893. " Display a message using ErrorMsg highlight group.
  894. function! s:Error(msg)
  895. echohl ErrorMsg
  896. echomsg a:msg
  897. echohl None
  898. endfunction
  899. " Warning {{{2
  900. " Display a message using WarningMsg highlight group.
  901. function! s:Warning(msg)
  902. echohl WarningMsg
  903. echomsg a:msg
  904. echohl None
  905. endfunction
  906. " GetTabNbr {{{2
  907. function! s:GetTabNbr(bufNbr)
  908. " Searching buffer bufno, in tabs.
  909. for i in range(tabpagenr("$"))
  910. if index(tabpagebuflist(i + 1), a:bufNbr) != -1
  911. return i + 1
  912. endif
  913. endfor
  914. return 0
  915. endfunction
  916. " GetWinNbr" {{{2
  917. function! s:GetWinNbr(tabNbr, bufNbr)
  918. " window number in tabpage.
  919. let tablist = tabpagebuflist(a:tabNbr)
  920. " Number: 0
  921. " String: 1
  922. " Funcref: 2
  923. " List: 3
  924. " Dictionary: 4
  925. " Float: 5
  926. if type(tablist) == 3
  927. return index(tabpagebuflist(a:tabNbr), a:bufNbr) + 1
  928. else
  929. return 1
  930. endif
  931. endfunction
  932. " StringWidth" {{{2
  933. if exists('*strwidth')
  934. function s:StringWidth(s)
  935. return strwidth(a:s)
  936. endfunction
  937. else
  938. function s:StringWidth(s)
  939. return len(a:s)
  940. endfunction
  941. endif
  942. " Winmanager Integration {{{2
  943. let g:BufExplorer_title = "\[Buf\ List\]"
  944. call s:Set("g:bufExplorerResize", 1)
  945. call s:Set("g:bufExplorerMaxHeight", 25) " Handles dynamic resizing of the window.
  946. " function! to start display. Set the mode to 'winmanager' for this buffer.
  947. " This is to figure out how this plugin was called. In a standalone fashion
  948. " or by winmanager.
  949. function! BufExplorer_Start()
  950. let b:displayMode = "winmanager"
  951. call BufExplorer()
  952. endfunction
  953. " Returns whether the display is okay or not.
  954. function! BufExplorer_IsValid()
  955. return 0
  956. endfunction
  957. " Handles dynamic refreshing of the window.
  958. function! BufExplorer_Refresh()
  959. let b:displayMode = "winmanager"
  960. call BufExplorer()
  961. endfunction
  962. function! BufExplorer_ReSize()
  963. if !g:bufExplorerResize
  964. return
  965. end
  966. let nlines = min([line("$"), g:bufExplorerMaxHeight])
  967. execute nlines." wincmd _"
  968. " The following lines restore the layout so that the last file line is also
  969. " the last window line. Sometimes, when a line is deleted, although the
  970. " window size is exactly equal to the number of lines in the file, some of
  971. " the lines are pushed up and we see some lagging '~'s.
  972. let pres = getpos(".")
  973. normal! $
  974. let _scr = &scrolloff
  975. let &scrolloff = 0
  976. normal! z-
  977. let &scrolloff = _scr
  978. call setpos(".", pres)
  979. endfunction
  980. " Default values {{{1
  981. call s:Set("g:bufExplorerDisableDefaultKeyMapping", 0) " Do not disable default key mappings.
  982. call s:Set("g:bufExplorerDefaultHelp", 1) " Show default help?
  983. call s:Set("g:bufExplorerDetailedHelp", 0) " Show detailed help?
  984. call s:Set("g:bufExplorerFindActive", 1) " When selecting an active buffer, take you to the window where it is active?
  985. call s:Set("g:bufExplorerOnlyOneTab", 1) " If ShowTabBuffer = 1, only store the most recent tab for this buffer.
  986. call s:Set("g:bufExplorerReverseSort", 0) " Sort in reverse order by default?
  987. call s:Set("g:bufExplorerShowDirectories", 1) " (Dir's are added by commands like ':e .')
  988. call s:Set("g:bufExplorerShowRelativePath", 0) " Show listings with relative or absolute paths?
  989. call s:Set("g:bufExplorerShowTabBuffer", 0) " Show only buffer(s) for this tab?
  990. call s:Set("g:bufExplorerShowUnlisted", 0) " Show unlisted buffers?
  991. call s:Set("g:bufExplorerShowNoName", 0) " Show 'No Name' buffers?
  992. call s:Set("g:bufExplorerSortBy", "mru") " Sorting methods are in s:sort_by:
  993. call s:Set("g:bufExplorerSplitBelow", &splitbelow) " Should horizontal splits be below or above current window?
  994. call s:Set("g:bufExplorerSplitOutPathName", 1) " Split out path and file name?
  995. call s:Set("g:bufExplorerSplitRight", &splitright) " Should vertical splits be on the right or left of current window?
  996. call s:Set("g:bufExplorerSplitVertSize", 0) " Height for a vertical split. If <=0, default Vim size is used.
  997. call s:Set("g:bufExplorerSplitHorzSize", 0) " Height for a horizontal split. If <=0, default Vim size is used.
  998. "1}}}
  999. " Default key mapping {{{1
  1000. if !hasmapto('BufExplorer') && g:bufExplorerDisableDefaultKeyMapping == 0
  1001. nnoremap <script> <silent> <unique> <Leader>be :BufExplorer<CR>
  1002. endif
  1003. if !hasmapto('BufExplorerHorizontalSplit') && g:bufExplorerDisableDefaultKeyMapping == 0
  1004. nnoremap <script> <silent> <unique> <Leader>bs :BufExplorerHorizontalSplit<CR>
  1005. endif
  1006. if !hasmapto('BufExplorerVerticalSplit') && g:bufExplorerDisableDefaultKeyMapping == 0
  1007. nnoremap <script> <silent> <unique> <Leader>bv :BufExplorerVerticalSplit<CR>
  1008. endif
  1009. " vim:ft=vim foldmethod=marker sw=4