[lug] Vi and Bracket Indenting

David L. Anselmi anselmi at anselmi.us
Tue Oct 11 19:44:28 MDT 2005


Bill Thoen wrote:
> I'm trying to figure how to change vi's indenting behavior after typing a
> curly bracket when writing C code. It seems to indent code between { }
> brackets far too deeply. For example:
> int test()
> {
>           /* codes starts way out here */
> }

I have a file:

/usr/share/vim/vim63/indent/c.vim

that seems to control this by running the vim command "setlocal 
cindent".  There are various incantations 'round there to cause 
appropriate indent files to be loaded.

Seems that when you type {\n in a C file it indents by a tab for me.  So 
I'm betting that ts, sw, et. al. control how this works.

If you want a tab for each indent level (what I prefer but boy most 
people hate that) then you make ts and sw the same.  If they are 
different you're likely to get combinations of spaces and tabs for your 
indents (ugly).  But you can probably arrange to have the tab key or any 
indents use a certain number of spaces rather than any tab characters.

HTH,
Dave



More information about the LUG mailing list