Solved

Vim

Posted on 2004-09-28
9
480 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 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
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

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). …
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

707 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