In Vim, how to change the vimrc so that I could keep files' \t characters while I don't want \t characters appear in the newline generated by auto-indentation and tab-button I pressed.

Is this achievable?

Here is what I have appended to the tail of _vimrc:

set nu 
set noexpandtab " I want to read \t, not to translate them as spaces.
set tabstop=8 " I want to read \t as 8-space-width.

set softtabstop=4 " This makes the <BS> and <Tab> always 4-space-long.
set autoindent
set colorcolumn=100
set shiftwidth=4


set noexpandtab


set expandtab


This will make both auto-indentation and Tabs you manually typed to only spaces.

Now you can type a line containing mixture of both spaces and Tabs with length greater than which tabstop is set,

without worrying some spaces become \t. And actually,

set expandtab does NOT means your files don't contains \t any more,

by typing <Ctrl-Q> + <Tab> you can insert the real \t in your program.

before I solve this problem I think the opposite is true.

So WHY ask this question? For short, just for fun I can say.

In Python, you can't mix both \t and spaces while indenting. also, you don't want the Vim to translate spaces to tabs in a string containing continuous spaces which is over the amount your tabstop is set in vimrc.

| improve this answer | |

Vim doesn't translate tabs (\t characters) to spaces unless you edit the line containing tabs in certain ways or use the :retab command. If you don't want tabs in lines you add, even if you type a tab, then you need to set expandtab:

:set expandtab
| improve this answer | |

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.