lightline.txt 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. *lightline.txt* A light and configurable statusline/tabline for Vim
  2. Author: itchyny (https://github.com/itchyny)
  3. License: MIT License
  4. Repository: https://github.com/itchyny/lightline.vim
  5. Last Change: 2022/03/16 00:15:04.
  6. CONTENTS *lightline-contents*
  7. Introduction |lightline-introduction|
  8. Spirit |lightline-spirit|
  9. Option |lightline-option|
  10. Function |lightline-function|
  11. Component Expansion |lightline-component-expansion|
  12. Colorscheme |lightline-colorscheme|
  13. Examples |lightline-examples|
  14. Troubleshooting |lightline-troubleshooting|
  15. ==============================================================================
  16. INTRODUCTION *lightline-introduction*
  17. The *lightline* plugin is a light and configurable statusline/tabline for Vim.
  18. ------------------------------------------------------------------------------
  19. SPIRIT *lightline-spirit*
  20. Minimalism
  21. The core script is very small to achieve enough functions as a
  22. statusline plugin.
  23. Configurability
  24. You can create your own component and easily add to the statusline
  25. and the tabline.
  26. Orthogonality
  27. The plugin does not rely on the implementation of other plugins.
  28. Such plugin crossing settings should be configured by users.
  29. You find this plugin does not integrate with other plugins by default.
  30. This plugin does not provide branch information, which is a basic
  31. component in existing statusline plugins. It is a design of
  32. lightline.vim that such plugin crossing configuration should be
  33. written by users. Once a plugin starts to integrate with some famous
  34. plugins, it should be kept updated to follow the changes of the
  35. plugins and should accept integration requests with new plugins.
  36. Instead, lightline.vim is designed very carefully so that users can
  37. easily integrate with other plugins. Good APIs keep a plugin clean.
  38. ------------------------------------------------------------------------------
  39. OPTIONS *lightline-option*
  40. g:lightline *g:lightline*
  41. All the configurations are stored in this global variable.
  42. g:lightline.active *g:lightline.active*
  43. g:lightline.inactive *g:lightline.inactive*
  44. g:lightline.tabline *g:lightline.tabline*
  45. Dictionaries to store the statusline/tabline components.
  46. Note that right groups of components are stored from right to
  47. left.
  48. The default values are:
  49. >
  50. let g:lightline.active = {
  51. \ 'left': [ [ 'mode', 'paste' ],
  52. \ [ 'readonly', 'filename', 'modified' ] ],
  53. \ 'right': [ [ 'lineinfo' ],
  54. \ [ 'percent' ],
  55. \ [ 'fileformat', 'fileencoding', 'filetype' ] ] }
  56. let g:lightline.inactive = {
  57. \ 'left': [ [ 'filename' ] ],
  58. \ 'right': [ [ 'lineinfo' ],
  59. \ [ 'percent' ] ] }
  60. let g:lightline.tabline = {
  61. \ 'left': [ [ 'tabs' ] ],
  62. \ 'right': [ [ 'close' ] ] }
  63. <
  64. g:lightline.tab *g:lightline.tab*
  65. A dictionary to store the tab components in each tabs.
  66. The default values are:
  67. >
  68. let g:lightline.tab = {
  69. \ 'active': [ 'tabnum', 'filename', 'modified' ],
  70. \ 'inactive': [ 'tabnum', 'filename', 'modified' ] }
  71. <
  72. g:lightline.component *g:lightline.component*
  73. A dictionary for statusline/tabline components.
  74. The default value is:
  75. >
  76. let g:lightline.component = {
  77. \ 'mode': '%{lightline#mode()}',
  78. \ 'absolutepath': '%F',
  79. \ 'relativepath': '%f',
  80. \ 'filename': '%t',
  81. \ 'modified': '%M',
  82. \ 'bufnum': '%n',
  83. \ 'paste': '%{&paste?"PASTE":""}',
  84. \ 'readonly': '%R',
  85. \ 'charvalue': '%b',
  86. \ 'charvaluehex': '%B',
  87. \ 'fileencoding': '%{&fenc!=#""?&fenc:&enc}',
  88. \ 'fileformat': '%{&ff}',
  89. \ 'filetype': '%{&ft!=#""?&ft:"no ft"}',
  90. \ 'percent': '%3p%%',
  91. \ 'percentwin': '%P',
  92. \ 'spell': '%{&spell?&spelllang:""}',
  93. \ 'lineinfo': '%3l:%-2c',
  94. \ 'line': '%l',
  95. \ 'column': '%c',
  96. \ 'close': '%999X X ',
  97. \ 'winnr': '%{winnr()}' }
  98. <
  99. g:lightline.component_visible_condition
  100. *g:lightline.component_visible_condition*
  101. A dictionary to store the visible condition of the components.
  102. Note that this configuration is used to control the visibility
  103. of the subseparators, not to control the visibility of the
  104. components themselves. Each expression should correspond to
  105. the condition on which each component is not empty.
  106. The default value is:
  107. >
  108. let g:lightline.component_visible_condition = {
  109. \ 'modified': '&modified||!&modifiable',
  110. \ 'readonly': '&readonly',
  111. \ 'paste': '&paste',
  112. \ 'spell': '&spell' }
  113. <
  114. g:lightline.component_function *g:lightline.component_function*
  115. A dictionary to store the function components.
  116. This is useful to write a complex component configuration and
  117. to integrate with other plugins. If a component set in both
  118. component and component_function, the configuration of
  119. component_function has priority.
  120. The default value is:
  121. >
  122. let g:lightline.component_function = {}
  123. <
  124. For example, if you want to display the name of the git branch,
  125. install |vim-fugitive| plugin and then configure as:
  126. >
  127. let g:lightline = {
  128. \ 'active': {
  129. \ 'left': [ [ 'mode', 'paste' ],
  130. \ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
  131. \ },
  132. \ 'component_function': {
  133. \ 'gitbranch': 'FugitiveHead'
  134. \ },
  135. \ }
  136. <
  137. If you simply want to display the branch name instead of
  138. installing a plugin for full git integration, you can use
  139. vim-gitbranch (https://github.com/itchyny/vim-gitbranch).
  140. g:lightline.component_function_visible_condition
  141. *g:lightline.component_function_visible_condition*
  142. A dictionary to store the visible conditions of the function
  143. components. Each expression should correspond to the condition
  144. each component is not empty. This configuration is used to
  145. control the visibility of the sub-separators. You can use this
  146. configuration to reduce the number of function calls for
  147. performance improvement by setting the value 1 (to tell lightline
  148. that the component is always visible).
  149. The default value is:
  150. >
  151. let g:lightline.component_function_visible_condition = {}
  152. <
  153. g:lightline.component_expand *g:lightline.component_expand*
  154. A dictionary to store expanding components. You can create
  155. warning and critical components. The values should be the name
  156. of functions should return either one of:
  157. + a string
  158. + an array of three elements:
  159. [[ left ], [ middle ], [ right ]]
  160. The component in this dictionary has priority over
  161. |g:lightline.component| and |g:lightline.component_function|.
  162. Note that the return string is appended to the statusline
  163. string without any conversion. So you should replace all the
  164. % signs with %%. Otherwise, lightline will be disabled in case
  165. the text has a % sign.
  166. (example: return substitute(text, '%', '%%', 'g')).
  167. See |lightline-component-expansion| for more detail.
  168. >
  169. let g:lightline.component_expand = {
  170. \ 'tabs': 'lightline#tabs' }
  171. <
  172. g:lightline.component_type *g:lightline.component_type*
  173. A dictionary to specify the types for components in
  174. |g:lightline.component_expand|. The types are used to specify
  175. the color. Specifically, the type raw is used to specify a
  176. component which should not be wrapped by item group: %(...%).
  177. If you want to specify the type of a raw component, please use
  178. |g:lightline.component_raw|.
  179. The default value is: >
  180. let g:lightline.component_type = {
  181. \ 'tabs': 'tabsel',
  182. \ 'close': 'raw' }
  183. <
  184. g:lightline.component_raw *g:lightline.component_raw*
  185. A dictionary to specify the raw type components. When you
  186. register a component to this dictionary (like >
  187. let g:lightline.component_raw = { 'example': 1 }
  188. < ), the example component is not wrapped by item group: %(...%).
  189. The default value is: >
  190. let g:lightline.component_raw = {}
  191. <
  192. g:lightline.tab_component *g:lightline.tab_component*
  193. A dictionary for components in one tab.
  194. The default value is: >
  195. let g:lightline.tab_component = {}
  196. <
  197. g:lightline.tab_component_function *g:lightline.tab_component_function*
  198. Another dictionary for components in one tab.
  199. A function specified as a tab component takes one argument:
  200. the tab [count].
  201. The default value is:
  202. >
  203. let g:lightline.tab_component_function = {
  204. \ 'filename': 'lightline#tab#filename',
  205. \ 'modified': 'lightline#tab#modified',
  206. \ 'readonly': 'lightline#tab#readonly',
  207. \ 'tabnum': 'lightline#tab#tabnum' }
  208. <
  209. g:lightline.colorscheme *g:lightline.colorscheme*
  210. The colorscheme for lightline.vim.
  211. Currently, wombat, solarized, powerline, powerlineish,
  212. jellybeans, molokai, seoul256, darcula,
  213. selenized_dark, selenized_black, selenized_light, selenized_white,
  214. Tomorrow, Tomorrow_Night, Tomorrow_Night_Blue,
  215. Tomorrow_Night_Bright, Tomorrow_Night_Eighties, PaperColor,
  216. landscape, one, materia, material, OldHope, nord, deus,
  217. simpleblack, srcery_drk, ayu_mirage, ayu_light, ayu_dark,
  218. apprentice, rosepine, and 16color are available.
  219. The default value is:
  220. >
  221. let g:lightline.colorscheme = 'default'
  222. <
  223. Note that the default colorscheme is exactly the same as the
  224. powerline theme.
  225. g:lightline.mode_map *g:lightline.mode_map*
  226. A dictionary of names for the modes. The keys are the return
  227. values of |mode()|.
  228. The default value is:
  229. >
  230. let g:lightline.mode_map = {
  231. \ 'n' : 'NORMAL',
  232. \ 'i' : 'INSERT',
  233. \ 'R' : 'REPLACE',
  234. \ 'v' : 'VISUAL',
  235. \ 'V' : 'V-LINE',
  236. \ "\<C-v>": 'V-BLOCK',
  237. \ 'c' : 'COMMAND',
  238. \ 's' : 'SELECT',
  239. \ 'S' : 'S-LINE',
  240. \ "\<C-s>": 'S-BLOCK',
  241. \ 't': 'TERMINAL',
  242. \ }
  243. <
  244. When you search a word, you get into the command mode. But if
  245. you want to keep the mode indicator as 'NORMAL', add >
  246. let g:lightline = { 'mode_map': { 'c': 'NORMAL' } }
  247. < to your .vimrc.
  248. g:lightline.separator *g:lightline.separator*
  249. g:lightline.subseparator *g:lightline.subseparator*
  250. Dictionaries to store separators.
  251. The default value is
  252. >
  253. let g:lightline.separator = { 'left': '', 'right': '' }
  254. let g:lightline.subseparator = { 'left': '|', 'right': '|' }
  255. <
  256. g:lightline.tabline_separator *g:lightline.tabline_separator*
  257. g:lightline.tabline_subseparator *g:lightline.tabline_subseparator*
  258. Dictionaries to store separators for the tabline.
  259. The default value is
  260. >
  261. let g:lightline.tabline_separator = g:lightline.separator
  262. let g:lightline.tabline_subseparator = g:lightline.subseparator
  263. <
  264. g:lightline.enable *g:lightline.enable*
  265. A dictionary to specify which feature is turned on.
  266. The default value is
  267. >
  268. let g:lightline.enable = {
  269. \ 'statusline': 1,
  270. \ 'tabline': 1
  271. \ }
  272. <
  273. ==============================================================================
  274. FUNCTION *lightline-function*
  275. Exposed functions for lightline.vim.
  276. lightline#mode() *lightline#mode()*
  277. Returns the mode of the Vim using |g:lightline.mode_map|.
  278. lightline#init() *lightline#init()*
  279. Initializes the internal state from |g:lightline|.
  280. lightline#colorscheme() *lightline#colorscheme()*
  281. Initializes the colorscheme and the highlight groups.
  282. lightline#update() *lightline#update()*
  283. Updates all the statuslines of existing windows.
  284. lightline#enable() *lightline#enable()*
  285. Enables |lightline|.
  286. lightline#disable() *lightline#disable()*
  287. Disables |lightline|.
  288. lightline#toggle() *lightline#toggle()*
  289. Toggles |lightline|.
  290. lightline#link([mode]) *lightline#link()*
  291. Creates links of the highlight groups for the active window.
  292. This function accepts an optional argument. It should be one
  293. of the return value of |mode()|.
  294. lightline#highlight() *lightline#highlight()*
  295. Set the highlight groups.
  296. lightline#statusline({inactive}) *lightline#statusline()*
  297. Returns |statusline| strings. If the argument is 0, it returns
  298. the statusline for active window, and the statusline for
  299. inactive window otherwise.
  300. lightline#tabline() *lightline#tabline()*
  301. Returns the tabline string.
  302. lightline#concatenate({list}, {num}) *lightline#concatenate()*
  303. A string concatenation function. Concatenating all the strings
  304. in {list} using the sub-separator of lightline. If {num} is 0,
  305. then the left sub-separator is used. Otherwise, the right
  306. sub-separator is used.
  307. lightline#palette() *lightline#palette()*
  308. Returns the palette data.
  309. ==============================================================================
  310. COMPONENT EXPANSION *lightline-component-expansion*
  311. You can create components, which have specific colors. This section gives an
  312. example using |syntastic|.
  313. If you want to add the |syntastic| flag to the statusline, an easy example is:
  314. >
  315. " Example A
  316. let g:lightline = {
  317. \ 'active': {
  318. \ 'right': [ [ 'lineinfo', 'syntastic' ],
  319. \ [ 'percent' ],
  320. \ [ 'fileformat', 'fileencoding', 'filetype' ] ]
  321. \ },
  322. \ 'component_function': {
  323. \ 'syntastic': 'SyntasticStatuslineFlag',
  324. \ }
  325. \ }
  326. let g:syntastic_mode_map = { 'mode': 'passive',
  327. \ 'active_filetypes': ['c', 'cpp'] }
  328. <
  329. However, the color of the syntastic component is the same as the lineinfo
  330. component.
  331. In order to change the syntastic component more outstanding, you have to use
  332. |g:lightline.component_expand|. See the following example:
  333. >
  334. " Example B
  335. let g:lightline = {
  336. \ 'active': {
  337. \ 'right': [ [ 'syntastic', 'lineinfo' ],
  338. \ [ 'percent' ],
  339. \ [ 'fileformat', 'fileencoding', 'filetype' ] ]
  340. \ },
  341. \ 'component_expand': {
  342. \ 'syntastic': 'SyntasticStatuslineFlag',
  343. \ },
  344. \ 'component_type': {
  345. \ 'syntastic': 'error',
  346. \ }
  347. \ }
  348. " Syntastic can call a post-check hook, let's update lightline there
  349. " For more information: :help syntastic-loclist-callback
  350. function! SyntasticCheckHook(errors)
  351. call lightline#update()
  352. endfunction
  353. <
  354. In order to understand the above codes, you firstly should know how the
  355. colorschemes work in lightline.vim. Open the following file.
  356. autoload/lightline/colorscheme/powerline.vim
  357. The colorscheme is created by one dictionary: s:p (abbreviation for palette).
  358. See the value of s:p.normal.right.
  359. >
  360. let s:p.normal.right = [ ['gray5', 'gray10'],
  361. \ ['gray9', 'gray4'],
  362. \ ['gray8', 'gray2'] ]
  363. <
  364. This array corresponds to the structure of g:lightline.active.right. Recall
  365. the example A.
  366. >
  367. " Example A
  368. let g:lightline.active.right = [ [ 'lineinfo', 'syntastic' ],
  369. \ [ 'percent' ],
  370. \ [ 'fileformat', 'fileencoding', 'filetype' ] ]
  371. <
  372. The colors are ([fgcolor, bgcolor):
  373. >
  374. (0) [ 'lineinfo', 'syntastic' ] --- s:p.normal.right[0] = ['gray5', 'gray10']
  375. (1) [ 'percent' ] --- s:p.normal.right[1] = ['gray9', 'gray4']
  376. (2) [ 'fileformat', 'fileencoding', 'filetype' ] --- s:p.normal.right[2] = ['gray8', 'gray2']
  377. <
  378. Recall the example B.
  379. >
  380. " Example B
  381. let g:lightline.active.right = [ [ 'syntastic', 'lineinfo' ],
  382. \ [ 'percent' ],
  383. \ [ 'fileformat', 'fileencoding', 'filetype' ] ]
  384. <
  385. If a component is specified in |g:lightline.component_expand|, lightline.vim
  386. expands the components before setting to statusline/tabline. In this example,
  387. the syntastic component is expanded using the |SyntasticStatuslineFlag| function.
  388. This function returns a {string}. Let us call it `syntastic_flag`.
  389. >
  390. let syntastic_flag = SyntasticStatuslineFlag()
  391. <
  392. The syntastic component is now expanded, so it go up to one component group.
  393. The type of the syntastic component is error, and the palette has error
  394. colors, the result is:
  395. >
  396. " Expanded result of Example B
  397. (error) [ syntastic_flag ] --- s:p.normal.error[0] = ['gray9', 'brightestred']
  398. (0) [ 'lineinfo' ] --- s:p.normal.right[0] = ['gray5', 'gray10']
  399. (1) [ 'percent' ] --- s:p.normal.right[1] = ['gray9', 'gray4']
  400. (2) [ 'fileformat', 'fileencoding', 'filetype' ] --- s:p.normal.right[2] = ['gray8', 'gray2']
  401. <
  402. Thus the syntastic component has the red color.
  403. Another example for |g:lightline.component_expand| is the tabs component.
  404. Actually, the expand feature is created for the tabs component.
  405. >
  406. let g:lightline.tabline.left = [ [ 'tabs' ] ]
  407. let g:lightline.component_expand = {
  408. \ 'tabs': 'lightline#tabs' }
  409. <
  410. Create three tabs and select the middle tab. Then execute
  411. >
  412. echo lightline#tabs()
  413. " [['%1T%{lightline#onetab(1,0)}'],
  414. " ['%2T%{lightline#onetab(2,1)}'],
  415. " ['%3T%{lightline#onetab(3,0)}%T']]
  416. <
  417. It returns an array of three elements. The expanded result is:
  418. >
  419. " Expanded result of tabline
  420. (0) ['%1T%{lightline#onetab(1,0)}'] --- s:p.tabline.left[0] = ['gray9', 'gray4']
  421. (tabsel) ['%2T%{lightline#onetab(2,1)}'] --- s:p.tabline.tabsel[0] = ['gray9', 'gray1']
  422. (0) ['%3T%{lightline#onetab(3,0)}%T'] --- s:p.tabline.left[0] = ['gray9', 'gray4']
  423. <
  424. If the tabline components are
  425. >
  426. let g:lightline.tabline.left = [ [ 'A', 'B', 'tabs', 'C', 'D' ] ]
  427. <
  428. then the expanded result is:
  429. >
  430. (0) ['A', 'B', '%1T%{lightline#onetab(1,0)}'] --- s:p.tabline.left[0]
  431. (tabsel) ['%2T%{lightline#onetab(2,1)}'] --- s:p.tabline.tabsel[0]
  432. (0) ['%3T%{lightline#onetab(3,0)}%T', 'C', 'D'] --- s:p.tabline.left[0]
  433. <
  434. In summary, when a function in |g:lightline.component_expand| returns an
  435. array of three elements, the first element and the last element remains as a
  436. part of existing component group. And the middle element goes up to new
  437. component group.
  438. ------------------------------------------------------------------------------
  439. COLORSCHEME *lightline-colorscheme*
  440. You can configure the colorscheme of lightline. For example,
  441. >
  442. let g:lightline = {
  443. \ 'colorscheme': 'wombat',
  444. \ }
  445. <
  446. The colorscheme files are found in the directory
  447. lightline.vim/autoload/lightline/colorscheme/
  448. In each file, one global variable is defined. For example, in the landscape.vim
  449. file, you see
  450. >
  451. let g:lightline#colorscheme#landscape#palette = s:p
  452. <
  453. In the file, the colors for the landscape colorscheme are defined. For example,
  454. >
  455. let s:p.normal.left = [ ['#0000ff', '#ffffff', 21, 231, 'bold' ], [ '#ffffff', '#0000ff', 231, 21 ] ]
  456. <
  457. defines the colors for the components on the left hand side, in normal mode.
  458. >
  459. let s:p.tabline.tabsel = [ [ '#dadada', '#121212', 253, 233 ] ]
  460. <
  461. defines the colors for the selected tab in tabline. In general, each palette
  462. follows the following style:
  463. >
  464. let s:p.{mode}.{where} = [ [ {guifg}, {guibg}, {ctermfg}, {ctermbg} ], ... ]
  465. <
  466. Now, you can create your own colorscheme for lightline. Create a
  467. yourcolorscheme.vim at
  468. {one of the paths in &rtp}/autoload/lightline/colorscheme/yourcolorscheme.vim
  469. The following code gives the minimal palette definition for lightline.
  470. >
  471. let s:p = {'normal': {}}
  472. let s:p.normal.left = [ [ ... ] ]
  473. let s:p.normal.right = [ [ ... ] ]
  474. let s:p.normal.middle = [ [ ... ] ]
  475. let g:lightline#colorscheme#yourcolorscheme#palette = s:p
  476. <
  477. And if you add the colorscheme configuration to your .vimrc(_vimrc),
  478. >
  479. let g:lightline = {
  480. \ 'colorscheme': 'yourcolorscheme',
  481. \ }
  482. <
  483. you find it possible to change the lightline colors as you wish.
  484. Moreover, if you want to change the colors based on the mode of vim, write
  485. something like this:
  486. >
  487. let s:p.insert.left = [ [ ... ] ]
  488. let s:p.insert.right = [ [ ... ] ]
  489. let s:p.replace.left = [ [ ... ] ]
  490. let s:p.replace.right = [ [ ... ] ]
  491. ...
  492. ...
  493. <
  494. For expanded components, you are recommended to define the following two
  495. colors.
  496. >
  497. let s:p.normal.error = [ [ ... ] ]
  498. let s:p.normal.warning = [ [ ... ] ]
  499. <
  500. For the complete list of components the color of which you should define in
  501. your colorscheme, see the colorscheme files in lightline.
  502. It is sometimes painful to write all the colors for both gui and cterm.
  503. Actually, lightline has some useful functions for writing colorschemes. For
  504. example, see
  505. lightline.vim/autoload/lightline/colorscheme/Tomorrow_Night.vim
  506. this colorscheme is defined using only gui color numbers. And convert to the
  507. normal colorscheme form using:
  508. >
  509. let g:lightline#colorscheme#Tomorrow_Night#palette = lightline#colorscheme#fill(s:p)
  510. <
  511. This function fills the cterm colors for a palette which has only gui colors, or
  512. vice versa. However, note that using the convenient function sources an
  513. additional Vim script file (autoload/lightline/colorscheme.vim), which causes
  514. a little slow down. If you want to avoid this situation, write all the colors
  515. as done in autoload/lightline/colorscheme/landscape.vim; firstly create the
  516. colorscheme using the fill function, and see the result, in a sense, the
  517. compiled version of your colorscheme.
  518. >
  519. echo g:lightline#colorscheme#yourcolorscheme#palette
  520. <
  521. Then copy and paste the result to the colorscheme file.
  522. If you want to contribute a new colorscheme that is not currently available
  523. please follow the following rules:
  524. *) All hex codes should be lowercase only
  525. *) Use 2 space soft tabs
  526. *) If your colorscheme has both light and dark variants, use a single file
  527. *) Normal Mode should default to Cyan
  528. *) Insert Mode should default to Green
  529. *) Visual Mode should default to Yellow
  530. *) Replace Mode should default to Red
  531. ==============================================================================
  532. EXAMPLES *lightline-examples*
  533. You can configure the appearance of statusline.
  534. Write the following examples in you .vimrc(_vimrc).
  535. In order to change the colorscheme:
  536. >
  537. let g:lightline = {
  538. \ 'colorscheme': 'wombat',
  539. \ }
  540. <
  541. In order to define your own component:
  542. >
  543. let g:lightline = {
  544. \ 'component_function': {
  545. \ 'filename': 'LightlineFilename',
  546. \ 'readonly': 'LightlineReadonly',
  547. \ 'modified': 'LightlineModified',
  548. \ }
  549. \ }
  550. function! LightlineFilename()
  551. return &ft ==# 'vimfiler' ? vimfiler#get_status_string() :
  552. \ &ft ==# 'unite' ? unite#get_status_string() :
  553. \ expand('%:t') !=# '' ? expand('%:t') : '[No Name]'
  554. endfunction
  555. function! LightlineReadonly()
  556. return &ft !~? 'help\|vimfiler' && &readonly ? 'RO' : ''
  557. endfunction
  558. function! LightlineModified()
  559. return &modifiable && &modified ? '+' : ''
  560. endfunction
  561. <
  562. Separators settings:
  563. >
  564. let g:lightline = {
  565. \ 'separator': { 'left': '', 'right': '' },
  566. \ 'subseparator': { 'left': '|', 'right': '|' }
  567. \ }
  568. <
  569. An example for fugitive, vimfiler and unite users.
  570. >
  571. let g:lightline = {
  572. \ 'active': {
  573. \ 'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'filename' ] ]
  574. \ },
  575. \ 'component_function': {
  576. \ 'fugitive': 'LightlineFugitive',
  577. \ 'filename': 'LightlineFilename'
  578. \ }
  579. \ }
  580. function! LightlineModified()
  581. return &ft =~# 'help\|vimfiler' ? '' : &modified ? '+' : &modifiable ? '' : '-'
  582. endfunction
  583. function! LightlineReadonly()
  584. return &ft !~? 'help\|vimfiler' && &readonly ? 'RO' : ''
  585. endfunction
  586. function! LightlineFilename()
  587. return (LightlineReadonly() !=# '' ? LightlineReadonly() . ' ' : '') .
  588. \ (&ft ==# 'vimfiler' ? vimfiler#get_status_string() :
  589. \ &ft ==# 'unite' ? unite#get_status_string() :
  590. \ expand('%:t') !=# '' ? expand('%:t') : '[No Name]') .
  591. \ (LightlineModified() !=# '' ? ' ' . LightlineModified() : '')
  592. endfunction
  593. function! LightlineFugitive()
  594. if exists('*FugitiveHead')
  595. return FugitiveHead()
  596. endif
  597. return ''
  598. endfunction
  599. <
  600. For users of lots of plugins:
  601. >
  602. let g:lightline = {
  603. \ 'active': {
  604. \ 'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'filename' ], ['ctrlpmark'] ],
  605. \ 'right': [ [ 'syntastic', 'lineinfo' ], ['percent'], [ 'fileformat', 'fileencoding', 'filetype' ] ]
  606. \ },
  607. \ 'component_function': {
  608. \ 'fugitive': 'LightlineFugitive',
  609. \ 'filename': 'LightlineFilename',
  610. \ 'fileformat': 'LightlineFileformat',
  611. \ 'filetype': 'LightlineFiletype',
  612. \ 'fileencoding': 'LightlineFileencoding',
  613. \ 'mode': 'LightlineMode',
  614. \ 'ctrlpmark': 'CtrlPMark',
  615. \ },
  616. \ 'component_expand': {
  617. \ 'syntastic': 'SyntasticStatuslineFlag',
  618. \ },
  619. \ 'component_type': {
  620. \ 'syntastic': 'error',
  621. \ },
  622. \ 'subseparator': { 'left': '|', 'right': '|' }
  623. \ }
  624. function! LightlineModified()
  625. return &ft ==# 'help' ? '' : &modified ? '+' : &modifiable ? '' : '-'
  626. endfunction
  627. function! LightlineReadonly()
  628. return &ft !~? 'help' && &readonly ? 'RO' : ''
  629. endfunction
  630. function! LightlineFilename()
  631. let fname = expand('%:t')
  632. return fname ==# 'ControlP' && has_key(g:lightline, 'ctrlp_item') ? g:lightline.ctrlp_item :
  633. \ fname =~# '^__Tagbar__\|__Gundo\|NERD_tree' ? '' :
  634. \ &ft ==# 'vimfiler' ? vimfiler#get_status_string() :
  635. \ &ft ==# 'unite' ? unite#get_status_string() :
  636. \ &ft ==# 'vimshell' ? vimshell#get_status_string() :
  637. \ (LightlineReadonly() !=# '' ? LightlineReadonly() . ' ' : '') .
  638. \ (fname !=# '' ? fname : '[No Name]') .
  639. \ (LightlineModified() !=# '' ? ' ' . LightlineModified() : '')
  640. endfunction
  641. function! LightlineFugitive()
  642. try
  643. if expand('%:t') !~? 'Tagbar\|Gundo\|NERD' && &ft !~? 'vimfiler' && exists('*FugitiveHead')
  644. let mark = '' " edit here for cool mark
  645. let branch = FugitiveHead()
  646. return branch !=# '' ? mark.branch : ''
  647. endif
  648. catch
  649. endtry
  650. return ''
  651. endfunction
  652. function! LightlineFileformat()
  653. return winwidth(0) > 70 ? &fileformat : ''
  654. endfunction
  655. function! LightlineFiletype()
  656. return winwidth(0) > 70 ? (&filetype !=# '' ? &filetype : 'no ft') : ''
  657. endfunction
  658. function! LightlineFileencoding()
  659. return winwidth(0) > 70 ? (&fenc !=# '' ? &fenc : &enc) : ''
  660. endfunction
  661. function! LightlineMode()
  662. let fname = expand('%:t')
  663. return fname =~# '^__Tagbar__' ? 'Tagbar' :
  664. \ fname ==# 'ControlP' ? 'CtrlP' :
  665. \ fname ==# '__Gundo__' ? 'Gundo' :
  666. \ fname ==# '__Gundo_Preview__' ? 'Gundo Preview' :
  667. \ fname =~# 'NERD_tree' ? 'NERDTree' :
  668. \ &ft ==# 'unite' ? 'Unite' :
  669. \ &ft ==# 'vimfiler' ? 'VimFiler' :
  670. \ &ft ==# 'vimshell' ? 'VimShell' :
  671. \ winwidth(0) > 60 ? lightline#mode() : ''
  672. endfunction
  673. function! CtrlPMark()
  674. if expand('%:t') ==# 'ControlP' && has_key(g:lightline, 'ctrlp_item')
  675. call lightline#link('iR'[g:lightline.ctrlp_regex])
  676. return lightline#concatenate([g:lightline.ctrlp_prev, g:lightline.ctrlp_item
  677. \ , g:lightline.ctrlp_next], 0)
  678. else
  679. return ''
  680. endif
  681. endfunction
  682. let g:ctrlp_status_func = {
  683. \ 'main': 'CtrlPStatusFunc_1',
  684. \ 'prog': 'CtrlPStatusFunc_2',
  685. \ }
  686. function! CtrlPStatusFunc_1(focus, byfname, regex, prev, item, next, marked)
  687. let g:lightline.ctrlp_regex = a:regex
  688. let g:lightline.ctrlp_prev = a:prev
  689. let g:lightline.ctrlp_item = a:item
  690. let g:lightline.ctrlp_next = a:next
  691. return lightline#statusline(0)
  692. endfunction
  693. function! CtrlPStatusFunc_2(str)
  694. return lightline#statusline(0)
  695. endfunction
  696. let g:tagbar_status_func = 'TagbarStatusFunc'
  697. function! TagbarStatusFunc(current, sort, fname, ...) abort
  698. return lightline#statusline(0)
  699. endfunction
  700. " Syntastic can call a post-check hook, let's update lightline there
  701. " For more information: :help syntastic-loclist-callback
  702. function! SyntasticCheckHook(errors)
  703. call lightline#update()
  704. endfunction
  705. let g:unite_force_overwrite_statusline = 0
  706. let g:vimfiler_force_overwrite_statusline = 0
  707. let g:vimshell_force_overwrite_statusline = 0
  708. <
  709. ------------------------------------------------------------------------------
  710. TROUBLESHOOTING *lightline-troubleshooting*
  711. Problem 1: |lightline-problem-1|
  712. How to install this plugin.
  713. Problem 2: |lightline-problem-2|
  714. How to update this plugin.
  715. Problem 3: |lightline-problem-3|
  716. How to uninstall this plugin.
  717. Problem 4: |lightline-problem-4|
  718. Cool statuslines appear only on |:vsp|.
  719. Problem 5: |lightline-problem-5|
  720. The statusline does not seem to be correctly colored.
  721. Problem 6: |lightline-problem-6|
  722. How to use a powerline font and the triangles for separators.
  723. Problem 10: |lightline-problem-10|
  724. Cool statusline disappears in |unite|, |vimfiler| and |vimshell|
  725. buffers.
  726. Problem 11: |lightline-problem-11|
  727. Cool statusline disappears in |CtrlP|, |Tagbar| buffers.
  728. Problem 12: |lightline-problem-12|
  729. How to make the plus sign red like |powerline|?
  730. Problem 13: |lightline-problem-13|
  731. How to change the lightline colorscheme on the fly.
  732. Problem 14: |lightline-problem-14|
  733. The 'E541' warning appears on the right hand side.
  734. Many components disable the statusline of lightline.
  735. Problem 15: |lightline-problem-15|
  736. Do not deal with the tabline.
  737. Do not use the fancy separators in the tabline.
  738. Problem 16: |lightline-problem-16|
  739. When changed the component to a function component to an expanding
  740. component, the statusline of lightline is sometimes disabled.
  741. Problem 17: |lightline-problem-17|
  742. Found a bug of this plugin.
  743. Got many errors while using this plugin.
  744. Vim hangs while using this plugin.
  745. Want this plugin to be more configurable.
  746. This troubleshooting is not helpful.
  747. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  748. Problem 1: *lightline-problem-1*
  749. How to install this plugin.
  750. If you install this plugin using Vim packages:
  751. >
  752. git clone https://github.com/itchyny/lightline.vim \
  753. ~/.vim/pack/plugins/start/lightline
  754. <
  755. If you install this plugin using |vim-pathogen|:
  756. >
  757. git clone https://github.com/itchyny/lightline.vim \
  758. ~/.vim/bundle/lightline.vim
  759. <
  760. If you install this plugin using |Vundle|:
  761. 1. Add the following configuration to your
  762. .vimrc(_vimrc).
  763. >
  764. Plugin 'itchyny/lightline.vim'
  765. <
  766. 2. Install with |:PluginInstall|.
  767. If you install this plugin using |NeoBundle|:
  768. 1. Add the following configuration to your
  769. .vimrc(_vimrc).
  770. >
  771. NeoBundle 'itchyny/lightline.vim'
  772. <
  773. 2. Install with |:NeoBundleInstall|.
  774. If you install this plugin using |vim-plug|:
  775. 1. Add the following configuration to your
  776. .vimrc(_vimrc).
  777. >
  778. Plug 'itchyny/lightline.vim'
  779. <
  780. 2. Install with |:PlugInstall|.
  781. If you install this plugin using |dein|:
  782. 1. Add the following configuration to your
  783. .vimrc(_vimrc).
  784. >
  785. call dein#add('itchyny/lightline.vim')
  786. <
  787. 2. Install with :call |dein#install()|.
  788. Problem 2: *lightline-problem-2*
  789. How to update this plugin.
  790. If you installed this plugin using Vim packages:
  791. >
  792. git -C ~/.vim/pack/plugins/start/lightline pull
  793. <
  794. If you installed this plugin using |vim-pathogen|:
  795. >
  796. git -C ~/.vim/bundle/lightline.vim pull
  797. <
  798. If you installed this plugin using |Vundle|:
  799. Execute |:PluginUpdate|.
  800. If you installed this plugin using |NeoBundle|:
  801. Execute |:NeoBundleUpdate|.
  802. If you installed this plugin using |vim-plug|:
  803. Execute |:PlugUpdate|.
  804. If you installed this plugin using |dein|:
  805. Execute :call |dein#update()|.
  806. Problem 3: *lightline-problem-3*
  807. How to uninstall this plugin.
  808. If you installed this plugin using Vim packages:
  809. >
  810. rm -rf ~/.vim/pack/plugins/start/lightline
  811. <
  812. If you installed this plugin using |vim-pathogen|:
  813. >
  814. rm -rf ~/.vim/bundle/lightline.vim
  815. <
  816. If you have installed this plugin using |Vundle|:
  817. 1. Remove `Plugin 'itchyny/lightline.vim'`
  818. from your .vimrc(_vimrc).
  819. 2. Execute |:PluginClean|.
  820. If you installed this plugin using |NeoBundle|:
  821. 1. Remove `NeoBundle 'itchyny/lightline.vim'`
  822. from your .vimrc(_vimrc).
  823. 2. Remove the plugin directory.
  824. If you installed this plugin using |vim-plug|:
  825. 1. Remove `Plug 'itchyny/lightline.vim'`
  826. from your .vimrc(_vimrc).
  827. 2. Execute |:PlugClean|.
  828. If you installed this plugin using |dein|:
  829. 1. Remove `call dein#add('itchyny/lightline.vim')`
  830. from your .vimrc(_vimrc).
  831. 2. Remove the plugin directory.
  832. Problem 4: *lightline-problem-4*
  833. Cool statuslines appear only on |:vsp|.
  834. Add the following setting to your .vimrc(_vimrc).
  835. >
  836. set laststatus=2
  837. <
  838. Problem 5: *lightline-problem-5*
  839. The statusline does not seem to be correctly colored.
  840. Add
  841. >
  842. export TERM=xterm-256color
  843. <
  844. to your .*shrc and add
  845. >
  846. if !has('gui_running')
  847. set t_Co=256
  848. endif
  849. <
  850. to your .vimrc(_vimrc).
  851. Problem 6: *lightline-problem-6*
  852. How to use a powerline font and the triangles for separators.
  853. Using a patched font is not recommended due to less
  854. portability. Also the powerline fonts project is not actively
  855. maintained (https://github.com/powerline/fonts).
  856. If you still want to use a patched font, you can configure
  857. >
  858. \ 'separator': { 'left': "\ue0b0", 'right': "\ue0b2" },
  859. \ 'subseparator': { 'left': "\ue0b1", 'right': "\ue0b3" },
  860. <
  861. or
  862. >
  863. \ 'separator': { 'left': "\u2b80", 'right': "\u2b82" },
  864. \ 'subseparator': { 'left': "\u2b81", 'right': "\u2b83" },
  865. <
  866. Problem 10: *lightline-problem-10*
  867. Cool statusline disappears on |unite|, |vimfiler| and |vimshell|
  868. buffers.
  869. Add the following settings to your .vimrc(_vimrc).
  870. >
  871. let g:unite_force_overwrite_statusline = 0
  872. let g:vimfiler_force_overwrite_statusline = 0
  873. let g:vimshell_force_overwrite_statusline = 0
  874. <
  875. Problem 11: *lightline-problem-11*
  876. Cool statusline disappears in |CtrlP|, |Tagbar| buffers.
  877. Add the following settings to your .vimrc(_vimrc).
  878. >
  879. let g:ctrlp_status_func = {
  880. \ 'main': 'CtrlPStatusFunc_1',
  881. \ 'prog': 'CtrlPStatusFunc_2',
  882. \ }
  883. function! CtrlPStatusFunc_1(focus, byfname, regex, prev, item, next, marked)
  884. return lightline#statusline(0)
  885. endfunction
  886. function! CtrlPStatusFunc_2(str)
  887. return lightline#statusline(0)
  888. endfunction
  889. let g:tagbar_status_func = 'TagbarStatusFunc'
  890. function! TagbarStatusFunc(current, sort, fname, ...) abort
  891. return lightline#statusline(0)
  892. endfunction
  893. <
  894. See |lightline-example| for more cool settings for
  895. these plugins.
  896. Problem 12: *lightline-problem-12*
  897. How to make the plus sign red like |powerline|?
  898. Use the following settings.
  899. >
  900. let g:lightline = {
  901. \ 'component': {
  902. \ 'modified': '%#ModifiedColor#%{LightlineModified()}',
  903. \ }
  904. \ }
  905. function! LightlineModified()
  906. let map = { 'V': 'n', "\<C-v>": 'n', 's': 'n', 'v': 'n', "\<C-s>": 'n', 'c': 'n', 'R': 'n'}
  907. let mode = get(map, mode()[0], mode()[0])
  908. let bgcolor = {'n': [240, '#585858'], 'i': [31, '#0087af']}
  909. let color = get(bgcolor, mode, bgcolor.n)
  910. exe printf('hi ModifiedColor ctermfg=196 ctermbg=%d guifg=#ff0000 guibg=%s term=bold cterm=bold',
  911. \ color[0], color[1])
  912. return &modified ? '+' : &modifiable ? '' : '-'
  913. endfunction
  914. <
  915. It's surely complicated. There's no easy API to do a thing
  916. like this. But it means that your request does not match
  917. the spirit of lightline.
  918. Problem 13: *lightline-problem-13*
  919. How to change the lightline colorscheme on the fly.
  920. To update your lightline colorscheme in sync with your vim
  921. colorscheme (only for select colorschemes which exist for
  922. both), add the following settings to your .vimrc(_vimrc).
  923. >
  924. augroup LightlineColorscheme
  925. autocmd!
  926. autocmd ColorScheme * call s:lightline_update()
  927. augroup END
  928. function! s:lightline_update()
  929. if !exists('g:loaded_lightline')
  930. return
  931. endif
  932. try
  933. if g:colors_name =~# 'wombat\|solarized\|landscape\|jellybeans\|seoul256\|Tomorrow'
  934. let g:lightline.colorscheme =
  935. \ substitute(substitute(g:colors_name, '-', '_', 'g'), '256.*', '', '')
  936. call lightline#init()
  937. call lightline#colorscheme()
  938. call lightline#update()
  939. endif
  940. catch
  941. endtry
  942. endfunction
  943. <
  944. If you have not settled on a single lightline colorscheme, you
  945. can easily switch between lightline colorschemes by adding the
  946. following LightlineColorscheme command to your .vimrc(_vimrc).
  947. >
  948. function! s:set_lightline_colorscheme(name) abort
  949. let g:lightline.colorscheme = a:name
  950. call lightline#init()
  951. call lightline#colorscheme()
  952. call lightline#update()
  953. endfunction
  954. function! s:lightline_colorschemes(...) abort
  955. return join(map(
  956. \ globpath(&rtp,"autoload/lightline/colorscheme/*.vim",1,1),
  957. \ "fnamemodify(v:val,':t:r')"),
  958. \ "\n")
  959. endfunction
  960. command! -nargs=1 -complete=custom,s:lightline_colorschemes LightlineColorscheme
  961. \ call s:set_lightline_colorscheme(<q-args>)
  962. <
  963. Problem 14: *lightline-problem-14*
  964. The 'E541' warning appears on the right hand side.
  965. Many components disable the statusline of lightline.
  966. The number of items in statusline/tabline is limited to 80
  967. (see |E541|). You cannot register too much components.
  968. Problem 15: *lightline-problem-15*
  969. Do not deal with the tabline.
  970. Do not use the fancy separators in the tabline.
  971. You can disable the tabline feature of lightline.vim using:
  972. >
  973. let g:lightline = {
  974. \ 'enable': { 'tabline': 0 },
  975. \ }
  976. <
  977. If you don't like the separators in the tabline, use:
  978. >
  979. let g:lightline = {
  980. \ 'tabline_separator': { 'left': '', 'right': '' },
  981. \ 'tabline_subseparator': { 'left': '', 'right': '' },
  982. \ }
  983. <
  984. Problem 16: *lightline-problem-16*
  985. When changed the component to a function component to an expanding
  986. component, the statusline of lightline is sometimes disabled.
  987. When you changed from
  988. >
  989. \ 'component_function': {
  990. \ 'my': 'My',
  991. \ }
  992. <
  993. to
  994. >
  995. \ 'component_expand': {
  996. \ 'my': 'My',
  997. \ }
  998. <
  999. the statusline of lightline is disabled unexpectedly.
  1000. In such a case, the text returned by 'My' function may include
  1001. the '%' character. Replace all the '%' signs with '%%'.
  1002. >
  1003. function My()
  1004. ...
  1005. return substitute(text, '%', '%%', 'g')
  1006. endfunction
  1007. <
  1008. Problem 17: *lightline-problem-17*
  1009. Found a bug of this plugin.
  1010. Got many errors while using this plugin.
  1011. Vim hangs while using this plugin.
  1012. Want this plugin to be more configurable.
  1013. This troubleshooting is not helpful.
  1014. Report/Request the issue/feature at
  1015. https://github.com/itchyny/lightline.vim/issues.
  1016. ==============================================================================
  1017. vim:tw=78:sw=4:ts=8:ft=help:norl:noet: