bufexplorer.vim 40 KB

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