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
Solved

Vim

Posted on 2004-09-28
9
477 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
9 Comments
 
LVL 18

Accepted Solution

by:
liddler earned 125 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 125 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why VNC doesn't work in Redhat? 11 71
how to install java on RHEL image on EC2 4 39
AWS EC2 HTTP & HTTPS 2 44
Samba 4, Users Permission, 5 44
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

792 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