?
Solved

Vim

Posted on 2004-09-28
9
Medium Priority
?
482 Views
Last Modified: 2010-04-20
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
0
Comment
Question by:hongjun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 18

Accepted Solution

by:
liddler earned 500 total points
ID: 12169302
:set autoindent

...but I've not used it I just got that from http://yakko.cs.wmich.edu/presentations/20010927-vim/
0
 

Assisted Solution

by:skewray
skewray earned 500 total points
ID: 12169886

Set autoindent only works during insert, and is set by default.

This isn't what you asked, but you can indent/unindent whole sections at once my using marks:

    Cursor to last line
    Type "ma"
    Cursor to first line
    Type ">'a" or "<'a"

If you switch the first and last line, the cursor will teleport to the mark afterwards, an irritating feature/bug,
since then the operation cannot be repeated for larger indents.  (Although for biger indents, try "3>%").  If
you are programming in C/C++, you can do

   Cursor to one of "{" or "}"
   Type ">%"

which is quicker and doesn't require a mark.  

0
 
LVL 33

Author Comment

by:hongjun
ID: 12170230
skewray, if I do not have a { ..} then the >% or <% will not work.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 33

Author Comment

by:hongjun
ID: 12170283
found this rather good reference
http://vim.sourceforge.net/htmldoc/quickref.html
0
 

Expert Comment

by:skewray
ID: 12174220
'%' 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".
0
 
LVL 11

Expert Comment

by:avizit
ID: 12176034
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 
0
 
LVL 33

Author Comment

by:hongjun
ID: 12176092
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
0
 
LVL 33

Author Comment

by:hongjun
ID: 12176093
I will leave this question open a while before I finalized it.
0
 
LVL 33

Author Comment

by:hongjun
ID: 12205847
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
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question