example.vim 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. " MIT License. Copyright (c) 2013-2021 Bailey Ling et al.
  2. " vim: et ts=2 sts=2 sw=2
  3. scriptencoding utf-8
  4. " we don't actually want this loaded :P
  5. finish
  6. " Due to some potential rendering issues, the use of the `space` variable is
  7. " recommended.
  8. let s:spc = g:airline_symbols.space
  9. " Extension specific variables can be defined the usual fashion.
  10. if !exists('g:airline#extensions#example#number_of_cats')
  11. let g:airline#extensions#example#number_of_cats = 42
  12. endif
  13. " First we define an init function that will be invoked from extensions.vim
  14. function! airline#extensions#example#init(ext)
  15. " Here we define a new part for the plugin. This allows users to place this
  16. " extension in arbitrary locations.
  17. call airline#parts#define_raw('cats', '%{airline#extensions#example#get_cats()}')
  18. " Next up we add a funcref so that we can run some code prior to the
  19. " statusline getting modified.
  20. call a:ext.add_statusline_func('airline#extensions#example#apply')
  21. " You can also add a funcref for inactive statuslines.
  22. " call a:ext.add_inactive_statusline_func('airline#extensions#example#unapply')
  23. endfunction
  24. " This function will be invoked just prior to the statusline getting modified.
  25. function! airline#extensions#example#apply(...)
  26. " First we check for the filetype.
  27. if &filetype == "nyancat"
  28. " Let's say we want to append to section_c, first we check if there's
  29. " already a window-local override, and if not, create it off of the global
  30. " section_c.
  31. let w:airline_section_c = get(w:, 'airline_section_c', g:airline_section_c)
  32. " Then we just append this extension to it, optionally using separators.
  33. let w:airline_section_c .= s:spc.g:airline_left_alt_sep.s:spc.'%{airline#extensions#example#get_cats()}'
  34. endif
  35. endfunction
  36. " Finally, this function will be invoked from the statusline.
  37. function! airline#extensions#example#get_cats()
  38. let cats = ''
  39. for i in range(1, g:airline#extensions#example#number_of_cats)
  40. let cats .= ' (,,,)=(^.^)=(,,,) '
  41. endfor
  42. return cats
  43. endfunction