In vim, I'd like to set nbsp to ! or · . But I'm not concerned with tab.

In my .vimrc, I have :

 set listchars=nbsp:·
 set list

However, when I open a vim sesion, I still see tab showing as ^I.


:set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<

... it executes without error and I can see the changes.

If I run

:set listchars=nbsp:!,tab:>


:set listchars=nbsp:!,tab:

I get

E474: Argument invalide: listchars=nbsp:!,tab:>

What is going on here? How can I set listchars so vim doesn't highlight tab and just nbsp?

Running VIM - Vi IMproved 7.4


The thing is, ^I is Vim's way of not displaying a Tab character, since essential Tab is stored in the file the same as a Ctrl+I and ^I is the Vim way to represent Ctrl character symbols.

If you want a Tab to simply show as spaces when using :set list, you should set it to do so under 'listchars' (note that you need two spaces, since the tab: item requires two or three characters.) Of course, there's a trick to do that, since a space is usually a separator for the :set command, so you need to escape it with a backslash.

This will work:

set listchars=tab:\ \ ,nbsp:·

You can add the tab:\ \ at the end of the option too, but that might look a bit more awkward with the trailing space.

Another option is to set it using :let and the & syntax to access option values:

let &listchars = 'tab:  ,nbsp:·'

One advantage of this second approach is that you can also use string escape sequences for special characters in your string, such as the middle dot you're using for nbsp:

let &listchars = "tab:  ,nbsp:\xb7"

(This can be an advantage in cases where you want to keep your vimrc or snippets of it using simple base ASCII characters only, for example when you're concerned about preserving formatting and spaces when using copy & paste to transfer these snippets to other systems through a remote connection. Not a huge deal in most cases these days, but I thought I'd mention it anyways.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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