Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - keeping track of exact whitespace counts

Tags:

vim

whitespace

In both Eclipse and Notepad++, I have my text editors configured so a space has a semi-transparent dot in the center, which makes it easy to count whitespace. I prefer to use spaces instead of tabs in my text editing, and this feature is crucial when working with a whitespace-sensitive language like Python.

I have attached a screenshot with some dummy code in case my wording wasn't clear.

At any rate, is there any way to come close to this functionality in Vim (or GVim)? I suppose there is highlighting but that does seem a bit subpar. There's also good old fashioned math by looking at the column number. What are my other options?

whitespace example

like image 542
smcg Avatar asked Jan 16 '23 21:01

smcg


2 Answers

Thes lines in your vimrc should give you an approximation but you won't get dots for normal or leading space: only trailing spaces. That's a Vim limitation.

set list
set listchars=
set listchars+=tab:»\ 
set listchars+=extends:› 
set listchars+=precedes:‹ 
set listchars+=nbsp:· 
set listchars+=trail:· 

See :help 'list' and :help 'listchars.

like image 53
romainl Avatar answered Jan 21 '23 15:01

romainl


I agree with romainl's answer, but would like to add a mention of the indent guides, which can colour indentation based on your current tab size settings.

like image 22
Walter Avatar answered Jan 21 '23 16:01

Walter