Displaying tabs as characters

  • When I work on files in python, I sometimes mistake tabs for spaces and vice versa. Is there a way I can get Vim to display a character for a tab instead of a tab?

    Just as a side note, you can configure to convert all tabs to spaces with `retab` every time you save the file.

    If you have installed vim-faq, you can get an offline answer there: `:h vim-faq` and search `/invisible`. The hard to memorize tag is `:h faq-19.8`.

  • Doorknob

    Doorknob Correct answer

    6 years ago

    Yes, use listchars:

    set list
    set listchars=tab:>-
    

    If you put these two lines in your .vimrc, tabs will be shown as > for the start position and - through the rest of the tab.

    (Sidenote: listchars can also show trailing spaces with trail:x (replace x with the character you want to use for a trailing space), which can be useful as well.)

    Note: I like to use `set listchars=tab:!·,trail:·`, IMHO `·` is a lot clearer than a `-` ... You need a fairly recent Vim version for this to work btw (not sure which exactly, I think 7.3.x)...

    I like using the unicode character `▸` as it is slightly smaller than `>`. Currently I see trailing white space by marking the eol (though I may try the above). My settings are: `set listchars=eol:¬,tab:▸\ ` and

    This one works the best for me `set listchars=eol:·,tab:⍿·,trail:×·` as it is very clean.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM