bufexplorer.vim 41 KB

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