bufexplorer.vim 40 KB

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