Reputation: 4479
Sublime (a text editor) can display beginning of line whitespace as a special character like --->
:
function foo() {
--->if (true) {
--->--->alert(true);
--->}
}
It's helpful in some cases. So I want to let Vim to do the same thing. I tried using :set list
, but this options only display tab characters as ^I
, it doesn't display whitespace. Is there some way to do that like it is possible in Sublime?
Upvotes: 4
Views: 568
Reputation: 28944
One can effectively emulate such arrows using the conceal feature
(see :help conceal
):
function! EnableIndentArrows()
exe 'syntax match NonText ''\%(^\%( \{'.&sw.'}\)*'.
\ ' \{0,'.(&sw-2).'}\)\@<= '' transparent conceal cchar=┈'
exe 'syntax match NonText ''\%(^\%( \{'.&sw.'}\)*'.
\ ' \{'.(&sw-1).'}\)\@<= '' transparent conceal cchar=>'
set conceallevel=2 concealcursor=nc
endfunction
Upvotes: 0
Reputation: 2886
You can highlight BOL white space, this will not insert a special character like you ask, but it will at least make it stand out by assigning it a specific color.
:highlight BOLWhitespace guibg=red ctermbg=red
:match BOLWhitespace /^\s\+/
The first line will create a highlight group called BOLWhitespace and give it the color red (might want to use something a bit more subtle). The second line will activate this highlight for all white space at the beginning of lines.
Maybe this is an acceptable compromise?
Upvotes: 2