Solved

Vim

Posted on 2004-09-28
9
476 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
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…
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…

816 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

8 Experts available now in Live!

Get 1:1 Help Now