collapse fname in tabline when using unique_tail formatter

This commit is contained in:
Shohei Fujii 2017-10-18 09:16:26 +09:00
parent a1b7479b54
commit b044b4b204
2 changed files with 14 additions and 2 deletions

View File

@ -21,8 +21,14 @@ function! airline#extensions#tabline#formatters#unique_tail#format(bufnr, buffer
endif
endfor
let fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':p:.')
for nr in values(duplicates)
let map[nr] = airline#extensions#tabline#formatters#default#wrap_name(nr, fnamemodify(bufname(nr), ':p:.'))
let fnamecollapse = get(g:, 'airline#extensions#tabline#fnamecollapse', 1)
if fnamecollapse
let map[nr] = airline#extensions#tabline#formatters#default#wrap_name(nr, substitute(fnamemodify(name, fmod), '\v\w\zs.{-}\ze(\\|/)', '', 'g'))
else
let map[nr] = airline#extensions#tabline#formatters#default#wrap_name(nr, fnamemodify(bufname(nr), fmod))
endif
endfor
if has_key(map, a:bufnr)

View File

@ -741,7 +741,7 @@ with the middle mouse button to delete that buffer.
let g:airline#extensions#tabline#formatter = 'foo'
<
Note: the following variables are only used by the 'default' formatter.
Note: the following variables are used by the 'default' formatter.
When no disambiguation is needed, both 'unique_tail_improved' and
'unique_tail' delegate formatting to 'default', so these variables also
control rendering of unique filenames when using these formatters.
@ -766,6 +766,12 @@ with the middle mouse button to delete that buffer.
" with the containing parent directory.
let g:airline#extensions#tabline#formatter = 'unique_tail'
" The following variables are also used by `unique_tail` formatter.
" the meanings are the same as the ones in default formatter.
let g:airline#extensions#tabline#fnamemod = ':p:.'
let g:airline#extensions#tabline#fnamecollapse = 1
" The `unique_tail_improved` - another algorithm, that will smartly uniquify
" buffers names with similar filename, suppressing common parts of paths.
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'