Create for me a custom neovim set statusline for my init.vim. It should show the mode,…
- User
Create for me a custom neovim set statusline for my init.vim. It should show the mode, then the file in its path, then the modification status, read only, flag, and then the file encoding, type, and format, then the percentage, then the file line:collumn, all while maintaining automatically to my theme's colors. Info: 'statusline' 'stl' E540 E542 'statusline' 'stl' string (default empty) global or local to window |global-local| {not in Vi} {not available when compiled without the |+statusline| feature} When nonempty, this option determines the content of the status line. Also see |status-line|.
The option consists of printf style '%' items interspersed with normal text. Each status line item is of the form: %-0{minwid}.{maxwid}{item} All fields except the {item} is optional. A single percent sign can be given as "%%". Up to 80 items can be specified. *E541* When the option starts with "%!" then it is used as an expression, evaluated and the result is used as the option value. Example: :set statusline=%!MyStatusLine() The result can contain %{} items that will be evaluated too. When there is error while evaluating the option then it will be made empty to avoid further errors. Otherwise screen updating would loop. Note that the only effect of 'ruler' when this option is set (and 'laststatus' is 2) is controlling the output of |CTRL-G|. field meaning - Left justify the item. The default is right justified when minwid is larger than the length of the item. 0 Leading zeroes in numeric items. Overridden by '-'. minwid Minimum width of the item, padding as set by '-' & '0'. Value must be 50 or less. maxwid Maximum width of the item. Truncation occurs with a '<' on the left for text items. Numeric items will be shifted down to maxwid-2 digits followed by '>'number where number is the amount of missing digits, much like an exponential notation. item A one letter code as described below. Following is a description of the possible statusline items. The second character in "item" is the type: N for number S for string F for flags as described below - not applicable item meaning f S Path to the file in the buffer, as typed or relative to current directory. F S Full path to the file in the buffer. t S File name (tail) of file in the buffer. m F Modified flag, text is "[+]"; "[-]" if 'modifiable' is off. M F Modified flag, text is ",+" or ",-". r F Readonly flag, text is "[RO]". R F Readonly flag, text is ",RO". h F Help buffer flag, text is "[help]". H F Help buffer flag, text is ",HLP". w F Preview window flag, text is "[Preview]". W F Preview window flag, text is ",PRV". y F Type of file in the buffer, e.g., "[vim]". See 'filetype'. Y F Type of file in the buffer, e.g., ",VIM". See 'filetype'. {not available when compiled without |+autocmd| feature} q S "[Quickfix List]", "[Location List]" or empty. k S Value of "b:keymap_name" or 'keymap' when |:lmap| mappings are being used: "<keymap>" n N Buffer number. b N Value of character under cursor. B N As above, in hexadecimal. o N Byte number in file of byte under cursor, first byte is 1. Mnemonic: Offset from start of file (with one added) {not available when compiled without |+byte_offset| feature} O N As above, in hexadecimal. N N Printer page number. (Only works in the 'printheader' option.) l N Line number. L N Number of lines in buffer. c N Column number. v N Virtual column number. V N Virtual column number as -{num}. Not displayed if equal to 'c'. p N Percentage through file in lines as in |CTRL-G|. P S Percentage through file of displayed window. This is like the percentage described for 'ruler'. Always 3 in length. a S Argument list status as in default title. ({current} of {max}) Empty if the argument file count is zero or one. { NF Evaluate expression between '%{' and '}' and substitute result. Note that there is no '%' before the closing '}'. ( - Start of item group. Can be used for setting the width and alignment of a section. Must be followed by %) somewhere. ) - End of item group. No width fields allowed. T N For 'tabline': start of tab page N label. Use %T after the last label. This information is used for mouse clicks. X N For 'tabline': start of close tab N label. Use %X after the label, e.g.: %3Xclose%X. Use %999X for a "close current tab" mark. This information is used for mouse clicks. < - Where to truncate line if too long. Default is at the start. No width fields allowed. = - Separation point between left and right aligned items. No width fields allowed. # - Set highlight group. The name must follow and then a # again. Thus use %#HLname# for highlight group HLname. The same highlighting is used, also for the statusline of non-current windows. * - Set highlight group to User{N}, where {N} is taken from the minwid field, e.g. %1*. Restore normal highlight with %* or %0*. The difference between User{N} and StatusLine will be applied to StatusLineNC for the statusline of non-current windows. The number N must be between 1 and 9. See |hl-User1..9| When displaying a flag, Vim removes the leading comma, if any, when that flag comes right after plaintext. This will make a nice display when flags are used like in the examples below. When all items in a group becomes an empty string (i.e. flags that are not set) and a minwid is not set for the group, the whole group will become empty. This will make a group like the following disappear completely from the statusline when none of the flags are set. :set statusline=...%(\ [%M%R%H]%)... Beware that an expression is evaluated each and every time the status line is displayed. The current buffer and current window will be set temporarily to that of the window (and buffer) whose statusline is currently being drawn. The expression will evaluate in this context. The variable "actual_curbuf" is set to the 'bufnr()' number of the real current buffer. The 'statusline' option may be evaluated in the |sandbox|, see |sandbox-option|. It is not allowed to change text or jump to another window while evaluating 'statusline' |textlock|. If the statusline is not updated when you want it (e.g., after setting a variable that's used in an expression), you can force an update by setting an option without changing its value. Example: :let &ro = &ro A result of all digits is regarded a number for display purposes. Otherwise the result is taken as flag text and applied to the rules described above. Watch out for errors in expressions. They may render Vim unusable! If you are stuck, hold down ':' or 'Q' to get a prompt, then quit and edit your .vimrc or whatever with "vim -u NONE" to get it right. Examples: Emulate standard status line with 'ruler' set :set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P Similar, but add ASCII value of char under the cursor (like "ga") :set statusline=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P Display byte count and byte value, modified flag in red. :set statusline=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b' :hi User1 term=inverse,bold cterm=inverse,bold ctermfg=red Display a ,GZ flag if a compressed file is loaded :set statusline=...%r%{VarExists('b:gzflag','\ [GZ]')}%h... In the YXXY:autocmd|'s: :let b:gzflag = 1 And: :unlet b:gzflag And define this function: :function VarExists(var, val) : if exists(a:var) | return a:val | else | return '' | endif :endfunction - Assistant