bufexplorer.vim 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  1. "=============================================================================
  2. " Copyright: Copyright (c) 2001-2013, 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: Tuesday, 22 October 2013
  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. " noremap <silent> <F11> :BufExplorer<CR>
  54. " noremap <silent> <m-F11> :BufExplorerHorizontalSplit<CR>
  55. " noremap <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.2"
  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. 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. hi def link bufExplorerBufNbr Number
  414. hi def link bufExplorerMapping NonText
  415. hi def link bufExplorerHelp Special
  416. hi def link bufExplorerOpenIn Identifier
  417. hi def link bufExplorerSortBy String
  418. hi def link bufExplorerSplit NonText
  419. hi def link bufExplorerTitle NonText
  420. hi def link bufExplorerSortType bufExplorerSortBy
  421. hi def link bufExplorerToggleSplit bufExplorerSplit
  422. hi def link bufExplorerToggleOpen bufExplorerOpenIn
  423. hi def link bufExplorerActBuf Identifier
  424. hi def link bufExplorerAltBuf String
  425. hi def link bufExplorerCurBuf Type
  426. hi def link bufExplorerHidBuf Constant
  427. hi def link bufExplorerLockedBuf Special
  428. hi def link bufExplorerModBuf Exception
  429. hi def link bufExplorerUnlBuf Comment
  430. endif
  431. endfunction
  432. " ToggleHelp {{{2
  433. function! s:ToggleHelp()
  434. let g:bufExplorerDetailedHelp = !g:bufExplorerDetailedHelp
  435. setlocal modifiable
  436. " Save position.
  437. normal! ma
  438. " Remove old header.
  439. if s:firstBufferLine > 1
  440. execute "keepjumps 1,".(s:firstBufferLine - 1) "d _"
  441. endif
  442. call append(0, s:CreateHelp())
  443. silent! normal! g`a
  444. delmarks a
  445. setlocal nomodifiable
  446. if exists("b:displayMode") && b:displayMode == "winmanager"
  447. call WinManagerForceReSize("BufExplorer")
  448. endif
  449. endfunction
  450. " GetHelpStatus {{{2
  451. function! s:GetHelpStatus()
  452. let ret = '" Sorted by '.((g:bufExplorerReverseSort == 1) ? "reverse " : "").g:bufExplorerSortBy
  453. let ret .= ' | '.((g:bufExplorerFindActive == 0) ? "Don't " : "")."Locate buffer"
  454. let ret .= ((g:bufExplorerShowUnlisted == 0) ? "" : " | Show unlisted")
  455. let ret .= ((g:bufExplorerShowTabBuffer == 0) ? "" : " | Show buffers/tab")
  456. let ret .= ((g:bufExplorerOnlyOneTab == 0) ? "" : " | One tab/buffer")
  457. let ret .= ' | '.((g:bufExplorerShowRelativePath == 0) ? "Absolute" : "Relative")
  458. let ret .= ' '.((g:bufExplorerSplitOutPathName == 0) ? "Full" : "Split")." path"
  459. return ret
  460. endfunction
  461. " CreateHelp {{{2
  462. function! s:CreateHelp()
  463. if g:bufExplorerDefaultHelp == 0 && g:bufExplorerDetailedHelp == 0
  464. let s:firstBufferLine = 1
  465. return []
  466. endif
  467. let header = []
  468. if g:bufExplorerDetailedHelp == 1
  469. call add(header, '" Buffer Explorer ('.g:bufexplorer_version.')')
  470. call add(header, '" --------------------------')
  471. call add(header, '" <F1> : toggle this help')
  472. call add(header, '" <enter> or o or Mouse-Double-Click : open buffer under cursor')
  473. call add(header, '" <shift-enter> or t : open buffer in another tab')
  474. call add(header, '" B : toggle if to save/use recent tab or not')
  475. call add(header, '" d : delete buffer')
  476. call add(header, '" D : wipe buffer')
  477. call add(header, '" f : toggle find active buffer')
  478. call add(header, '" p : toggle spliting of file and path name')
  479. call add(header, '" q : quit')
  480. call add(header, '" r : reverse sort')
  481. call add(header, '" R : toggle showing relative or full paths')
  482. call add(header, '" s : cycle thru "sort by" fields '.string(s:sort_by).'')
  483. call add(header, '" S : reverse cycle thru "sort by" fields')
  484. call add(header, '" T : toggle if to show only buffers for this tab or not')
  485. call add(header, '" u : toggle showing unlisted buffers')
  486. else
  487. call add(header, '" Press <F1> for Help')
  488. endif
  489. if (!exists("b:displayMode") || b:displayMode != "winmanager") || (b:displayMode == "winmanager" && g:bufExplorerDetailedHelp == 1)
  490. call add(header, s:GetHelpStatus())
  491. call add(header, '"=')
  492. endif
  493. let s:firstBufferLine = len(header) + 1
  494. return header
  495. endfunction
  496. " GetBufferInfo {{{2
  497. function! s:GetBufferInfo(bufnr)
  498. redir => bufoutput
  499. " Show all buffers including the unlisted ones. [!] tells Vim to show the
  500. " unlisted ones.
  501. buffers!
  502. redir END
  503. if a:bufnr > 0
  504. " Since we are only interested in this specified buffer
  505. " remove the other buffers listed
  506. let bufoutput = substitute(bufoutput."\n", '^.*\n\(\s*'.a:bufnr.'\>.\{-}\)\n.*', '\1', '')
  507. endif
  508. let [all, allwidths, listedwidths] = [[], {}, {}]
  509. for n in keys(s:types)
  510. let allwidths[n] = []
  511. let listedwidths[n] = []
  512. endfor
  513. " Loop over each line in the buffer.
  514. for buf in split(bufoutput, '\n')
  515. let bits = split(buf, '"')
  516. " Use first and last components after the split on '"', in case a
  517. " filename with an embedded '"' is present.
  518. let b = {"attributes": bits[0], "line": substitute(bits[-1], '\s*', '', '')}
  519. let name = bufname(str2nr(b.attributes))
  520. let b["hasNoName"] = empty(name)
  521. if b.hasNoName
  522. let name = "[No Name]"
  523. endif
  524. for [key, val] in items(s:types)
  525. let b[key] = fnamemodify(name, val)
  526. endfor
  527. if getftype(b.fullname) == "dir" && g:bufExplorerShowDirectories == 1
  528. let b.shortname = "<DIRECTORY>"
  529. endif
  530. call add(all, b)
  531. for n in keys(s:types)
  532. call add(allwidths[n], s:StringWidth(b[n]))
  533. if b.attributes !~ "u"
  534. call add(listedwidths[n], s:StringWidth(b[n]))
  535. endif
  536. endfor
  537. endfor
  538. let [s:allpads, s:listedpads] = [{}, {}]
  539. for n in keys(s:types)
  540. let s:allpads[n] = repeat(' ', max(allwidths[n]))
  541. let s:listedpads[n] = repeat(' ', max(listedwidths[n]))
  542. endfor
  543. return all
  544. endfunction
  545. " BuildBufferList {{{2
  546. function! s:BuildBufferList()
  547. let lines = []
  548. " Loop through every buffer.
  549. for buf in s:raw_buffer_listing
  550. " Skip unlisted buffers if we are not to show them.
  551. if !g:bufExplorerShowUnlisted && buf.attributes =~ "u"
  552. " Skip unlisted buffers if we are not to show them.
  553. continue
  554. endif
  555. " Skip "No Name" buffers if we are not to show them.
  556. if g:bufExplorerShowNoName == 0 && buf.hasNoName
  557. continue
  558. endif
  559. " Are we to show only buffer(s) for this tab?
  560. if g:bufExplorerShowTabBuffer
  561. let show_buffer = 0
  562. for bufnr in s:tabSpace[tabpagenr()]
  563. if buf.attributes =~ '^\s*'.bufnr.'\>'
  564. " Only buffers shown on the current tabpagenr
  565. let show_buffer = 1
  566. break
  567. endif
  568. endfor
  569. if show_buffer == 0
  570. continue
  571. endif
  572. endif
  573. let line = buf.attributes." "
  574. " Are we to split the path and file name?
  575. if g:bufExplorerSplitOutPathName
  576. let type = (g:bufExplorerShowRelativePath) ? "relativepath" : "path"
  577. let path = buf[type]
  578. let pad = (g:bufExplorerShowUnlisted) ? s:allpads.shortname : s:listedpads.shortname
  579. let line .= buf.shortname." ".strpart(pad.path, s:StringWidth(buf.shortname))
  580. else
  581. let type = (g:bufExplorerShowRelativePath) ? "relativename" : "fullname"
  582. let path = buf[type]
  583. let line .= path
  584. endif
  585. let pads = (g:bufExplorerShowUnlisted) ? s:allpads : s:listedpads
  586. if !empty(pads[type])
  587. let line .= strpart(pads[type], s:StringWidth(path))." "
  588. endif
  589. let line .= buf.line
  590. call add(lines, line)
  591. endfor
  592. call setline(s:firstBufferLine, lines)
  593. call s:SortListing()
  594. endfunction
  595. " SelectBuffer {{{2
  596. function! s:SelectBuffer(...)
  597. " Sometimes messages are not cleared when we get here so it looks like an
  598. " error has occurred when it really has not.
  599. "echo ""
  600. let _bufNbr = -1
  601. if (a:0 == 1) && (a:1 == "ask")
  602. " Ask the user for input.
  603. call inputsave()
  604. let cmd = input("Enter buffer number to switch to: ")
  605. call inputrestore()
  606. " Clear the message area from the previous prompt.
  607. redraw | echo
  608. if strlen(cmd) > 0
  609. let _bufNbr = str2nr(cmd)
  610. else
  611. call s:Error("Invalid buffer number, try again.")
  612. return
  613. endif
  614. else
  615. " Are we on a line with a file name?
  616. if line('.') < s:firstBufferLine
  617. execute "normal! \<CR>"
  618. return
  619. endif
  620. let _bufNbr = str2nr(getline('.'))
  621. " Check and see if we are running BufferExplorer via WinManager.
  622. if exists("b:displayMode") && b:displayMode == "winmanager"
  623. let _bufName = expand("#"._bufNbr.":p")
  624. if (a:0 == 1) && (a:1 == "tab")
  625. call WinManagerFileEdit(_bufName, 1)
  626. else
  627. call WinManagerFileEdit(_bufName, 0)
  628. endif
  629. return
  630. endif
  631. endif
  632. if bufexists(_bufNbr)
  633. if bufnr("#") == _bufNbr && !exists("g:bufExplorerChgWin")
  634. return s:Close()
  635. endif
  636. " Are we suppose to open the selected buffer in a tab?
  637. if (a:0 == 1) && (a:1 == "tab")
  638. " Yes, we are to open the selected buffer in a tab.
  639. " Restore [BufExplorer] buffer.
  640. execute "keepjumps silent buffer!".s:originBuffer
  641. " Get the tab nmber where this bufer is located in.
  642. let tabNbr = s:GetTabNbr(_bufNbr)
  643. " Was the tab found?
  644. if tabNbr == 0
  645. " _bufNbr is not opened in any tabs. Open a new tab with the selected buffer in it.
  646. execute "999tab split +buffer" . _bufNbr
  647. else
  648. " The _bufNbr is already opened in a tab, go to that tab.
  649. execute tabNbr . "tabnext"
  650. " Focus window.
  651. execute s:GetWinNbr(tabNbr, _bufNbr) . "wincmd w"
  652. endif
  653. else
  654. " No, the user did not ask to open the selected buffer in a tab.
  655. " Are we suppose to move to the tab where the active buffer is?
  656. if exists("g:bufExplorerChgWin")
  657. execute g:bufExplorerChgWin."wincmd w"
  658. elseif bufloaded(_bufNbr) && g:bufExplorerFindActive
  659. if g:bufExplorerFindActive
  660. call s:Close()
  661. endif
  662. " Get the tab number where this buffer is located in.
  663. let tabNbr = s:GetTabNbr(_bufNbr)
  664. " Was the tab found?
  665. if tabNbr != 0
  666. " Yes, the buffer is located in a tab. Go to that tab number.
  667. execute tabNbr . "tabnext"
  668. else
  669. "Nope, the buffer is not in a tab. Simply switch to that
  670. "buffer.
  671. let _bufName = expand("#"._bufNbr.":p")
  672. execute _bufName ? "drop ".escape(_bufName, " ") : "buffer "._bufNbr
  673. endif
  674. endif
  675. " Switch to the selected buffer.
  676. execute "keepalt keepjumps silent b!" _bufNbr
  677. endif
  678. " Make the buffer 'listed' again.
  679. call setbufvar(_bufNbr, "&buflisted", "1")
  680. " Call any associated function references. g:bufExplorerFuncRef may be
  681. " an individual function reference or it may be a list containing
  682. " function references. It will ignore anything that's not a function
  683. " reference.
  684. "
  685. " See :help FuncRef for more on function references.
  686. if exists("g:BufExplorerFuncRef")
  687. if type(g:BufExplorerFuncRef) == 2
  688. keepj call g:BufExplorerFuncRef()
  689. elseif type(g:BufExplorerFuncRef) == 3
  690. for FncRef in g:BufExplorerFuncRef
  691. if type(FncRef) == 2
  692. keepj call FncRef()
  693. endif
  694. endfor
  695. endif
  696. endif
  697. else
  698. call s:Error("Sorry, that buffer no longer exists, please select another")
  699. call s:DeleteBuffer(_bufNbr, "wipe")
  700. endif
  701. endfunction
  702. " RemoveBuffer {{{2
  703. function! s:RemoveBuffer(mode)
  704. " Are we on a line with a file name?
  705. if line('.') < s:firstBufferLine
  706. return
  707. endif
  708. " Do not allow this buffer to be deleted if it is the last one.
  709. if len(s:MRUList) == 1
  710. call s:Error("Sorry, you are not allowed to delete the last buffer")
  711. return
  712. endif
  713. " These commands are to temporarily suspend the activity of winmanager.
  714. if exists("b:displayMode") && b:displayMode == "winmanager"
  715. call WinManagerSuspendAUs()
  716. end
  717. let _bufNbr = str2nr(getline('.'))
  718. if getbufvar(_bufNbr, '&modified') == 1
  719. call s:Error("Sorry, no write since last change for buffer "._bufNbr.", unable to delete")
  720. return
  721. else
  722. " Okay, everything is good, delete or wipe the buffer.
  723. call s:DeleteBuffer(_bufNbr, a:mode)
  724. endif
  725. " Reactivate winmanager autocommand activity.
  726. if exists("b:displayMode") && b:displayMode == "winmanager"
  727. call WinManagerForceReSize("BufExplorer")
  728. call WinManagerResumeAUs()
  729. end
  730. endfunction
  731. " DeleteBuffer {{{2
  732. function! s:DeleteBuffer(buf, mode)
  733. " This routine assumes that the buffer to be removed is on the current line.
  734. try
  735. " Wipe/Delete buffer from Vim.
  736. if a:mode == "wipe"
  737. execute "silent bwipe" a:buf
  738. else
  739. execute "silent bdelete" a:buf
  740. endif
  741. " Delete the buffer from the list on screen.
  742. setlocal modifiable
  743. normal! "_dd
  744. setlocal nomodifiable
  745. " Delete the buffer from the raw buffer list.
  746. call filter(s:raw_buffer_listing, 'v:val.attributes !~ " '.a:buf.' "')
  747. catch
  748. call s:Error(v:exception)
  749. endtry
  750. endfunction
  751. " Close {{{2
  752. function! s:Close()
  753. " Get only the listed buffers.
  754. let listed = filter(copy(s:MRUList), "buflisted(v:val)")
  755. " If we needed to split the main window, close the split one.
  756. if s:splitMode != ""
  757. execute "wincmd c"
  758. endif
  759. " Check to see if there are anymore buffers listed.
  760. if len(listed) == 0
  761. " Since there are no buffers left to switch to, open a new empty
  762. " buffers.
  763. execute "enew"
  764. else
  765. " Since there are buffers left to switch to, swith to the previous and
  766. " then the current.
  767. for b in reverse(listed[0:1])
  768. execute "keepjumps silent b ".b
  769. endfor
  770. endif
  771. " Clear any messages.
  772. echo
  773. endfunction
  774. " ToggleSplitOutPathName {{{2
  775. function! s:ToggleSplitOutPathName()
  776. let g:bufExplorerSplitOutPathName = !g:bufExplorerSplitOutPathName
  777. call s:RebuildBufferList()
  778. call s:UpdateHelpStatus()
  779. endfunction
  780. " ToggleShowRelativePath {{{2
  781. function! s:ToggleShowRelativePath()
  782. let g:bufExplorerShowRelativePath = !g:bufExplorerShowRelativePath
  783. call s:RebuildBufferList()
  784. call s:UpdateHelpStatus()
  785. endfunction
  786. " ToggleShowTabBuffer {{{2
  787. function! s:ToggleShowTabBuffer()
  788. let g:bufExplorerShowTabBuffer = !g:bufExplorerShowTabBuffer
  789. call s:RebuildBufferList(g:bufExplorerShowTabBuffer)
  790. call s:UpdateHelpStatus()
  791. endfunction
  792. " ToggleOnlyOneTab {{{2
  793. function! s:ToggleOnlyOneTab()
  794. let g:bufExplorerOnlyOneTab = !g:bufExplorerOnlyOneTab
  795. call s:RebuildBufferList()
  796. call s:UpdateHelpStatus()
  797. endfunction
  798. " ToggleShowUnlisted {{{2
  799. function! s:ToggleShowUnlisted()
  800. let g:bufExplorerShowUnlisted = !g:bufExplorerShowUnlisted
  801. let num_bufs = s:RebuildBufferList(g:bufExplorerShowUnlisted == 0)
  802. call s:UpdateHelpStatus()
  803. endfunction
  804. " ToggleFindActive {{{2
  805. function! s:ToggleFindActive()
  806. let g:bufExplorerFindActive = !g:bufExplorerFindActive
  807. call s:UpdateHelpStatus()
  808. endfunction
  809. " RebuildBufferList {{{2
  810. function! s:RebuildBufferList(...)
  811. setlocal modifiable
  812. let curPos = getpos('.')
  813. if a:0 && a:000[0] && (line('$') >= s:firstBufferLine)
  814. " Clear the list first.
  815. execute "keepjumps ".s:firstBufferLine.',$d _'
  816. endif
  817. let num_bufs = s:BuildBufferList()
  818. call setpos('.', curPos)
  819. setlocal nomodifiable
  820. return num_bufs
  821. endfunction
  822. " UpdateHelpStatus {{{2
  823. function! s:UpdateHelpStatus()
  824. setlocal modifiable
  825. let text = s:GetHelpStatus()
  826. call setline(s:firstBufferLine - 2, text)
  827. setlocal nomodifiable
  828. endfunction
  829. " MRUCmp {{{2
  830. function! s:MRUCmp(line1, line2)
  831. return index(s:MRUList, str2nr(a:line1)) - index(s:MRUList, str2nr(a:line2))
  832. endfunction
  833. " SortReverse {{{2
  834. function! s:SortReverse()
  835. let g:bufExplorerReverseSort = !g:bufExplorerReverseSort
  836. call s:ReSortListing()
  837. endfunction
  838. " SortSelect {{{2
  839. function! s:SortSelect()
  840. let g:bufExplorerSortBy = get(s:sort_by, index(s:sort_by, g:bufExplorerSortBy) + 1, s:sort_by[0])
  841. call s:ReSortListing()
  842. endfunction
  843. " ReverseSortSelect {{{2
  844. function! s:ReverseSortSelect()
  845. let g:bufExplorerSortBy = get(s:sort_by, index(s:sort_by, g:bufExplorerSortBy) - 1, s:sort_by[-1])
  846. call s:ReSortListing()
  847. endfunction
  848. " ReSortListing {{{2
  849. function! s:ReSortListing()
  850. setlocal modifiable
  851. let curPos = getpos('.')
  852. call s:SortListing()
  853. call s:UpdateHelpStatus()
  854. call setpos('.', curPos)
  855. setlocal nomodifiable
  856. endfunction
  857. " SortListing {{{2
  858. function! s:SortListing()
  859. let sort = s:firstBufferLine.",$sort".((g:bufExplorerReverseSort == 1) ? "!": "")
  860. if g:bufExplorerSortBy == "number"
  861. " Easiest case.
  862. execute sort 'n'
  863. elseif g:bufExplorerSortBy == "name"
  864. if g:bufExplorerSplitOutPathName
  865. execute sort 'ir /\d.\{7}\zs\f\+\ze/'
  866. else
  867. execute sort 'ir /\zs[^\/\\]\+\ze\s*line/'
  868. endif
  869. elseif g:bufExplorerSortBy == "fullpath"
  870. if g:bufExplorerSplitOutPathName
  871. " Sort twice - first on the file name then on the path.
  872. execute sort 'ir /\d.\{7}\zs\f\+\ze/'
  873. endif
  874. execute sort 'ir /\zs\f\+\ze\s\+line/'
  875. elseif g:bufExplorerSortBy == "extension"
  876. execute sort 'ir /\.\zs\w\+\ze\s/'
  877. elseif g:bufExplorerSortBy == "mru"
  878. let l = getline(s:firstBufferLine, "$")
  879. call sort(l, "<SID>MRUCmp")
  880. if g:bufExplorerReverseSort
  881. call reverse(l)
  882. endif
  883. call setline(s:firstBufferLine, l)
  884. endif
  885. endfunction
  886. " MRUListShow {{{2
  887. function! s:MRUListShow()
  888. echomsg "MRUList=".string(s:MRUList)
  889. endfunction
  890. " Error {{{2
  891. " Display a message using ErrorMsg highlight group.
  892. function! s:Error(msg)
  893. echohl ErrorMsg
  894. echomsg a:msg
  895. echohl None
  896. endfunction
  897. " Warning {{{2
  898. " Display a message using WarningMsg highlight group.
  899. function! s:Warning(msg)
  900. echohl WarningMsg
  901. echomsg a:msg
  902. echohl None
  903. endfunction
  904. " GetTabNbr {{{2
  905. function! s:GetTabNbr(bufNbr)
  906. " Searching buffer bufno, in tabs.
  907. for i in range(tabpagenr("$"))
  908. if index(tabpagebuflist(i + 1), a:bufNbr) != -1
  909. return i + 1
  910. endif
  911. endfor
  912. return 0
  913. endfunction
  914. " GetWinNbr" {{{2
  915. function! s:GetWinNbr(tabNbr, bufNbr)
  916. " window number in tabpage.
  917. let tablist = tabpagebuflist(a:tabNbr)
  918. " Number: 0
  919. " String: 1
  920. " Funcref: 2
  921. " List: 3
  922. " Dictionary: 4
  923. " Float: 5
  924. if type(tablist) == 3
  925. return index(tabpagebuflist(a:tabNbr), a:bufNbr) + 1
  926. else
  927. return 1
  928. endif
  929. endfunction
  930. " StringWidth" {{{2
  931. if exists('*strwidth')
  932. function s:StringWidth(s)
  933. return strwidth(a:s)
  934. endfunction
  935. else
  936. function s:StringWidth(s)
  937. return len(a:s)
  938. endfunction
  939. endif
  940. " Winmanager Integration {{{2
  941. let g:BufExplorer_title = "\[Buf\ List\]"
  942. call s:Set("g:bufExplorerResize", 1)
  943. call s:Set("g:bufExplorerMaxHeight", 25) " Handles dynamic resizing of the window.
  944. " function! to start display. Set the mode to 'winmanager' for this buffer.
  945. " This is to figure out how this plugin was called. In a standalone fashion
  946. " or by winmanager.
  947. function! BufExplorer_Start()
  948. let b:displayMode = "winmanager"
  949. call BufExplorer()
  950. endfunction
  951. " Returns whether the display is okay or not.
  952. function! BufExplorer_IsValid()
  953. return 0
  954. endfunction
  955. " Handles dynamic refreshing of the window.
  956. function! BufExplorer_Refresh()
  957. let b:displayMode = "winmanager"
  958. call BufExplorer()
  959. endfunction
  960. function! BufExplorer_ReSize()
  961. if !g:bufExplorerResize
  962. return
  963. end
  964. let nlines = min([line("$"), g:bufExplorerMaxHeight])
  965. execute nlines." wincmd _"
  966. " The following lines restore the layout so that the last file line is also
  967. " the last window line. Sometimes, when a line is deleted, although the
  968. " window size is exactly equal to the number of lines in the file, some of
  969. " the lines are pushed up and we see some lagging '~'s.
  970. let pres = getpos(".")
  971. execute $
  972. let _scr = &scrolloff
  973. let &scrolloff = 0
  974. normal! z-
  975. let &scrolloff = _scr
  976. call setpos(".", pres)
  977. endfunction
  978. " Default values {{{1
  979. call s:Set("g:bufExplorerDisableDefaultKeyMapping", 0) " Do not disable default key mappings.
  980. call s:Set("g:bufExplorerDefaultHelp", 1) " Show default help?
  981. call s:Set("g:bufExplorerDetailedHelp", 0) " Show detailed help?
  982. call s:Set("g:bufExplorerFindActive", 1) " When selecting an active buffer, take you to the window where it is active?
  983. call s:Set("g:bufExplorerOnlyOneTab", 1) " If ShowTabBuffer = 1, only store the most recent tab for this buffer.
  984. call s:Set("g:bufExplorerReverseSort", 0) " Sort in reverse order by default?
  985. call s:Set("g:bufExplorerShowDirectories", 1) " (Dir's are added by commands like ':e .')
  986. call s:Set("g:bufExplorerShowRelativePath", 0) " Show listings with relative or absolute paths?
  987. call s:Set("g:bufExplorerShowTabBuffer", 0) " Show only buffer(s) for this tab?
  988. call s:Set("g:bufExplorerShowUnlisted", 0) " Show unlisted buffers?
  989. call s:Set("g:bufExplorerShowNoName", 0) " Show "No Name" buffers?
  990. call s:Set("g:bufExplorerSortBy", "mru") " Sorting methods are in s:sort_by:
  991. call s:Set("g:bufExplorerSplitBelow", &splitbelow) " Should horizontal splits be below or above current window?
  992. call s:Set("g:bufExplorerSplitOutPathName", 1) " Split out path and file name?
  993. call s:Set("g:bufExplorerSplitRight", &splitright) " Should vertical splits be on the right or left of current window?
  994. call s:Set("g:bufExplorerSplitVertSize", 0) " Height for a vertical split. If <=0, default Vim size is used.
  995. call s:Set("g:bufExplorerSplitHorzSize", 0) " Height for a horizontal split. If <=0, default Vim size is used.
  996. "1}}}
  997. " Default key mapping {{{1
  998. if !hasmapto('BufExplorer') && g:bufExplorerDisableDefaultKeyMapping == 0
  999. noremap <script> <silent> <unique> <Leader>be :BufExplorer<CR>
  1000. endif
  1001. if !hasmapto('BufExplorerHorizontalSplit') && g:bufExplorerDisableDefaultKeyMapping == 0
  1002. noremap <script> <silent> <unique> <Leader>bs :BufExplorerHorizontalSplit<CR>
  1003. endif
  1004. if !hasmapto('BufExplorerVerticalSplit') && g:bufExplorerDisableDefaultKeyMapping == 0
  1005. noremap <script> <silent> <unique> <Leader>bv :BufExplorerVerticalSplit<CR>
  1006. endif
  1007. " vim:ft=vim foldmethod=marker sw=4