-1

I am pretty noob at Vim still, pardon my ignorance

"Boundary" whitespace is any whitespace except single spaces between words, paraphrasing from VSCode docs: whitespace rendering in VSCode

I want to mimic this same behavior in Vim (ideally with no plugins).

An example of how this feature looks in VSCode: example boundary whitespace rendering in VSCode from previous stackoverflow thread

There aren't many resources that I found on this topic. There is Render space if it have multi space in Vim, which addresses this exact same feature (previous example image shown is from that question), but the provided solution does not work exactly as expected.

This is an example of how boundary whitespaces look after trying out that stackoverflow solution: my .vimrc file and sample boundary whitespace rendering

  • While the '·' character is shown when there are 2 or more spaces in a row, which is desired, they are also shown highlighted, which is not what I expected
  • Moreover, if I place the cursor on a line that contains consecutive spaces, they disappear (or are highlighted into invisibility, whatever is happening that renders them invisible)
  • Excuse my newbie comments in my .vimrc; the rest of the file is commented out

This is another example, in VSCode, of the desired behavior: another example desired boundary whitespace rendering

Am I missing something from that previous question? Is the highlighting of whitespaces normal or a different issue on its own? Thanks in advance!

Finn
  • 11
  • 2

1 Answers1

1

The feature you are looking for can be enabled with :help 'list' and customized with :help 'listchars':

1

The result above can be obtained by adding the following lines to your vimrc:

set list
set listchars=eol:↵,lead:·

If your color scheme makes those characters too visible, you can override its NonText and SpecialKey highlight groups (mentioned in :help 'listchars') to make them more bearable. For example:

augroup MyColors
    autocmd!
    autocmd ColorScheme * hi NonText ctermfg=235 | hi SpecialKey ctermfg=235
augroup END
colorscheme foobar

2

Note that listchars was more limited at the time the linked question was answered so, while it was more or less valid at the time, it is no longer necessary to use the conceal feature for this.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • Thanks for your answer! That looks exactly like what I'm after. Unfortunately, it seems like the `listchars` option doesn't accept the `lead` argument :( It looks like it's only a feature in Neovim: [https://neovim.io/doc/user/options.html#'listchars'](https://neovim.io/doc/user/options.html#'listchars'). Running the command `:help 'listchars'` shows information about arguments like eol, tab, space, trail, but no lead – Finn Jan 01 '23 at 01:16
  • 1
    Like I said in my answer, `lead` is relatively new (two years). Update Vim to a more up-to-date version (posterior to 8.2.2454) to have it. – romainl Jan 01 '23 at 08:35