Link to home
Start Free TrialLog in
Avatar of hongjun
hongjunFlag for Singapore

asked on

Vim

I am using Solaris.
Does vi or vim has got auto-indent option just like emacs?
I know it is possible to use a .vimrc file but then it will only help in indenting while you type. For example if I were to remove a if-statement, then perhaps I will end up re-indentiing manually each line. Very troublesome process.



hongjun
ASKER CERTIFIED SOLUTION
Avatar of liddler
liddler
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hongjun

ASKER

skewray, if I do not have a { ..} then the >% or <% will not work.
Avatar of hongjun

ASKER

found this rather good reference
http://vim.sourceforge.net/htmldoc/quickref.html
Avatar of skewray
skewray

'%' searches for a matching opposite character, so you can auto-indent over [], {}, or ().  If you are indenting, say,
Pascal, you could use ">/end" followed by a carriage return, assuming Pascal uses "end" like Algol did.  Vim might
be programmable so that it could search for other pairs of characters, but I have never attempted to do so.  If you
know you need to indent ten lines, you could use ">10j".
Though this may not be what you are looking for ,

there is a program "indent" which can indent your programs

http://www.gnu.org/software/indent/indent.html 
Avatar of hongjun

ASKER

I am posting this question because I have got a Unix shell practical exam this coming Friday and new accounts will be given to all students and so will result in me not having a desired .vimrc file. But then guess I will have to make code out a .vimrc myself before I start. And because of that, definitely I am not allowed to install any new programs like the "indent" program given above.

hongjun
Avatar of hongjun

ASKER

I will leave this question open a while before I finalized it.
Avatar of hongjun

ASKER

Hi to all.
There's another quite ok program named "cb".

$> cb yourprogram.c

Will display the formatted program..
Then we can always redirect it to a file..

Cheers
hongjun