Sometime there is 0xa0 in my code, which causes compile error and hard to find out where it is because it's invisible.. I searched on google and found set listchars=nbsp:. can make the 0xa0 visible.

I want to enable listchars permanently, but it requires set list, which causes tabs are displayed as '^I'.

How can I enable set list and make tabs remain unchanged?

  • What is the value of listchars (set listchars?)? IIRC 'list' wont display special characters for items not in listchars.
    – D. Ben Knoble
    Jan 31, 2019 at 14:38
  • Only set listchars=nbsp:. and the tabs still displayed as '^I'. I can confirm it is set correctly with command set listchars, it shows 'listchars=nbsp:.'
    – aj3423
    Jan 31, 2019 at 15:13
  • Ah; it may displaying the « control character » version (thats a <C-i> representation).
    – D. Ben Knoble
    Jan 31, 2019 at 15:15

2 Answers 2


Displaying ^I for tab is the default Vi behavior. You could set the list character for tab to a spaces:

set listchars=nbsp:×,tab:\ \ ,trail:\ ,
set list

Note that I have added a definition for trailing spaces (to be displayed as spaces). Without it, the nbsp is not displayed.

Alternative: Use Syntax highlighting

Just add the following to your vimrc:

autocmd Syntax * syntax match NBSP "[\xa0]" containedin=ALL | highlight link NBSP Error
  • Same idea, same time!
    – D. Ben Knoble
    Jan 31, 2019 at 15:19
  • @D.BenKnoble Yes :-). Could you test in your environment, that the replacement char for nbsp is only displayed, when a replacement char for trail is defined?
    – Ralf
    Jan 31, 2019 at 15:24
  • given set list listchars=nsbp:_ (not the exact char, but close enough), it is displayed. Setting trail seems to be optional for me.
    – D. Ben Knoble
    Jan 31, 2019 at 15:30
  • @D.BenKnoble I'm pretty sure it is a bug. Try it with vim --clean. I checked two versions on Linux (7.4 & 8.1.857) and Windows (8.1.x & cygwin 8.0.x).
    – Ralf
    Jan 31, 2019 at 17:37
  • Indeed... not sure whats causing me to not see it. Repro’d with vim —clean as you suggested
    – D. Ben Knoble
    Jan 31, 2019 at 17:46

One slightly hacky workaround that I’m not entirely satisfied with is to use the space character for listchars tab:

execute 'set listchars+=tab:  '

(Note that there are 2 spaces; the first character traditionally represents the start of a tab, and the second character is used for the "filler" space.)

I use myself a value more like

execute 'set listchars+=tab:» '

So that I can see where the tabs are.

Your Answer

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

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