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

Use of [[ and ]] w/ different formatting?

Expand Messages
  • Dominique Devienne
    Hi VIM ers, I like using [[ and ]] commands to navigate a file to the previous and next function/class, but the large code base I work on uses a Java-like
    Message 1 of 7 , Oct 16, 2008
    • 0 Attachment
      Hi VIM'ers,

      I like using [[ and ]] commands to navigate a file to the previous and
      next function/class, but the large code base I work on uses a
      Java-like formatting where opening braces don't go in column 0 of a
      separate line, but of the end of the declaration.

      So instead of:

      foo()
      {
      }

      we'll have

      foo() {
      }

      Can something be done to modify or remap [[ and ]] to still work in
      such configuration? Thanks, --DD

      PS: I'm not a folding user (yet). My brain's limited to one or two new
      VIM commands a year :)
      PPS: VIM scripting / remapping etc is high voodoo to me.

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Gary Johnson
      ... Our project uses different formatting of C and C++ functions, with braces indented like this: int bar(void) { return 42; } I wrote the attached plugin so
      Message 2 of 7 , Oct 16, 2008
      • 0 Attachment
        On 2008-10-16, Dominique Devienne <ddevienne@...> wrote:
        > Hi VIM'ers,
        >
        > I like using [[ and ]] commands to navigate a file to the previous and
        > next function/class, but the large code base I work on uses a
        > Java-like formatting where opening braces don't go in column 0 of a
        > separate line, but of the end of the declaration.
        >
        > So instead of:
        >
        > foo()
        > {
        > }
        >
        > we'll have
        >
        > foo() {
        > }
        >
        > Can something be done to modify or remap [[ and ]] to still work in
        > such configuration? Thanks, --DD

        Our project uses different formatting of C and C++ functions, with
        braces indented like this:

        int bar(void)
        {
        return 42;
        }

        I wrote the attached plugin so that the [[, ][, ]], [] and gd
        commands would all work correctly in our environment. It seems to
        work as-is for your format as well.

        HTH,
        Gary

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Dominique Devienne
        ... Thanks David and Gary. David s search the mailing list hint got me the map defs that do it for me. I m not sure what behavior difference there is (if
        Message 3 of 7 , Oct 16, 2008
        • 0 Attachment
          On Thu, Oct 16, 2008 at 3:31 PM, David Lam <david.k.lam1@...> wrote:
          > http://markmail.org/message/qcdkeabyfv3urj7u

          Thanks David and Gary. David's "search the mailing list" hint got me
          the map defs that do it for me.

          I'm not sure what behavior difference there is (if any) with your
          plugin Gary, but for an average user like myself, David's mappings
          seem to simpler and good enough (just edit _vimrc and drop 4 map
          defs). Cheers, --DD

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Gary Johnson
          ... For you re application, there might not be a difference. I just tried David s mappings from that URL on some of our project s C++ code and the behavior
          Message 4 of 7 , Oct 16, 2008
          • 0 Attachment
            On 2008-10-16, Dominique Devienne <ddevienne@...> wrote:
            > On Thu, Oct 16, 2008 at 3:31 PM, David Lam <david.k.lam1@...> wrote:
            > > http://markmail.org/message/qcdkeabyfv3urj7u
            >
            > Thanks David and Gary. David's "search the mailing list" hint got me
            > the map defs that do it for me.
            >
            > I'm not sure what behavior difference there is (if any) with your
            > plugin Gary, but for an average user like myself, David's mappings
            > seem to simpler and good enough (just edit _vimrc and drop 4 map
            > defs). Cheers, --DD

            For you're application, there might not be a difference. I just
            tried David's mappings from that URL on some of our project's C++
            code and the behavior was inconsistent: ]] and [[ would often jump
            to the end of a block rather than to the end of a function.

            Regards,
            Gary


            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • David Lam
            go look at :h section it has some more complex mappings for the [[ ]] thingys -- If your { or } are not in the first column, and you would like to use
            Message 5 of 7 , Oct 16, 2008
            • 0 Attachment
              go look at :h section

              it has some more complex mappings for the [[ ]] thingys -->

              If your '{' or '}' are not in the first column, and you would like to use "[["
              and "]]" anyway, try these mappings: >
                 :map [[ ?{<CR>w99[{
                 :map ][ /}<CR>b99]}
                 :map ]] j0[[%/{<CR>
                 :map [] k$][%?}<CR>


              On Thu, Oct 16, 2008 at 2:46 PM, Gary Johnson <garyjohn@...> wrote:

              On 2008-10-16, Dominique Devienne <ddevienne@...> wrote:
              > On Thu, Oct 16, 2008 at 3:31 PM, David Lam <david.k.lam1@...> wrote:
              > > http://markmail.org/message/qcdkeabyfv3urj7u
              >
              > Thanks David and Gary. David's "search the mailing list" hint got me
              > the map defs that do it for me.
              >
              > I'm not sure what behavior difference there is (if any) with your
              > plugin Gary, but for an average user like myself, David's mappings
              > seem to simpler and good enough (just edit _vimrc and drop 4 map
              > defs). Cheers, --DD

              For you're application, there might not be a difference.  I just
              tried David's mappings from that URL on some of our project's C++
              code and the behavior was inconsistent:  ]] and [[ would often jump
              to the end of a block rather than to the end of a function.

              Regards,
              Gary





              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---

            • tanaka tarou
              how about this? ... --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use maillist. For more information, visit
              Message 6 of 7 , Oct 16, 2008
              • 0 Attachment
                how about this?
                 
                :nmap <F8> 2][%
                 

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---

              • tanaka tarou
                sorry, I didn t check whether other people post --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use maillist.
                Message 7 of 7 , Oct 16, 2008
                • 0 Attachment

                  sorry, I didn't check whether other people post


                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---

                Your message has been successfully submitted and would be delivered to recipients shortly.