Zachary Burt
Zachary Burt

Reputation: 51

TextMate-style code beautifucation in vim?

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).

Upvotes: 0

Views: 170

Answers (3)

romainl
romainl

Reputation: 196546

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.

Upvotes: 0

BryanH
BryanH

Reputation: 6062

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

Upvotes: 0

Gebb
Gebb

Reputation: 6546

Have you tried gg=G in normal mode?

Upvotes: 2

Related Questions