bufexplorer.vim 40 KB

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