Sponsored Content
Special Forums UNIX and Linux Applications Setting vi indentation to k&r style? Post 302271630 by kermit on Friday 26th of December 2008 08:04:54 PM
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.
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
Text::FindIndent(3pm)					User Contributed Perl Documentation				     Text::FindIndent(3pm)

NAME
Text::FindIndent - Heuristically determine the indent style SYNOPSIS
use Text::FindIndent; my $indentation_type = Text::FindIndent->parse($text, skip_pod => 1); if ($indentation_type =~ /^s(d+)/) { print "Indentation with $1 spaces "; } elsif ($indentation_type =~ /^t(d+)/) { print "Indentation with tabs, a tab should indent by $1 characters "; } elsif ($indentation_type =~ /^m(d+)/) { print "Indentation with $1 characters in tab/space mixed mode "; } else { print "Indentation style unknown "; } DESCRIPTION
This is a module that attempts to intuit the underlying indent "policy" for a text file (most likely a source code file). METHODS
parse The class method "parse" tries to determine the indentation style of the given piece of text (which must start at a new line and can be passed in either as a string or as a reference to a scalar containing the string). Returns a letter followed by a number. If the letter is "s", then the text is most likely indented with spaces. The number indicates the number of spaces used for indentation. A "t" indicates tabs. The number after the "t" indicates the number characters each level of indentation corresponds to. A "u" indicates that the indenation style could not be determined. Finally, an "m" followed by a number means that this many characters are used for each indentation level, but the indentation is an arbitrary number of tabs followed by 0-7 spaces. This can happen if your editor is stupid enough to do smart indentation/whitespace compression. (I.e. replaces all indentations many tabs as possible but leaves the rest as spaces.) The function supports parsing of "vim" modelines. Those settings override the heuristics. The modeline's options that are recognized are "sts"/"softtabstob", "et"/"noet"/"expandtabs"/"noexpandtabs", and "ts"/"tabstop". Similarly, parsing of "emacs" Local Variables is somewhat supported. "parse" use explicit settings to override the heuristics but uses style settings only as a fallback. The following options are recognized: "tab-width", "indent-tabs-mode", "c-basic-offset", and "style". There is one named option that you can pass to "parse()": "skip_pod". When set to true, any section of POD (see perlpod) will be ignored for indentation finding. This is because verbatim paragraphs and examples embedded in POD or quite often indented differently from normal Perl code around the POD section. Defaults to false. Example: my $mode = Text::FindIndent->parse($text, skip_pod => 1); to_vim_commands A class method that converts the output of "parse($text)" into a series of vi(m) commands that will configure vim to use the detected indentation setting. Returns zero (failure) or more lines of text that are suitable for passing to "VIM::DoCommand()" one by one. As a convenience, if the argument to "to_vim_commands" doesn't look like the output of "parse", it is redirected to "parse" first. To use this, you can put the following line in your .vimrc if your vim has Perl support. Suggestions on how to do this in a more elegant way are welcome. The code should be on one line but is broken up for displaying: map <F5> <Esc> :perl use Text::FindIndent;VIM::DoCommand($_) for Text::FindIndent->to_vim_commands(join " ", $curbuf->Get(1..$curbuf->Count()));<CR> (Patches to implement the equivalent for emacs would be welcome as well.) SUPPORT
Bugs should be reported via the CPAN bug tracker at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-FindIndent> For other issues, contact the author. AUTHOR
Steffen Mueller <smueller@cpan.org> Adam Kennedy <adamk@cpan.org> COPYRIGHT
Copyright 2008 - 2010 Steffen Mueller. Copyright 2008 - 2010 Adam Kennedy, This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.10.1 2011-01-04 Text::FindIndent(3pm)
All times are GMT -4. The time now is 11:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy