4

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

Community
  • 1
  • 1
smcg
  • 3,195
  • 2
  • 30
  • 40
  • 2
    https://groups.google.com/forum/?fromgroups#!topic/vim_dev/dIQHjW1g92s – Conner Aug 06 '12 at 17:22
  • See also [this](http://stackoverflow.com/questions/1675688/make-vim-show-all-white-spaces-as-a-character) notorious question. – glts Aug 06 '12 at 19:33

2 Answers2

6

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.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • You can also separate these via comma, ```set listchars=tab:»\ ,extends:›,precedes:‹,nbsp:·,trail:·``` – Conner Aug 06 '12 at 17:23
  • sigh. sounds like the full support is not a priority at all for the developers, judging by the google thread (despite that it's a common feature in modern text editors). I'll accept this unless a better solution comes along in a day or two. – smcg Aug 06 '12 at 18:14
  • You can leave the question open, I don't mind. `highlight` seems dirtier but might be a viable alternative in the mean time. – romainl Aug 07 '12 at 14:46
3

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.

Walter
  • 7,809
  • 1
  • 30
  • 30
  • I copied the plugin, autoload, and doc dirs to my .vim directory but can't get the plugin to initialize. also tried adding a source statement and failed. How do I load it? – smcg Aug 06 '12 at 19:49
  • Do `:IndentGuidesEnable` in a Vim window or add it to your `.vimrc`. Since I only use the plug-in for Python I have the following in `~/.vim/ftplugin/python.vim`: `let g:indent_guides_start_level=2\n let g:indent_guides_guide_size=1\n IndentGuidesEnable` ... (\n only for illustration purposes) but you can customize as you see fit. :) – Walter Aug 07 '12 at 07:36
  • :IndentGuidesEnable works within Vim but not when I add it to .vimrc (with or without colon) – smcg Aug 07 '12 at 13:12
  • That's because plug-ins are loaded after vimrc is processed. Maybe just enable it for specific file types, as described in my previous comment...? – Walter Aug 08 '12 at 11:49