Skip to content

Instantly share code, notes, and snippets.

@mopp
Last active August 29, 2015 13:57
Show Gist options
  • Save mopp/9528841 to your computer and use it in GitHub Desktop.
Save mopp/9528841 to your computer and use it in GitHub Desktop.
" わかりやすくするために最低限だけ書いています.
" 皆さんの設定に真似して組み込んでください.
let g:lightline = {
\ 'active' : {
\ 'left' : [ [ 'mode', 'paste' ], [ 'filename', 'modified' ], [ 'readonly' ], [ 'buflist' ] ],
\ 'right' : [ [ 'fileencoding', 'fileformat', 'lineinfo', 'percent' ], [ 'filetype' ] ],
\ },
\ 'component_function' : {
\ 'buflist' : 'Mline_buflist',
\ },
\ }
let g:mline_bufhist_queue = []
" 表示数
let g:mline_bufhist_limit = 4
" 除外パターン
let g:mline_bufhist_exclution_pat = '^$\|.jax$\|vimfiler:\|\[unite\]\|tagbar'
" 表示非表示切り替え
let g:mline_bufhist_enable = 1
command! Btoggle :let g:mline_bufhist_enable = g:mline_bufhist_enable ? 0 : 1 | :redrawstatus!
function! Mline_bufhist()
if &filetype =~? 'unite\|vimfiler\|tagbar' || !&modifiable || len(g:mline_bufhist_queue) == 0 || g:mline_bufhist_enable == 0
return ''
endif
let current_buf_nr = bufnr('%')
let buf_names_str = ''
let last = g:mline_bufhist_queue[-1]
for i in g:mline_bufhist_queue
let t = fnamemodify(i, ':t')
let n = bufnr(t)
if n != current_buf_nr
let buf_names_str .= printf('[%d]:%s' . (i == last ? '' : ' | '), n, t)
endif
endfor
return buf_names_str
endfunction
function! s:update_recent_buflist(file)
if a:file =~? g:mline_bufhist_exclution_pat
" exclusion from queue
return
endif
if len(g:mline_bufhist_queue) == 0
" init
for i in range(min( [ bufnr('$'), g:mline_bufhist_limit + 1 ] ))
let t = bufname(i)
if bufexists(i) && t !~? g:mline_bufhist_exclution_pat
call add(g:mline_bufhist_queue, fnamemodify(t, ':p'))
endif
endfor
endif
" update exist buffer
let idx = index(g:mline_bufhist_queue, a:file)
if 0 <= idx
call remove(g:mline_bufhist_queue, idx)
endif
call insert(g:mline_bufhist_queue, a:file)
if g:mline_bufhist_limit + 1 < len(g:mline_bufhist_queue)
call remove(g:mline_bufhist_queue, -1)
endif
endfunction
augroup general
autocmd!
autocmd TabEnter,BufWinEnter * call s:update_recent_buflist(expand('<amatch>'))
augroup END
@tueda
Copy link

tueda commented Jul 26, 2014

s/Mline_buflist/Mline_bufhist/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment