mirror of
https://github.com/vim-airline/vim-airline.git
synced 2025-07-27 07:54:44 +02:00
implement customizable file name formatting (#230).
This commit is contained in:
parent
b636c28ae2
commit
7a2f6525c3
@ -19,10 +19,11 @@ function! airline#deprecation#check()
|
|||||||
\ [ 'g:airline_enable_branch', 'g:airline#extensions#branch#enabled' ],
|
\ [ 'g:airline_enable_branch', 'g:airline#extensions#branch#enabled' ],
|
||||||
\ [ 'g:airline_enable_bufferline', 'g:airline#extensions#bufferline#enabled' ],
|
\ [ 'g:airline_enable_bufferline', 'g:airline#extensions#bufferline#enabled' ],
|
||||||
\ [ 'g:airline_enable_syntastic', 'g:airline#extensions#syntastic#enabled' ],
|
\ [ 'g:airline_enable_syntastic', 'g:airline#extensions#syntastic#enabled' ],
|
||||||
|
\ [ 'g:airline#extensions#tabline#fnamemod', 'g:airline#extensions#tabline#fnamefunc' ],
|
||||||
\ ]
|
\ ]
|
||||||
for test in tests
|
for test in tests
|
||||||
if exists(test[0])
|
if exists(test[0])
|
||||||
echom printf('The variable %s is deprecated and may not work in the future. It has been replaced with %s', test[0], test[1])
|
echom printf('The variable %s is deprecated and may not work in the future. It has been replaced with %s. Please read the documentation.', test[0], test[1])
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
" MIT License. Copyright (c) 2013 Bailey Ling.
|
" MIT License. Copyright (c) 2013 Bailey Ling.
|
||||||
" vim: et ts=2 sts=2 sw=2
|
" vim: et ts=2 sts=2 sw=2
|
||||||
|
|
||||||
let s:fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':p:.')
|
let s:fnamefunc = get(g:, 'airline#extensions#tabline#fnamefunc', 'airline#extensions#tabline#fname_func')
|
||||||
let s:excludes = get(g:, 'airline#extensions#tabline#excludes', [])
|
let s:excludes = get(g:, 'airline#extensions#tabline#excludes', [])
|
||||||
let s:tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0)
|
let s:tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0)
|
||||||
let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
|
let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1)
|
||||||
@ -82,6 +82,11 @@ function! airline#extensions#tabline#title(n)
|
|||||||
return airline#extensions#tabline#get_buffer_name(buflist[winnr - 1])
|
return airline#extensions#tabline#get_buffer_name(buflist[winnr - 1])
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! airline#extensions#tabline#fname_func(name)
|
||||||
|
let fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':p:.')
|
||||||
|
return substitute(fnamemodify(a:name, fmod), '\w\zs.\{-}\ze\/', '', 'g')
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#tabline#get_buffer_name(nr)
|
function! airline#extensions#tabline#get_buffer_name(nr)
|
||||||
let _ = ''
|
let _ = ''
|
||||||
let name = bufname(a:nr)
|
let name = bufname(a:nr)
|
||||||
@ -93,7 +98,7 @@ function! airline#extensions#tabline#get_buffer_name(nr)
|
|||||||
if empty(name)
|
if empty(name)
|
||||||
let _ .= '[No Name]'
|
let _ .= '[No Name]'
|
||||||
else
|
else
|
||||||
let _ .= fnamemodify(name, s:fmod)
|
let _ .= call(s:fnamefunc, [name])
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if getbufvar(a:nr, '&modified') == 1
|
if getbufvar(a:nr, '&modified') == 1
|
||||||
|
@ -305,8 +305,15 @@ virtualenv <https://github.com/jmcantrell/vim-virtualenv>
|
|||||||
* enable/disable displaying buffers with a single tab. >
|
* enable/disable displaying buffers with a single tab. >
|
||||||
let g:airline#extensions#tabline#show_buffers = 1
|
let g:airline#extensions#tabline#show_buffers = 1
|
||||||
<
|
<
|
||||||
* configure the formatting of filenames (see |filename-modifiers|). >
|
* defines a function for how to format the file name. >
|
||||||
let g:airline#extensions#tabline#fnamemod = ':p:.'
|
" the default renders /foo/bar/file.txt => /f/b/file.txt
|
||||||
|
let g:airline#extensions#tabline#fnamefunc
|
||||||
|
|
||||||
|
" here's a simple example to show only the file name:
|
||||||
|
function! MyFileFormat(file)
|
||||||
|
return fnamemodify(a:file, ':t')
|
||||||
|
endfunction
|
||||||
|
let g:airline#extensions#tabline#fnamefunc = 'MyFileFormat'
|
||||||
<
|
<
|
||||||
* configure filename match rules to exclude from the tabline. >
|
* configure filename match rules to exclude from the tabline. >
|
||||||
let g:airline#extensions#tabline#excludes = []
|
let g:airline#extensions#tabline#excludes = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user