While doing a
cat on some files, I noticed that some of the text wasn't aligning properly as it does with Vim.
After thinking for a while, I realized that it was due to the <Tab> characters present in those files. I used to use hard tabs instead of spaces (also called soft tabs) a long time back. Later, I started using soft tabs by putting
set expandtab in my
The problematic files contained a mixture of both hard, as well as soft tabs, resulting in misalignment of text in some places.
List the hard tabs
To fix this, i.e., remove hard tabs, the first thing that needs to be done is listing them. This can be done using:
on the Vim command line.
The above command lists unprintable characters with a control symbol, i.e., '^'. The tabs are listed as ^I (that is a capital i).
Remove the hard tabs
Now, to actually remove them:
- You can either remove them manually using the usual deletion methods of Vim, such as backspace, 'x' etc.
do the following on the Vim command line:
:set expandtab (not needed if it is already in your .vimrc) :retab
This will convert all hard tabs to soft tabs according to the value of
softtabstop (if present in your .vimrc).