:: [DNG] C indentation customisation […
Top Page
Delete this message
Reply to this message
Author: dvalin
Date:  
To: dng
Subject: [DNG] C indentation customisation [Was: Re: vdev status update in daedalus
On 21.07.25 03:17, Steve Litt wrote:

> I prefer the second way for one reason: It's how Vim naturally formats


> C and several other languages.


It is some decades since I last hacked enough C to fuss over indentation, but my old notes retain echoes of how I tuned Vim's indentation behaviour. While probably not to everyone's taste as is, it might prompt the dissatisfied to twiddle some of the knobs:

Example Indentation Customisation:

----------------------------------

The following should mostly work _if_ used within top level { ... },

e.g. in a function.

set noai

set cindent

setlocal cinoptions=>s,n-s,{s,:s,=s,g0,hs,p5,t0,+s,(0,u0,w1,m0

>s => Normal indent = shiftwidth


n-s => Outdent shiftwidth after an "if", "while", etc.,

if it is NOT inside a set of braces.

{s => Indent for opening braces that are inside other braces.

:s => Indent for "case" after switch = shiftwidth

=s => Indent after case = shiftwidth

Defaults: (May vary by now?)

---------

cinwords=if,else,while,do,for,switch

cinkeys=0{,0},0),:,0#,!^F,o,O,e

cinoptions=>s,e0,n0,f0,{0,}0,^0,L-1,:s,=s,l0,b0,gs,hs,N0,ps,ts,is,+s,

c3,C0,/0,(2s,us,U0,w0,W0,k0,m0,j0,J0,)20,*70,#0

Check where last set:   :verbose set cinoptions

My vim-8.1.0875 is not quite the latest (7 yrs old now), but its cinoptions-values options include a fair bunch of cino-? suboptions, which allow significant tuning of indentation. with {N & }N cleaning things up nicely. There's pages of it - enough to satisfy even a demanding futzer, I suspect. (Some of the possibilities give me the horrors, though.)

Anyway, it's control such as this which goes far to making Vim the only editor for me. (That and folding, and ...) Oh, and a little mapping, activated only when vimming in mutt, to jump to the Subject line and insert "[Was: ", then go to insert before that, all on an Alt-W.

Erik