init.vim 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. function! s:check_defined(variable, default)
  5. if !exists(a:variable)
  6. let {a:variable} = a:default
  7. endif
  8. endfunction
  9. let s:loaded = 0
  10. function! airline#init#bootstrap()
  11. if s:loaded
  12. return
  13. endif
  14. let s:loaded = 1
  15. let g:airline#init#bootstrapping = 1
  16. let g:airline#init#vim_async = (v:version >= 800 && has('job'))
  17. let g:airline#init#is_windows = has('win32') || has('win64')
  18. call s:check_defined('g:airline_detect_modified', 1)
  19. call s:check_defined('g:airline_detect_paste', 1)
  20. call s:check_defined('g:airline_detect_crypt', 1)
  21. call s:check_defined('g:airline_detect_spell', 1)
  22. call s:check_defined('g:airline_detect_spelllang', 1)
  23. call s:check_defined('g:airline_detect_iminsert', 0)
  24. call s:check_defined('g:airline_inactive_collapse', 1)
  25. call s:check_defined('g:airline_exclude_filenames', ['DebuggerWatch','DebuggerStack','DebuggerStatus'])
  26. call s:check_defined('g:airline_exclude_filetypes', [])
  27. call s:check_defined('g:airline_exclude_preview', 0)
  28. " If g:airline_mode_map_codes is set to 1 in your .vimrc it will display
  29. " only the modes' codes in the status line. Refer :help mode() for codes.
  30. " That may be a preferred presentation because it is minimalistic.
  31. call s:check_defined('g:airline_mode_map_codes', 0)
  32. call s:check_defined('g:airline_mode_map', {})
  33. if g:airline_mode_map_codes != 1
  34. " If you prefer different mode names than those below they can be
  35. " customised by inclusion in your .vimrc - for example, including just:
  36. " let g:airline_mode_map = {
  37. " \ 'Rv' : 'VIRTUAL REPLACE',
  38. " \ 'niV' : 'VIRTUAL REPLACE (NORMAL)',
  39. " \ }
  40. " ...would override 'Rv' and 'niV' below respectively.
  41. call extend(g:airline_mode_map, {
  42. \ '__' : '------',
  43. \ 'n' : 'NORMAL',
  44. \ 'no' : 'OP PENDING',
  45. \ 'nov' : 'OP PENDING CHAR',
  46. \ 'noV' : 'OP PENDING LINE',
  47. \ 'no' : 'OP PENDING BLOCK',
  48. \ 'niI' : 'INSERT (NORMAL)',
  49. \ 'niR' : 'REPLACE (NORMAL)',
  50. \ 'niV' : 'V REPLACE (NORMAL)',
  51. \ 'v' : 'VISUAL',
  52. \ 'V' : 'V-LINE',
  53. \ '' : 'V-BLOCK',
  54. \ 's' : 'SELECT',
  55. \ 'S' : 'S-LINE',
  56. \ '' : 'S-BLOCK',
  57. \ 'i' : 'INSERT',
  58. \ 'ic' : 'INSERT COMPL GENERIC',
  59. \ 'ix' : 'INSERT COMPL',
  60. \ 'R' : 'REPLACE',
  61. \ 'Rc' : 'REPLACE COMP GENERIC',
  62. \ 'Rv' : 'V REPLACE',
  63. \ 'Rx' : 'REPLACE COMP',
  64. \ 'c' : 'COMMAND',
  65. \ 'cv' : 'VIM EX',
  66. \ 'ce' : 'EX',
  67. \ 'r' : 'PROMPT',
  68. \ 'rm' : 'MORE PROMPT',
  69. \ 'r?' : 'CONFIRM',
  70. \ '!' : 'SHELL',
  71. \ 't' : 'TERMINAL',
  72. \ 'multi' : 'MULTI',
  73. \ }, 'keep')
  74. " NB: no*, cv, ce, r? and ! do not actually display
  75. else
  76. " Exception: The control character in ^S and ^V modes' codes
  77. " break the status line if allowed to render 'naturally' so
  78. " they are overridden with ^ (when g:airline_mode_map_codes = 1)
  79. call extend(g:airline_mode_map, {
  80. \ '' : '^V',
  81. \ '' : '^S',
  82. \ }, 'keep')
  83. endif
  84. call s:check_defined('g:airline_theme_map', {})
  85. call extend(g:airline_theme_map, {
  86. \ 'default': 'dark',
  87. \ '\CTomorrow': 'tomorrow',
  88. \ 'base16': 'base16',
  89. \ 'mo[l|n]okai': 'molokai',
  90. \ 'wombat': 'wombat',
  91. \ 'zenburn': 'zenburn',
  92. \ 'solarized': 'solarized',
  93. \ 'flattened': 'solarized',
  94. \ '\CNeoSolarized': 'solarized',
  95. \ }, 'keep')
  96. call s:check_defined('g:airline_symbols', {})
  97. " First define the symbols,
  98. " that are common in Powerline/Unicode/ASCII mode,
  99. " then add specific symbols for either mode
  100. call extend(g:airline_symbols, {
  101. \ 'paste': 'PASTE',
  102. \ 'spell': 'SPELL',
  103. \ 'modified': '+',
  104. \ 'space': ' ',
  105. \ 'keymap': 'Keymap:',
  106. \ 'ellipsis': '...'
  107. \ }, 'keep')
  108. if get(g:, 'airline_powerline_fonts', 0)
  109. " Symbols for Powerline terminals
  110. call s:check_defined('g:airline_left_sep', "\ue0b0") " 
  111. call s:check_defined('g:airline_left_alt_sep', "\ue0b1") " 
  112. call s:check_defined('g:airline_right_sep', "\ue0b2") " 
  113. call s:check_defined('g:airline_right_alt_sep', "\ue0b3") " 
  114. " ro=, ws=☲, lnr=, mlnr=☰, colnr=℅, br=, nx=Ɇ, crypt=🔒, dirty=⚡
  115. " Note: For powerline, we add an extra space after maxlinenr symbol,
  116. " because it is usually setup as a ligature in most powerline patched
  117. " fonts. It can be over-ridden by configuring a custom maxlinenr
  118. call extend(g:airline_symbols, {
  119. \ 'readonly': "\ue0a2",
  120. \ 'whitespace': "\u2632",
  121. \ 'maxlinenr': "\u2261 ",
  122. \ 'linenr': " \ue0a1:",
  123. \ 'colnr': " \u2105:",
  124. \ 'branch': "\ue0a0",
  125. \ 'notexists': "\u0246",
  126. \ 'dirty': "\u26a1",
  127. \ 'crypt': nr2char(0x1F512),
  128. \ }, 'keep')
  129. " Note: If "\u2046" (Ɇ) does not show up, try to use "\u2204" (∄)
  130. elseif &encoding==?'utf-8' && !get(g:, "airline_symbols_ascii", 0)
  131. " Symbols for Unicode terminals
  132. call s:check_defined('g:airline_left_sep', "")
  133. call s:check_defined('g:airline_left_alt_sep', "")
  134. call s:check_defined('g:airline_right_sep', "")
  135. call s:check_defined('g:airline_right_alt_sep', "")
  136. " ro=⊝, ws=☲, lnr=㏑, mlnr=☰, colnr=℅, br=ᚠ, nx=Ɇ, crypt=🔒
  137. call extend(g:airline_symbols, {
  138. \ 'readonly': "\u229D",
  139. \ 'whitespace': "\u2632",
  140. \ 'maxlinenr': "\u2261",
  141. \ 'linenr': " \u33d1:",
  142. \ 'colnr': " \u2105:",
  143. \ 'branch': "\u16A0",
  144. \ 'notexists': "\u0246",
  145. \ 'crypt': nr2char(0x1F512),
  146. \ 'dirty': '!',
  147. \ }, 'keep')
  148. else
  149. " Symbols for ASCII terminals
  150. call s:check_defined('g:airline_left_sep', "")
  151. call s:check_defined('g:airline_left_alt_sep', "")
  152. call s:check_defined('g:airline_right_sep', "")
  153. call s:check_defined('g:airline_right_alt_sep', "")
  154. call extend(g:airline_symbols, {
  155. \ 'readonly': 'RO',
  156. \ 'whitespace': '!',
  157. \ 'linenr': ' ln:',
  158. \ 'maxlinenr': '',
  159. \ 'colnr': ' cn:',
  160. \ 'branch': '',
  161. \ 'notexists': '?',
  162. \ 'crypt': 'cr',
  163. \ 'dirty': '!',
  164. \ }, 'keep')
  165. endif
  166. call airline#parts#define('mode', {
  167. \ 'function': 'airline#parts#mode',
  168. \ 'accent': 'bold',
  169. \ })
  170. call airline#parts#define_function('iminsert', 'airline#parts#iminsert')
  171. call airline#parts#define_function('paste', 'airline#parts#paste')
  172. call airline#parts#define_function('crypt', 'airline#parts#crypt')
  173. call airline#parts#define_function('spell', 'airline#parts#spell')
  174. call airline#parts#define_function('filetype', 'airline#parts#filetype')
  175. call airline#parts#define('readonly', {
  176. \ 'function': 'airline#parts#readonly',
  177. \ 'accent': 'red',
  178. \ })
  179. if get(g:, 'airline_section_c_only_filename',0)
  180. call airline#parts#define_raw('file', '%t%m')
  181. else
  182. call airline#parts#define_raw('file', airline#formatter#short_path#format('%f%m'))
  183. endif
  184. call airline#parts#define_raw('path', '%F%m')
  185. call airline#parts#define('linenr', {
  186. \ 'raw': '%{g:airline_symbols.linenr}%l',
  187. \ 'accent': 'bold'})
  188. call airline#parts#define('maxlinenr', {
  189. \ 'raw': '/%L%{g:airline_symbols.maxlinenr}',
  190. \ 'accent': 'bold'})
  191. call airline#parts#define('colnr', {
  192. \ 'raw': '%{g:airline_symbols.colnr}%v',
  193. \ 'accent': 'bold'})
  194. call airline#parts#define_function('ffenc', 'airline#parts#ffenc')
  195. call airline#parts#define('hunks', {
  196. \ 'raw': '',
  197. \ 'minwidth': 100})
  198. call airline#parts#define('branch', {
  199. \ 'raw': '',
  200. \ 'minwidth': 80})
  201. call airline#parts#define('coc_status', {
  202. \ 'raw': '',
  203. \ 'accent': 'bold'
  204. \ })
  205. call airline#parts#define('coc_current_function', {
  206. \ 'raw': '',
  207. \ 'accent': 'bold'
  208. \ })
  209. call airline#parts#define('lsp_progress', {
  210. \ 'raw': '',
  211. \ 'accent': 'bold'
  212. \ })
  213. call airline#parts#define_empty(['obsession', 'tagbar', 'syntastic-warn',
  214. \ 'syntastic-err', 'eclim', 'whitespace','windowswap', 'taglist',
  215. \ 'ycm_error_count', 'ycm_warning_count', 'neomake_error_count',
  216. \ 'neomake_warning_count', 'ale_error_count', 'ale_warning_count',
  217. \ 'lsp_error_count', 'lsp_warning_count', 'scrollbar',
  218. \ 'nvimlsp_error_count', 'nvimlsp_warning_count',
  219. \ 'vim9lsp_warning_count', 'vim9lsp_error_count',
  220. \ 'languageclient_error_count', 'languageclient_warning_count',
  221. \ 'coc_warning_count', 'coc_error_count', 'vista', 'battery'])
  222. call airline#parts#define_text('bookmark', '')
  223. call airline#parts#define_text('capslock', '')
  224. call airline#parts#define_text('codeium', '')
  225. call airline#parts#define_text('gutentags', '')
  226. call airline#parts#define_text('gen_tags', '')
  227. call airline#parts#define_text('grepper', '')
  228. call airline#parts#define_text('xkblayout', '')
  229. call airline#parts#define_text('keymap', '')
  230. call airline#parts#define_text('omnisharp', '')
  231. unlet g:airline#init#bootstrapping
  232. endfunction
  233. function! airline#init#sections()
  234. let spc = g:airline_symbols.space
  235. if !exists('g:airline_section_a')
  236. let g:airline_section_a = airline#section#create_left(['mode', 'crypt', 'paste', 'keymap', 'spell', 'capslock', 'xkblayout', 'iminsert'])
  237. endif
  238. if !exists('g:airline_section_b')
  239. if airline#util#winwidth() > 99
  240. let g:airline_section_b = airline#section#create(['hunks', 'branch', 'battery'])
  241. else
  242. let g:airline_section_b = airline#section#create(['hunks', 'branch'])
  243. endif
  244. endif
  245. if !exists('g:airline_section_c')
  246. if exists("+autochdir") && &autochdir == 1
  247. let g:airline_section_c = airline#section#create(['%<', 'path', spc, 'readonly', 'coc_status', 'lsp_progress'])
  248. else
  249. let g:airline_section_c = airline#section#create(['%<', 'file', spc, 'readonly', 'coc_status', 'lsp_progress'])
  250. endif
  251. endif
  252. if !exists('g:airline_section_gutter')
  253. let g:airline_section_gutter = airline#section#create(['%='])
  254. endif
  255. if !exists('g:airline_section_x')
  256. let g:airline_section_x = airline#section#create_right(['coc_current_function', 'bookmark', 'scrollbar', 'tagbar', 'taglist', 'vista', 'gutentags', 'gen_tags', 'omnisharp', 'grepper', 'codeium', 'filetype'])
  257. endif
  258. if !exists('g:airline_section_y')
  259. let g:airline_section_y = airline#section#create_right(['ffenc'])
  260. endif
  261. if !exists('g:airline_section_z')
  262. if airline#util#winwidth() > 79
  263. let g:airline_section_z = airline#section#create(['windowswap', 'obsession', '%p%%', 'linenr', 'maxlinenr', 'colnr'])
  264. else
  265. let g:airline_section_z = airline#section#create(['%p%%', 'linenr', 'colnr'])
  266. endif
  267. endif
  268. if !exists('g:airline_section_error')
  269. let g:airline_section_error = airline#section#create(['ycm_error_count', 'syntastic-err', 'eclim', 'neomake_error_count', 'ale_error_count', 'lsp_error_count', 'nvimlsp_error_count', 'languageclient_error_count', 'coc_error_count', 'vim9lsp_error_count'])
  270. endif
  271. if !exists('g:airline_section_warning')
  272. let g:airline_section_warning = airline#section#create(['ycm_warning_count', 'syntastic-warn', 'neomake_warning_count', 'ale_warning_count', 'lsp_warning_count', 'nvimlsp_warning_count', 'languageclient_warning_count', 'whitespace', 'coc_warning_count', 'vim9lsp_warning_count'])
  273. endif
  274. endfunction