0

I have a bunch of ugly code in vim: it's not indented consistently at all. TextMate has this wonderful "code cleanup" function... and I'm sure vim is just as powerful, I just don't know how to automatically clean up my entire file (putting consistent tabs, with consistent length, after curly braces...and then unindenting after every code block is the main thing I want).

Zachary Burt
  • 51
  • 1
  • 2
  • 1
    If you post some (1) current code with your (2) expected formatting and (3) how vm actually formats, that would be helpful. – BryanH Jun 09 '12 at 04:18

3 Answers3

2

Have you tried gg=G in normal mode?

Gebb
  • 6,371
  • 3
  • 44
  • 56
0

In addition to Gebb's answer, make sure the following is in your .vimrc:

filetype indent plugin on

Also, to strip out any trailing whitespace automatically, add this:

autocmd BufWritePre * :%s/\s\+$//e
Community
  • 1
  • 1
BryanH
  • 5,826
  • 3
  • 34
  • 47
0

In Vim, indentation is defined by filetype-specific scripts. The default JavaScript indent file is not very up to date and doesn't play very well with "modern" ways of writing JS (lots of nested objects, anonymous functions…). Try other indent files and see if it solves your issue.

romainl
  • 186,200
  • 21
  • 280
  • 313