Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-09-2009, 01:41 PM   #1
Registered: Dec 2005
Posts: 34

Rep: Reputation: 15
vim , indent and printing

Whenever I print a C source file, the spacing and tabs
are all messed up.I've tried to fix the formatting with
the indent program, but that makes it worse. Also, vim
doesn't seem to recognise the formatting of indent. I've
noticed also that using 'less' to view a file demonstrates
the same messed up formatting as when I print. How can I get
everything formatted properly and working together? I wished
I could tell vim to reformat according to vim C style but
don't know if it can be done. Any suggestions?
Old 05-09-2009, 03:34 PM   #2
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
You probably should define your tab spacing using vim's "set tabstop=n" option, where 'n' is the position where you want your tabs to, well, stop.

With respect to your existing files, which having various tab-stops, use the same option describe above to fix them. If you are still unsatisfied with the results, there are tools that you can use to beautify your code. One tool I like is "uncrustify". I believe it is available at SourceForge.
Old 05-09-2009, 04:10 PM   #3
Registered: Dec 2005
Posts: 34

Original Poster
Rep: Reputation: 15
solved: vim and printing

I think I got this figured out, at least sort of. In the .vimrc in the home dir, add: set expandtab
This converts tabs to spaces. Also, there is a way to reformat in Vim:
type gg=G and this reformats the entire file. I think I found this in the help for cindent. It's in there somewhere. Dang! reading the manual is
actually helpful! What I really need is to print out manual sections
or cough up the bucks for a book. The free online book has some useful
stuff but I'm thinking about Robbins' book.
Old 05-09-2009, 05:23 PM   #4
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

You're absolutely correct:
Tabs are Evil (but the Tab Key is good).
- Alan Babich
Anyway, I'm glad you found the "set expandtab" and your files should now be consistently formatted.

- Beware editing makefiles (which rely on tabs for their rules), or source-controlled source files (where expanding tabs can result in massive "diff's").


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Editor comparison: vim VS vim-lite, Cleaning vim Ruler2112 *BSD 4 04-13-2009 04:26 PM
vim printing problem baikonur Linux - Software 0 05-10-2007 02:57 AM
Vim re indent? dlublink Linux - Software 3 10-02-2006 01:37 PM
backspace key printing ^? in vim clockworks Linux - General 3 01-23-2004 12:07 PM
indent chrismiceli Linux - General 1 05-12-2003 07:22 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:26 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration