diff --git a/autoload/airline/extensions/tabline/formatters.vim b/autoload/airline/extensions/tabline/formatters.vim index 9485bb3c..656ba225 100644 --- a/autoload/airline/extensions/tabline/formatters.vim +++ b/autoload/airline/extensions/tabline/formatters.vim @@ -10,10 +10,6 @@ let s:buf_modified_symbol = g:airline_symbols.modified function! airline#extensions#tabline#formatters#default(bufnr, buffers) let _ = '' - if s:buf_nr_show - let _ .= printf(s:buf_nr_format, a:bufnr) - endif - let name = bufname(a:bufnr) if empty(name) let _ .= '[No Name]' @@ -25,10 +21,40 @@ function! airline#extensions#tabline#formatters#default(bufnr, buffers) endif endif + return s:wrap_name(a:bufnr, _) +endfunction + +function! airline#extensions#tabline#formatters#unique_tail(bufnr, buffers) + let duplicates = {} + let tails = {} + let map = {} + for nr in a:buffers + let name = bufname(nr) + if empty(name) + let map[nr] = '[No Name]' + else + let tail = fnamemodify(name, ':t') + if has_key(tails, tail) + let duplicates[nr] = nr + endif + let tails[tail] = 1 + let map[nr] = s:wrap_name(nr, tail) + endif + endfor + + for nr in values(duplicates) + let map[nr] = s:wrap_name(nr, fnamemodify(bufname(nr), ':p:.')) + endfor + + return map[a:bufnr] +endfunction + +function! s:wrap_name(bufnr, buffer_name) + let _ = s:buf_nr_show ? printf(s:buf_nr_format, a:bufnr) : '' + let _ .= a:buffer_name if getbufvar(a:bufnr, '&modified') == 1 let _ .= s:buf_modified_symbol endif - return _ endfunction diff --git a/doc/airline.txt b/doc/airline.txt index 67afa03b..d8566d45 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -386,6 +386,11 @@ eclim < * configure collapsing parent directories in buffer name. > let g:airline#extensions#tabline#fnamecollapse = 1 + + " The `unique_tail` algorithm will display the tail of the filename, unless + " there is another file of the same name, in which it will display it along + " with the containing parent directory. + let g:airline#extensions#tabline#formatter = 'unique_tail' < * configure the minimum number of buffers needed to show the tabline. > let g:airline#extensions#tabline#buffer_min_count = 0