Solved

Vim

Posted on 2004-09-28
9
468 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
 
LVL 33

Author Comment

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

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

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)

Join & Write a Comment

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.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now