4
votes

I've got a perplexing Vim problem. If I start editing a new file, say with vim test.txt, and I type in the word "do" and hit enter (while still in insert mode), the next line is automatically indented. Before giving a quick answer, please read this whole post.

Two questions:

  1. Why might this happen?
  2. How can I debug the startup process (reading ~/.vimrc and files in ~/.vim/)?

More information:

  • Here's my .vimrc: http://dotfiles.org/~meonkeys/.vimrc.
  • "do", "if", and "switch" all cause indenting, but I still haven't figured out what language Vim is using indent rules for.
  • I do have a bunch of stuff in ~/.vim/. Here's that: http://adammonsen.com/tmp/dot_vim.tgz
  • I can't find anything in my ~/.vimrc or ~/.vim/ that should turn on some kind of indenting even if filetype is unset!
  • If I start Vim using vim -u /dev/null test.txt, the problem goes away.
  • Yes, I know about the autoindent setting. I don't think this is the problem because turning on autoindent after using a null vimrc doesn't indent the line after "do" is typed in.
1
When you are seeing this behavior, run :scriptnames. This will show you a list of scripts that have been sourced. Also, are you sure filetype is unset? :echo &ft to find out.Randy Morris

1 Answers

8
votes
'smartindent' 'si'      boolean (default off)
                        local to buffer
                        {not in Vi}
                        {not available when compiled without the
                        |+smartindent| feature}
        Do smart autoindenting when starting a new line.  Works for C-like
        programs, but can also be used for other languages.  'cindent' does
        something like this, works better in most cases, but is more strict,
        see |C-indenting|.  When 'cindent' is on, setting 'si' has no effect.
        'indentexpr' is a more advanced alternative.
        Normally 'autoindent' should also be on when using 'smartindent'.
        An indent is automatically inserted:
        - After a line ending in '{'.
        - After a line starting with a keyword from 'cinwords'.
        - Before a line starting with '}' (only with the "O" command).

cinwords defaults to if,else,while,do,for,switch