tags:

views:

411

answers:

3

How do you prettify / align / format code in vi? What is the command?

I have pasted in a hunk of code and I need to have it all formatted/aligned... obviously I am a vi neophyte.

x

+3  A: 

={motion}

:h =

P.S. You shouldn't use vi if vim is available.

wRAR
What is motion?
Xofo
`:h {motion}`. And please read about basics of vim.
wRAR
I will read the basics ... but could you explain this command?x
Xofo
`{motion}` is a command that moves the cursor such as `w` or `4j`. `=` command is applied to the range covered by `{motion}`.
wRAR
+1  A: 

If manually adjusting indents I will open a visual block with V on the first or last line I want to re-indent, move to the brace containing the block, goto the other brace with % then shift the line with > or <

If indents are off by a lot I will shift everything all the way left with < and repeat it with . and then re-indent everything.

Another solution is to use the unix fmt command as described in Your problem with Vim is that you don't grok vi., {!}fmt

Winder
Note that visual mode isn't available in vi.
wRAR
+4  A: 
Kimball Robinson