bufexplorer.vim 40 KB

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