bufexplorer.vim 40 KB

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