1

I want to set my tab stops to 2 spaces in any text (.txt) file I edit but I haven't been able to get the hang of it. Maybe I'm just dense. I've read the inline docs to no avail. I've tried reading Vim-related blog posts but it's difficult to narrow it down to this specific problem because searching for vim text tabs includes lots of stuff unrelated to text-type files. This is what I've come up with but which doesn't work:

autocmd FileType txt setlocal ts=2 sts=2 sw=2 expandtab

Feel free to downvote me and take away my programmer badge for asking such a stupid question, but I'm tired of banging my head against the wall on this.

Jim
  • 13,430
  • 26
  • 104
  • 155

1 Answers1

0

We all know that feeling. Your problem is a missing "e" in the filetype. Change "txt" to "text" and it should work.

If there was a problem in detecting the filetype of the file you can add this command to help vim on that.

autocmd BufEnter *.txt set filetype=text

Result:

autocmd BufEnter *.txt set filetype=text
autocmd FileType text setlocal ts=2 sts=2 sw=2 expandtab

To check which type is your file you can execute this command:

:set filetype?
  • Yea, I did that but it doesn't work. If I do vim -u .vimrc.new foo.txt and .vimrc.new has just the line you've shown in it, doing "set filetype?", just shows "filetype=". Also, if I type in ":set", I don't see any of the new settings. – Jim Aug 05 '16 at 22:36
  • when puting the line in the `.vimrc` and calling `vim foo.txt` what happens ? – Meninx - メネンックス Aug 05 '16 at 22:41
  • 1
    You should probably add `,BufNew` such that this also works on new files – Vitor Aug 06 '16 at 11:25