6

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

Why I have this question: In Python, you can't mix both \t and spaces while indenting.

2 Answers 2

4

Replace

set noexpandtab

to

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.

1
  • I don't want vim to convert my tabs to spaces. I added to the file /etc/vim/vimrc the line set noexpandtab but it didnt help. What should I do?
    – Nathan G
    Commented Feb 17, 2023 at 13:16
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.