When I create a new line or hit
o I have Vim configured to match the previous indentation.
However, since I use hard tabs in most places, vim will replace any spaces that are greater than or equal to the current shift width with hard tabs.
Since I mix tabs and spaces depending on logical indent (tabs) and alignment (spaces), this gets really annoying.
For example, take the following comment (
› = tab,
○ = space):
› /* › › Returns: › › ○○○○0 for success › › ○○○○non-zero for failure › */
If I go to the end of the
0 for success line and hit enter (or just go to the line and, in normal mode, hit
o), seeing as how my tab width is 4, vim will copy the indentation but replace all sequences of 4 spaces with a hard tab instead of keeping them as 4 spaces.
› /* › › Returns: › › ○○○○0 for success › › › <-- super annoying › › ○○○○non-zero for failure › */
Here is my current indentation configuration:
set autoindent set nosmartindent set nocindent set indentexpr=-1 set indentkeys= filetype plugin indent off autocmd FileType * setlocal indentkeys= autocmd BufNewFile,BufRead * setlocal indentkeys=
How do I get Vim to match the indentation exactly when it creates a new line with automatic indentation?