Thursday, May 23, 2013

Re: How to get Allman style while typing and templated C++ code in Vim 7.3

On 2013-05-23, arjicot wrote:
> Il giorno mercoledì 22 maggio 2013 20:01:12 UTC+2, Ben Fritz ha scritto:
> > On Wednesday, May 22, 2013 10:43:48 AM UTC-5, arjicot wrote:
> > > Hi guys, my first post here and this is my 3rd day with vim.
> > >
> >
> > Welcome!
> >
> > >
> > > I'm used to astyle ( http://astyle.sourceforge.net/ ) and I
> > > like the Allman style and I would love the ability to get some
> > > smart formatting while typing C++ code
> >
> > It looks from the description of astyle, that you should just be
> > able to use astyle still, automatically as you type in Vim.
> >
> > See :help 'formatprg' and :help 'formatoptions'.
> >
> > > My actual .vimrc is this one
> > > ...
> > > syntax on
> > > ...
> > > set autoindent smartindent " auto/smart indent
> > > ...
> > > set autoindent
> > > set cindent
> >
> > You have autoindent turned on twice, and smartindent (which I
> > would recommend NOT using, it's not smart at all), and also
> > cindent. cindent will override all the previous ones.
> >
> > Additionally, normally you don't turn cindent on in your .vimrc.
> >
> > Instead, right before your "syntax on" command, put:
> >
> > filetype indent on
> >
> > or
> >
> > filetype plugin indent on
> >
> > This will turn on Vim's smart filetype-based indenting.
> >
> > If you want to use astyle you may not want to put the "indent"
> > in there however, or you could override it for C/C++ code using
> > the "after" directory (:help after-directory).
>
> Now i have
>
> ############################################

> autocmd FileType cpp set formatprg=astyle\ -s2pPA1

> ############################################
>
> but I got nothing out of this formatpgr, it's like nothing
> changed, not even with gg=G, I don't know where to look anymore,
> vim still uses the old formatting tool, it's supposed to be ok as
> far as I know.

The 'formatprg' option does not do automatic formatting unless the
'a' flag of 'formatoptions' is set, which I would not recommend in
this case. Further, the = command uses 'equalprg', not 'formatprg'.

So, to format your code using astyle as the 'formatprg', you will
need to manually reformat sections as you go with gq, not =.

Alternatively, you could set 'equalprg' to astyle, then use the =
command.

I think the behavior may be different between using astyle as the
'formatprg' vs. the 'equalprg', but I don't know what it is off the
top of my head.

Regards,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment