Updated Configuration Examples and Snippets (markdown)

sunqingyao 2017-09-04 11:20:09 +08:00
parent ca8160dbfd
commit f59c2057d5

@ -10,6 +10,67 @@ Feel free to add your special configuration, if it fixes a need.
set laststatus=2 set laststatus=2
``` ```
## Dynamically change accent of a vim-airline section (requires [AsyncRun](https://github.com/skywind3000/asyncrun.vim))
[Screencast](https://asciinema.org/a/136184)
augroup vimrc
" Auto rebuild C/C++ project when source file is updated, asynchronously
autocmd BufWritePost *.c,*.cpp,*.h
\ let dir=expand('<amatch>:p:h') |
\ if filereadable(dir.'/Makefile') || filereadable(dir.'/makefile') |
\ execute 'AsyncRun -cwd=<root> make -j8' |
\ endif
" Auto toggle the quickfix window
autocmd User AsyncRunStop
\ if g:asyncrun_status=='failure' |
\ execute('call asyncrun#quickfix_toggle(8, 1)') |
\ else |
\ execute('call asyncrun#quickfix_toggle(8, 0)') |
\ endif
augroup END
" Define new accents
function! AirlineThemePatch(palette)
" [ guifg, guibg, ctermfg, ctermbg, opts ].
" See "help attr-list" for valid values for the "opt" value.
" http://vim.wikia.com/wiki/Xterm256_color_names_for_console_Vim
let a:palette.accents.running = [ '', '', '', '', '' ]
let a:palette.accents.success = [ '#00ff00', '' , 'green', '', '' ]
let a:palette.accents.failure = [ '#ff0000', '' , 'red', '', '' ]
endfunction
let g:airline_theme_patch_func = 'AirlineThemePatch'
" Change color of the relevant section according to g:asyncrun_status, a global variable exposed by AsyncRun
" 'running': default, 'success': green, 'failure': red
let g:async_status_old = ''
function! Get_asyncrun_running()
let async_status = g:asyncrun_status
if async_status != g:async_status_old
if async_status == 'running'
call airline#parts#define_accent('asyncrun_status', 'running')
elseif async_status == 'success'
call airline#parts#define_accent('asyncrun_status', 'success')
elseif async_status == 'failure'
call airline#parts#define_accent('asyncrun_status', 'failure')
endif
let g:airline_section_x = airline#section#create(['asyncrun_status'])
AirlineRefresh
let g:async_status_old = async_status
endif
return async_status
endfunction
call airline#parts#define_function('asyncrun_status', 'Get_asyncrun_running')
let g:airline_section_x = airline#section#create(['asyncrun_status'])
## Integration with [vim-obsession](https://github.com/tpope/vim-obsession) ## Integration with [vim-obsession](https://github.com/tpope/vim-obsession)
Prepend a '$' when obsession is enabled ([origin](https://github.com/vim-airline/vim-airline/issues/777#issuecomment-113704356)) Prepend a '$' when obsession is enabled ([origin](https://github.com/vim-airline/vim-airline/issues/777#issuecomment-113704356))