Vi messes up my indentation


When I use vim in its indentation-keeping mode, creating a linebreak automatically indents the new line to the beginning of the previous one.

Unfortunately, this feature is broken, because it replaces spaces with tabs according to an unknown space-tab relation that is only used by vim. That is, if a line is indented by a number of spaces, then a linebreak will result in the next line being indented by a number of tabs and a small remainder of spaces.

If I try to open the file in any other editor, there is a good chance that a lot of the lines are indented anomalously, as the editor spaces tabs differently.

Do you know of a configuration option I can use to get rid of this? Other than disabling auto-indentation entirely and indenting each line manually?


You can set noexpandtab in your .vimrc or do it filetype by filetype with something like the following, which sets .make files to noexpandtab.



Unfortunately I’m new to .vimrc, and I’m not sure what is stopping this from working. Here’s the file content:

$ cat ~/.vimrc set noexpandtab
Yet when I open a new file, type a lot of spaces and hit enter, the next line will still get tabs.

Am I missing something, or do I have to log in again for it to take effect?


Oops, I’m a dumbass (but you knew that) and read your post wrong. I think you want the opposite of what I posted:


set expandtab, actually, but thanks! It works fine now.


OMG! I should just go back to sleep!

I’m glad you got it worked out and hope that I helped despite my gross errors. :slight_smile:

Free unique IP and $67 off with code [color=#CC0000]LMIP67[/color] or use [color=#CC0000]LM97[/color] for $97 off. Click for other Dreamhost coupons / promo codes