mirror of
https://github.com/vim-airline/vim-airline.git
synced 2024-11-22 15:49:14 +08:00
extensions: Allow customization of filetypes
Define the variable :let g:airline_filetype_overrides to allow for specific customization how a specific filetype will be displayed. For e.g. a German display, you can use: > :let g:airline_filetype_overrides = {'help': ['Hilfe', ':%f']} < This defines how section a and b will look like for a window with that specific filetype. Closes #1888
This commit is contained in:
parent
170b6d4c26
commit
7469672a46
|
@ -23,12 +23,15 @@ endfunction
|
|||
let s:script_path = tolower(resolve(expand('<sfile>:p:h')))
|
||||
|
||||
let s:filetype_overrides = {
|
||||
\ 'defx': ['defx', '%{b:defx.paths[0]}'],
|
||||
\ 'gundo': [ 'Gundo', '' ],
|
||||
\ 'help': [ 'Help', '%f' ],
|
||||
\ 'minibufexpl': [ 'MiniBufExplorer', '' ],
|
||||
\ 'nerdtree': [ get(g:, 'NERDTreeStatusline', 'NERD'), '' ],
|
||||
\ 'startify': [ 'startify', '' ],
|
||||
\ 'vim-plug': [ 'Plugins', '' ],
|
||||
\ 'vimfiler': [ 'vimfiler', '%{vimfiler#get_status_string()}' ],
|
||||
\ 'vimshell': ['vimshell','%{vimshell#get_status_string()}'],
|
||||
\ }
|
||||
|
||||
let s:filetype_regex_overrides = {}
|
||||
|
@ -58,18 +61,13 @@ function! airline#extensions#apply_left_override(section1, section2)
|
|||
endfunction
|
||||
|
||||
function! airline#extensions#apply(...)
|
||||
let filetype_overrides = get(s:, 'filetype_overrides', {})
|
||||
call extend(filetype_overrides, get(g:, 'airline_filetype_overrides', {}), 'force')
|
||||
|
||||
if s:is_excluded_window()
|
||||
return -1
|
||||
endif
|
||||
|
||||
if &buftype == 'help'
|
||||
call airline#extensions#apply_left_override('Help', '%f')
|
||||
let w:airline_section_x = ''
|
||||
let w:airline_section_y = ''
|
||||
let w:airline_render_right = 1
|
||||
endif
|
||||
|
||||
if &buftype == 'terminal'
|
||||
let w:airline_section_x = ''
|
||||
let w:airline_section_y = ''
|
||||
|
@ -81,11 +79,20 @@ function! airline#extensions#apply(...)
|
|||
let w:airline_section_c = bufname(winbufnr(winnr()))
|
||||
endif
|
||||
|
||||
if has_key(s:filetype_overrides, &ft)
|
||||
let args = s:filetype_overrides[&ft]
|
||||
if has_key(filetype_overrides, &ft) &&
|
||||
\ ((&filetype == 'help' && &buftype == 'help') || &filetype !~ 'help')
|
||||
" for help files only override it, if the buftype is also of type 'help',
|
||||
" else it would trigger when editing Vim help files
|
||||
let args = filetype_overrides[&ft]
|
||||
call airline#extensions#apply_left_override(args[0], args[1])
|
||||
endif
|
||||
|
||||
if &buftype == 'help'
|
||||
let w:airline_section_x = ''
|
||||
let w:airline_section_y = ''
|
||||
let w:airline_render_right = 1
|
||||
endif
|
||||
|
||||
for item in items(s:filetype_regex_overrides)
|
||||
if match(&ft, item[0]) >= 0
|
||||
call airline#extensions#apply_left_override(item[1][0], item[1][1])
|
||||
|
@ -213,14 +220,9 @@ function! airline#extensions#load()
|
|||
endif
|
||||
|
||||
if exists(':VimShell')
|
||||
let s:filetype_overrides['vimshell'] = ['vimshell','%{vimshell#get_status_string()}']
|
||||
let s:filetype_regex_overrides['^int-'] = ['vimshell','%{substitute(&ft, "int-", "", "")}']
|
||||
endif
|
||||
|
||||
if exists(':Defx')
|
||||
let s:filetype_overrides['defx'] = ['defx', '%{b:defx.paths[0]}']
|
||||
endif
|
||||
|
||||
if get(g:, 'airline#extensions#branch#enabled', 1) && (
|
||||
\ airline#util#has_fugitive() ||
|
||||
\ airline#util#has_lawrencium() ||
|
||||
|
|
|
@ -203,12 +203,27 @@ values):
|
|||
statusline modified >
|
||||
let g:airline_exclude_filetypes = [] " see source for current list
|
||||
<
|
||||
* define the set of names to be displayed instead of a specific filetypes (for
|
||||
section a and b): >
|
||||
|
||||
let g:airline_filetype_overrides = {
|
||||
\ 'defx': ['defx', '%{b:defx.paths[0]}'],
|
||||
\ 'gundo': [ 'Gundo', '' ],
|
||||
\ 'help': [ 'Help', '%f' ],
|
||||
\ 'minibufexpl': [ 'MiniBufExplorer', '' ],
|
||||
\ 'nerdtree': [ get(g:, 'NERDTreeStatusline', 'NERD'), '' ],
|
||||
\ 'startify': [ 'startify', '' ],
|
||||
\ 'vim-plug': [ 'Plugins', '' ],
|
||||
\ 'vimfiler': [ 'vimfiler', '%{vimfiler#get_status_string()}' ],
|
||||
\ 'vimshell': ['vimshell','%{vimshell#get_status_string()}'],
|
||||
\ }
|
||||
<
|
||||
* defines whether the preview window should be excluded from have its window
|
||||
statusline modified (may help with plugins which use the preview window
|
||||
heavily) >
|
||||
let g:airline_exclude_preview = 0
|
||||
<
|
||||
* disable the Airline customization for selective windows (this is a
|
||||
* disable the Airline customization for selected windows (this is a
|
||||
window-local variable so you can disable it per-window) >
|
||||
let w:airline_disabled = 1
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user