From 88894aa0adb1e677b2afd641b7889043eb8d1d79 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Fri, 5 Jun 2020 16:48:07 +1000 Subject: [PATCH] Support fzf and fzf.vim Adds a slightly nicer statusline for the terminal buffers created by the fzf and fzf.vim plugins. https://github.com/junegunn/fzf https://github.com/junegunn/fzf.vim --- autoload/airline/extensions.vim | 6 ++++ autoload/airline/extensions/fzf.vim | 48 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 autoload/airline/extensions/fzf.vim diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 594c8352..9030ba5b 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -170,6 +170,12 @@ function! airline#extensions#load() call add(s:loaded_ext, 'netrw') endif + " fzf buffers are also terminal buffers, so this must be above term. + if exists(':FZF') && get(g:, 'airline#extensions#fzf#enabled', 1) + call airline#extensions#fzf#init(s:ext) + call add(s:loaded_ext, 'fzf') + endif + if (has("terminal") || has('nvim')) && \ get(g:, 'airline#extensions#term#enabled', 1) call airline#extensions#term#init(s:ext) diff --git a/autoload/airline/extensions/fzf.vim b/autoload/airline/extensions/fzf.vim new file mode 100644 index 00000000..0853c0fa --- /dev/null +++ b/autoload/airline/extensions/fzf.vim @@ -0,0 +1,48 @@ +" MIT License. Copyright (c) 2013-2020 Bailey Ling et al. +" Plugin: https://github.com/junegunn/fzf, https://github.com/junegunn/fzf.vim +" vim: et ts=2 sts=2 sw=2 + +scriptencoding utf-8 + +if !get(g:, 'loaded_fzf', 0) + finish +endif + +function! airline#extensions#fzf#init(ext) abort + " Remove the custom statusline that fzf.vim sets by removing its `FileType + " fzf` autocmd. Ideally we'd use `let g:fzf_statusline = 0`, but this + " variable is checked *before* airline#extensions#init() is called. + augroup _fzf_statusline + autocmd! + augroup END + + call a:ext.add_statusline_func('airline#extensions#fzf#apply') + call a:ext.add_inactive_statusline_func('airline#extensions#fzf#inactive_apply') +endfunction + +function! airline#extensions#fzf#statusline(...) abort + let spc = g:airline_symbols.space + + let builder = airline#builder#new({ 'active': 1 }) + call builder.add_section('airline_a', spc.'FZF'.spc) + call builder.add_section('airline_c', '') + return builder.build() +endfunction + +function! airline#extensions#fzf#apply(...) abort + if &filetype ==# 'fzf' + let spc = g:airline_symbols.space + call a:1.add_section('airline_a', spc.'FZF'.spc) + call a:1.add_section('airline_c', '') + return 1 + endif +endfunction + +function! airline#extensions#fzf#inactive_apply(...) abort + if getbufvar(a:2.bufnr, '&filetype') ==# 'fzf' + let spc = g:airline_symbols.space + call a:1.add_section('airline_a', spc.'FZF'.spc) + call a:1.add_section('airline_c', '') + return 1 + endif +endfunction