0

Currently, I'm trying to make a pretty minimal custom status line that suits my needs. One element of it, however, is a diagnostics report that depends on another plugin (coc.nvim). With a function, I can display this report on my status line conditionally, that is, only when there are errors in my code.

Although I can modify the string presented in my status bar when there are errors to report, I cannot set whitespaces, as I'm using line characters in fillchars. This does not seems to affect whitespaces set by set statusline+=\ , however, I don't know how to include this command inside a string produced by another function.

As such, is there any special invisible character that can be set inside of a string, that could be ignored by set fillchars?

function! StatusDiagnostic() abort
  let info = get(b:, 'coc_diagnostic_info', {})
  if empty(info) | return '' | endif
  let msgs = []
  if get(info, 'error', 0)
    call add(msgs,'['. 'E' . info['error']  . ']'. ' ')
  endif
  if get(info, 'warning', 0)
    call add(msgs, '[' . 'W ' . info['warning'] . ']'. ' ')
  endif
  return join(msgs, ' '). '' . get(g:, 'coc_status', '')
endfunction

set fillchars=stl:─,stlnc:─
set laststatus=2
set statusline=
set statusline+=%m
set statusline+=\ 
set statusline+=%t
set statusline+=\ 
set statusline+=
set statusline+=\
set statusline+=%{StatusDiagnostic()}
set statusline+=%=
set statusline+=\ 
set statusline+=
set statusline+=\
set statusline+=%l
set statusline+=:
set statusline+=%L
set statusline+=\ 
set statusline+=
set statusline+=\
set statusline+=%P

Here is my status line: statusline with - instead of whitespace If I've failed to be clear, I want to put a whitespace after the closing bracket in E1.

5
  • 1
    I'm not sure I follow; maybe you just don't want to adjust fillchars? But you could try a non-breaking space (0xA0, I think)
    – D. Ben Knoble
    Jan 31 at 15:00
  • Also, welcome to Vi and Vim!
    – D. Ben Knoble
    Jan 31 at 15:00
  • Thank you for the welcome! A non-breaking space seems to be what I'm looking after. Any idea for how I should include that inside a string returned by the StatusDiagnostic() funcion?
    – Idervas
    Jan 31 at 15:32
  • Sure; change the spaces in your strings to the nbsp. For example, C-v xA0 should work to insert it. Or C-k NS.
    – D. Ben Knoble
    Jan 31 at 16:21
  • It worked! Thank you so much for your time!
    – Idervas
    Jan 31 at 16:33

1 Answer 1

1

@Ben is right :-| the solution is:

function! StatusDiagnostic() abort
  let info = get(b:, 'coc_diagnostic_info', {})
  if empty(info) | return '' | endif
  let msgs = []
  if get(info, 'error', 0)
    call add(msgs,'['. 'E' . info['error']  . ']'. "\<char 0xA0>")
  endif
  if get(info, 'warning', 0)
    call add(msgs, '[' . 'W ' . info['warning'] . ']'. "\<char 0xA0>")
  endif
  return join(msgs, "\<char 0xA0>"). '' . get(g:, 'coc_status', '')
endfunction
9
  • Thank you for your answer! However, although your suggestion works for whitespaces set by set statusline, they do not work inside of strings. I want to include a whitespace in the string returned by StatusDiagnostic(), that is ignored by fillchars.
    – Idervas
    Jan 31 at 15:17
  • Have you tried the second option with set &statusline="Hello World "? In my test it works even with fillchars set. Jan 31 at 15:20
  • Yes, all whitespaces inside any string are being affected by fillchars, the only exception being whitespaces set with "set statusline=\ ". I've included your exemple without the "&" before "statusline=", however, since including your line with this character was not recognized.
    – Idervas
    Jan 31 at 15:30
  • And what if you use the form with the leading & (set &statusline+=StatusDiagnostic())? Jan 31 at 15:49
  • 2
    :set &statusline+= is not valid. And let &statusline+=func() eliminates the OP's dynamic statusline behavior
    – D. Ben Knoble
    Jan 31 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.