(This is an excerpt taken from the post: Tabs & Spaces in Vim: How to Make Conscious Use of Both)
It will be presented two ways to visualize Tabs in Vim.
A quick way to visualize whether there is a Tab character is by searching for it using Vim’s
- In NORMAL mode, type
<Enter>. It will search for the Tab character (
\t) and highlight the results.
Although it may be good for a quick check, if you need persistent Tabs visibility plus the ability to use the
search-commands for other purposes, you might need another solution.
list mode displays on screen unprintable characters (
EOL, etc…) with strings defined by the
By default, it will display
^I for a Tab character but this default representation breaks screen alignment so, the suggestion is to set a string representation to be used for the Tab character:
:set listchars=tab:▷▷⋮or add
set listchars=tab:▷▷⋮to your
The command above defines the strings that Vim will display (
▷▷⋮) for a Tab character. Vim’s behavior is to repeat or omit the second character (
▷), which means:
A Tab character on a file that the indentation is set to occupy two screen spaces, will display
A Tab character on a file that the indentation is set to occupy four screen spaces, will display
listmode by typing
Add the following line to your
noremap <Leader><Tab><Tab> :set invlist<CR>
(You may substitute
<Leader><Tab><Tab> as you wish. If you’d like to know more about Vim mappings, please check this post.)
Check the full post about Tabs & Spaces in Vim to know more.
Do you have any other tip about visualizing Tabs in Vim? Please leave a comment!
Thanks for reading 🙌 !