Setting vi indentation to k&r style?


 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Setting vi indentation to k&r style?
# 1  
Old 12-19-2008
Setting vi indentation to k&r style?

A bit of searching on Google did not seem to yield any really helpful results on how to set vim to use k&r indentation style. I know Emacs has such a feature, but does vim? If so, how do I turn it on? I am just starting to learn vi, and when I am coding in C it looks really ugly without some sort of indent style going on....
# 2  
Old 12-23-2008
You can make a start with
Code:
:set autoindent

or
Code:
:set cindent

and
Code:
:set shiftwidth=4

which sets the number of spaces to indent by.
You can then do all manner of C-specific fine-tuning by setting cinoptions, described in detail in the vim documentation, or you could search for some ready-made cinoptions that give a K&R style.
# 3  
Old 12-26-2008
Quote:
Originally Posted by spirtle
You can make a start with
Code:
:set autoindent

or
Code:
:set cindent

and
Code:
:set shiftwidth=4

which sets the number of spaces to indent by.
You can then do all manner of C-specific fine-tuning by setting cinoptions, described in detail in the vim documentation, or you could search for some ready-made cinoptions that give a K&R style.
Thanks - the search term 'cinoptions' worked well.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Indentation for Lists in html

An writing some html instructions to have text beside an image. The image is located on the left and I want the tect to appear on the right side of the image. The text includes a list. The problem is that the list boxes and not shifted. The text within the list align on the left with the... (20 Replies)
Discussion started by: kristinu
20 Replies

2. Solaris

Setting up Solaris & ZFS for the first time

Hello All I’ve made the decision to switch my storage server from FreeNAS to Solaris. I opted to use FreeNAS as it has ZFS and until BTRFS is stable, it’s the best option (IMHO) for backup and network storage. The switch was facilitated by the USB stick that FreeNAS was on got lost during a... (1 Reply)
Discussion started by: BlueDalek
1 Replies

3. Homework & Coursework Questions

Indentation using awk

1. The problem statement, all variables and given/known data: I need to write an awk program who does this (sorry its too big) http://i.stack.imgur.com/yzSqB.jpg 2. Relevant commands, code, scripts, algorithms: .. 3. The attempts at a solution (include all code and scripts): declaring a... (2 Replies)
Discussion started by: guy9050
2 Replies

4. UNIX for Dummies Questions & Answers

Indentation using awk

I need to write an awk program who does this http://i.stack.imgur.com/yzSqB.jpg I'd be very grateful for any help, Thanks a lot (1 Reply)
Discussion started by: guy9050
1 Replies

5. Shell Programming and Scripting

Change indentation in scripts

Hi, I am a professional in writing shell scripts, and I am using a one-space indentation like this for i in file1 file2 do if then echo "$i" fi done so very deeply nested stuff still fits on my screen. At release time I usually double the indentation via sed 's/^ */&&/' to make... (8 Replies)
Discussion started by: MadeInGermany
8 Replies

6. Shell Programming and Scripting

Indentation help

Hi I have coded 300 line script.Its not indented properly.i am not good at indentation. I would appreciate your help on this. i want to use a 4 space indentataion.Hence if i "set tabstop=4" and use tabs for coding and if some one else open this script in their system it looks unindented since... (11 Replies)
Discussion started by: pinnacle
11 Replies

7. Shell Programming and Scripting

Regarding indentation using unix script

I have piece of Informatica code in a file as : IIF(substr(flag,0,2)=1,false,IIF(flag= 1 ,0,NULL)) Please provide me with idea how to write a unix script which reads this file and write indented code into another file. The output in the second file should look as: ... (1 Reply)
Discussion started by: srikanth.ch
1 Replies

8. Solaris

Setting timezone Sunos 5.8 & adjusting

I am new to this so i figure this is an easy one.. How do i change the time zone from Central to Eastern time in SunOS 5.8 ? I thought I needed to edit the /etc/TIMEZONE and them issue TZ=US/Eastern but I want to check. Is a reboot required afterwards? If I want to change the system time... (3 Replies)
Discussion started by: jay6ird
3 Replies

9. Programming

A question of indentation

Hi, Using GNU indent(1) I tried to indent a C source file which has no indentation (all lines start at column 1). The result I am trying to achieve, should look like this with the exception that only tabs are used for indentation (no spaces). Unfortunately, I couldn't find the appropriate... (1 Reply)
Discussion started by: Michael Iatrou
1 Replies
Login or Register to Ask a Question