mirror of
https://github.com/vim-airline/vim-airline.git
synced 2024-11-22 13:26:46 +08:00
Add improved short path tabline formatter
This commit is contained in:
parent
1ecbc76682
commit
9eb4aa47a3
|
@ -3,8 +3,6 @@
|
|||
|
||||
scriptencoding utf-8
|
||||
|
||||
let s:fnamecollapse = get(g:, 'airline#extensions#tabline#fnamecollapse', 1)
|
||||
|
||||
function! airline#extensions#tabline#formatters#short_path#format(bufnr, buffers)
|
||||
let fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':p:h:t')
|
||||
let _ = ''
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
" MIT License. Copyright (c) 2013-2021 Bailey Ling et al.
|
||||
" vim: et ts=2 sts=2 sw=2
|
||||
|
||||
scriptencoding utf-8
|
||||
|
||||
function! airline#extensions#tabline#formatters#short_path_improved#format(bufnr, buffers) abort
|
||||
let name = bufname(a:bufnr)
|
||||
if empty(name)
|
||||
return airline#extensions#tabline#formatters#default#wrap_name(a:bufnr, '[No Name]')
|
||||
endif
|
||||
|
||||
let tail = s:tail(a:bufnr)
|
||||
let tails = s:tails(a:bufnr, a:buffers)
|
||||
|
||||
if has_key(tails, tail)
|
||||
" Use short path for duplicates
|
||||
return airline#extensions#tabline#formatters#short_path#format(a:bufnr, a:buffers)
|
||||
endif
|
||||
|
||||
" Use tail for unique filenames
|
||||
return airline#extensions#tabline#formatters#default#wrap_name(a:bufnr, tail)
|
||||
endfunction
|
||||
|
||||
function! s:tails(self, buffers) abort
|
||||
let tails = {}
|
||||
for nr in a:buffers
|
||||
if nr != a:self
|
||||
let tails[s:tail(nr)] = 1
|
||||
endif
|
||||
endfor
|
||||
return tails
|
||||
endfunction
|
||||
|
||||
function! s:tail(bufnr) abort
|
||||
return fnamemodify(bufname(a:bufnr), ':t')
|
||||
endfunction
|
|
@ -1315,12 +1315,11 @@ Note: Not displayed if the number of tabs is less than 1
|
|||
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.
|
||||
" The `unique_tail_improved` algorithm will uniquify buffers names with
|
||||
" similar filename, suppressing common parts of paths.
|
||||
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
|
||||
|
||||
" The `short_path` - is a simple formatter, that will show the
|
||||
" The `short_path` algorithm is a simple formatter, that will show the
|
||||
filename, with its extension, and the first parent directory only.
|
||||
|
||||
e.g.
|
||||
|
@ -1335,6 +1334,11 @@ Note: Not displayed if the number of tabs is less than 1
|
|||
" or display file name as relative to the home directory, if possible
|
||||
let g:airline#extensions#tabline#fnamemod = ':~:h'
|
||||
|
||||
" The `short_path_improved` algorithm will only show the short path for
|
||||
" duplicate buffer names, otherwise suppressing directories.
|
||||
|
||||
let g:airline#extensions#tabline#formatter = 'short_path_improved'
|
||||
|
||||
* defines the customized format() function to display tab title in tab mode. >
|
||||
let g:airline#extensions#tabline#tabtitle_formatter = 'MyTabTitleFormatter'
|
||||
<
|
||||
|
|
Loading…
Reference in New Issue
Block a user