bufexplorer.vim 40 KB

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