Loading ...
Sorry, an error occurred while loading the content.

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

Expand Messages
  • Ben Fritz
    ... Welcome! ... 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
    Message 1 of 12 , May 22, 2013
    • 0 Attachment
      On Wednesday, May 22, 2013 10:43:48 AM UTC-5, arj...@... 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).

      --
      --
      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@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • arjicot@...
      ... Now i have ############################################ gnome-shell workaround
      Message 2 of 12 , May 23, 2013
      • 0 Attachment
        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, arj...@... 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

        ############################################
        " gnome-shell workaround http://askubuntu.com/questions/67/how-do-i-enable-full-color-support-in-terminal
        if $COLORTERM == 'gnome-terminal'
        set t_Co=256
        endif

        syntax on
        autocmd FileType cpp set formatprg=astyle\ -s2pPA1
        set number " show numbers on the left side
        set scrolloff=5 " keep at least 5 lines above/below
        set sidescrolloff=5 " keep at least 5 lines left/right

        " tab & space related settings
        set tabstop=2
        set shiftwidth=2
        set expandtab

        colorscheme distinguished

        " PLUGINS SETTINGS

        " pathogen
        " execute pathogen#infect()

        " clang_complete settings
        let g:clang_user_options="-std=c++0x"
        ############################################

        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.

        --
        --
        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@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • arjicot@...
        ... looks ok, but apparently doesn t have 1 feature that I would like to have, for example after editing and adding several snippets to different files in
        Message 3 of 12 , May 23, 2013
        • 0 Attachment
          Il giorno mercoledì 22 maggio 2013 19:22:01 UTC+2, David Fishburn ha scritto:
          > On Wed, May 22, 2013 at 11:43 AM, <arj...@...> wrote:
          >
          > ...
          >  
          > The second part it's about how under Vim it's possible to create some pre-packed files with some boring code and being able to just replace some key parts with some script, for example when creating a new C++ class I need the usual set of boring methods and ctors and the only thing that changes most of the time it's just the name of the class, so I would like to spend less time coding this repetitive portions of the code and kinda template and script the code generation for my source files
          >
          >
          >
          > There are various solutions for templates on vim.org.
          >
          >
          > Have you tried UltiSnips, which supports templates from various different templating solutions?
          >
          >
          >
          > http://www.vim.org/scripts/script.php?script_id=2715
          >
          >
          > David

          looks ok, but apparently doesn't have 1 feature that I would like to have, for example after editing and adding several snippets to different files in different times, I would like to have the ability to go back and change a value for all the files in a single command, apparently after adding this snippets there is plain text and you can't really go back and pretend to re-edit things in a scripted way.

          --
          --
          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@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • arjicot@...
          ... thanks, that documentation looks oddly paginated and not that easy to read, there is an rst version or a pdf one ? There is a more specific C++ plugin
          Message 4 of 12 , May 23, 2013
          • 0 Attachment
            Il giorno mercoledì 22 maggio 2013 19:22:04 UTC+2, Reid Thompson ha scritto:
            > On Wed, 2013-05-22 at 08:43 -0700, arjicot@... wrote:
            >
            > > Hi guys, my first post here and this is my 3rd day with vim.
            >
            > >
            >
            > > I'm under Ubuntu 13.04 64 bit so I have vim 7.3 installed, I currently use clang_complete to get some C++ related features like autocompletition but I'm stuck with code formatting rules and I can't find a way to speed up some particular activity when creating new classes or new code that can be easily templated because it follows some clear patterns.
            >
            > >
            >
            > > 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, for example I found really inconsistent what happens with the brackets, if I have..
            >
            >
            >
            >
            >
            >
            >
            > http://lug.fh-swf.de/vim/vim-c/screenshots-en.html
            >
            >
            >
            > http://www.thegeekstuff.com/2009/01/tutorial-make-vim-as-your-cc-ide-using-cvim-plugin/
            >
            >
            >
            >
            >
            > http://lug.fh-swf.de/vim/vim-doc/csupport.html
            >
            >
            >
            >
            >
            > --
            >
            > If you have received the message in error, please advise the sender by
            >
            > reply email and please delete the message. This message contains
            >
            > information which may be confidential or otherwise protected. Unless
            >
            > you are the addressee (or authorized to receive for the addressee), you
            >
            > may not use, copy, or disclose to anyone the message or any information
            >
            > contained in the message.

            thanks, that documentation looks oddly paginated and not that easy to read, there is an rst version or a pdf one ? There is a more specific C++ plugin maybe with C++11 support ? I don't care about C.

            --
            --
            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@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Christian Brabandt
            ... I don t know. Try, of any of those help you: https://github.com/vim-jp/cpp-vim http://www.vim.org/scripts/script.php?script_id=4293
            Message 5 of 12 , May 23, 2013
            • 0 Attachment
              On Thu, May 23, 2013 09:59, arjicot@... wrote:
              > thanks, that documentation looks oddly paginated and not that easy to
              > read, there is an rst version or a pdf one ? There is a more specific C++
              > plugin maybe with C++11 support ? I don't care about C.

              I don't know. Try, of any of those help you:
              https://github.com/vim-jp/cpp-vim
              http://www.vim.org/scripts/script.php?script_id=4293
              http://www.vim.org/scripts/script.php?script_id=3797

              regards,
              Christian

              --
              --
              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@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Ben Fritz
              ... After you edit your cpp file, are things set as you expect? ... -- -- You received this message from the vim_use maillist. Do not top-post! Type your
              Message 6 of 12 , May 23, 2013
              • 0 Attachment
                On Thursday, May 23, 2013 2:53:58 AM UTC-5, arj...@... wrote:
                >
                > 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.

                After you edit your cpp file, are things set as you expect?

                :verbose set formatprg? formatexpr? filetype? formatoptions?

                --
                --
                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@....
                For more options, visit https://groups.google.com/groups/opt_out.
              • Reid Thompson
                ... it supports both c and c++ http://www.vim.org/scripts/script.php?script_id=213 -- The key mappings of this plugin (PDF) :
                Message 7 of 12 , May 23, 2013
                • 0 Attachment
                  On Thu, 2013-05-23 at 00:59 -0700, arjicot@... wrote:
                  >
                  > thanks, that documentation looks oddly paginated and not that easy to read, there is an rst version or a pdf one ? There is a more specific C++ plugin maybe with C++11 support ? I don't care about C.
                  it supports both c and c++

                  http://www.vim.org/scripts/script.php?script_id=213 --> The key mappings of this plugin (PDF) : http://lug.fh-swf.de/vim/vim-c/c-hotkeys.pdf

                  The help file online : http://lug.fh-swf.de/vim/vim-c/csupport.html
                  --
                  If you have received the message in error, please advise the sender by
                  reply email and please delete the message. This message contains
                  information which may be confidential or otherwise protected. Unless
                  you are the addressee (or authorized to receive for the addressee), you
                  may not use, copy, or disclose to anyone the message or any information
                  contained in the message.


                  --
                  --
                  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@....
                  For more options, visit https://groups.google.com/groups/opt_out.
                • Reid Thompson
                  ... forgot the vim.org page http://www.vim.org/scripts/script.php?script_id=213 -- If you have received the message in error, please advise the sender by reply
                  Message 8 of 12 , May 23, 2013
                  • 0 Attachment
                    On Thu, 2013-05-23 at 14:44 +0000, Reid Thompson wrote:
                    > On Thu, 2013-05-23 at 00:59 -0700, arjicot@... wrote:
                    > >
                    > > thanks, that documentation looks oddly paginated and not that easy to read, there is an rst version or a pdf one ? There is a more specific C++ plugin maybe with C++11 support ? I don't care about C.
                    > it supports both c and c++
                    >
                    > http://www.vim.org/scripts/script.php?script_id=213 --> The key mappings of this plugin (PDF) : http://lug.fh-swf.de/vim/vim-c/c-hotkeys.pdf
                    >
                    > The help file online : http://lug.fh-swf.de/vim/vim-c/csupport.html

                    forgot the vim.org page
                    http://www.vim.org/scripts/script.php?script_id=213


                    --
                    If you have received the message in error, please advise the sender by
                    reply email and please delete the message. This message contains
                    information which may be confidential or otherwise protected. Unless
                    you are the addressee (or authorized to receive for the addressee), you
                    may not use, copy, or disclose to anyone the message or any information
                    contained in the message.


                    --
                    --
                    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@....
                    For more options, visit https://groups.google.com/groups/opt_out.
                  • Gary Johnson
                    ... 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,
                    Message 9 of 12 , May 23, 2013
                    • 0 Attachment
                      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@....
                      For more options, visit https://groups.google.com/groups/opt_out.
                    Your message has been successfully submitted and would be delivered to recipients shortly.