0

I'm going through the VimCasts.org archive of videos and number 5 covers using Vim's auto-indentation to format source code. I see it working properly in my Objective-C file but not my .vimrc.

My tab settings are as follows:

set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab

My .vimrc file has the following if block:

if has("autocmd")
filetype on
autocmd BufNewFile,BufRead *.rss,*.atom setfiletype xml
autocmd BufWritePre *.py,*.js :call <SID>StripTrailingWhitespaces()
endif

I would think that if I placed the cursor on the first line above and pressed Vjjjj= I would get the second, third and fourth line indented by two spaces, but what I get instead is:

if has("autocmd")
filetype on
    autocmd BufNewFile,BufRead *.rss,*.atom setfiletype xml
autocmd BufWritePre *.py,*.js :call <SID>StripTrailingWhitespaces()
    endif

Are my expectations incorrect or is this correct for some reason given the Vimscript language?

Chuck
  • 4,662
  • 2
  • 33
  • 55

1 Answers1

3

You need to add filetype plugin indent on to your vimrc to get vim to do indentation properly. (The plugin part isn't really necessary but is nice to have)

I would recommend replacing the filetype on line with filetype plugin indent on

FDinoff
  • 30,689
  • 5
  • 75
  • 96
  • I did that and sourced the `.vimrc` file but there was no change in the behavior. I also searched through the `.vimrc` file for `filetype` and the only occurrences were within the code block that I quoted. But I'll `:h` the `filetype` command and see if what I read there helps. – Chuck Jun 23 '14 at 18:07
  • @Chuck post your whole vimrc – FDinoff Jun 23 '14 at 18:22
  • Well, it'll be embarrassing. :) I'm working through multiple tutorials on Vim and Vimscript, so most of what's in there is code that I'm experimenting with, but here it is: http://pastebin.com/5nP7VyQ4 – Chuck Jun 23 '14 at 18:31
  • @Chuck did you reopen vim after changing the line or did you resource your vimrc? Because changing that line works for me. The only other thing you could check is does your vim support autocmd. (`echo has("autocmd")` should return 1). BTW it works for me using your vimrc. – FDinoff Jun 23 '14 at 18:35
  • I had sourced it, but closing all the windows and opening the `.vimrc` again worked. ty. – Chuck Jun 23 '14 at 22:15