bufexplorer.vim 40 KB

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