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

How would a vim guru type this c++ snippet?

Expand Messages
  • Chris Stankevitz
    Hello, I wish I worked with a vim guru because I would devote a day to just watching him work. I have tried to find vim guru videos on youtube but that
    Message 1 of 11 , Dec 3, 2013
    • 0 Attachment
      Hello,

      I wish I worked with a vim guru because I would devote a day to just watching him work. I have tried to find "vim guru" videos on youtube but that hasn't really panned out. So instead I'll turn to the group.

      In the attached files, I start with a class TCTest and I add a default constructor, a copy constructor, and an assignment operator.

      Regarding the change from test1.cpp -> test2.cpp, will you please do one of the following:

      a) come to my office and change test1.cpp into test2.cpp so I can see how you do it.

      b) record yourself changing test1.cpp -> test2.cpp and send me the video

      c) tell me the characters you would type to change test1.cpp ->test2.cpp

      d) give me some buzzwords and thoughts about how you would change test1.cpp -> test2.cpp

      Bonus points if your approach is O(1) with respect to the number of members in the class.

      Thank you!

      Chris

      --
      --
      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.
    • Fredrik Andersson
      You can always see if you can submit the problem to vimgolf.com (it was down for me at the moment so I could not try it out) and see what solution people come
      Message 2 of 11 , Dec 4, 2013
      • 0 Attachment
        You can always see if you can submit the problem to vimgolf.com (it was down for me at the moment so I could not try it out) and see what solution people come up with. =)


        On Wed, Dec 4, 2013 at 2:24 AM, Chris Stankevitz <chrisstankevitz@...> wrote:
        Hello,

        I wish I worked with a vim guru because I would devote a day to just watching him work.  I have tried to find "vim guru" videos on youtube but that hasn't really panned out.  So instead I'll turn to the group.

        In the attached files, I start with a class TCTest and I add a default constructor, a copy constructor, and an assignment operator.

        Regarding the change from test1.cpp -> test2.cpp, will you please do one of the following:

        a) come to my office and change test1.cpp into test2.cpp so I can see how you do it.

        b) record yourself changing test1.cpp -> test2.cpp and send me the video

        c) tell me the characters you would type to change test1.cpp ->test2.cpp

        d) give me some buzzwords and thoughts about how you would change test1.cpp -> test2.cpp

        Bonus points if your approach is O(1) with respect to the number of members in the class.

        Thank you!

        Chris

        --
        --
        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.

        --
        --
        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.
      • Marc Weber
        ... github.com/MarcWeber/vim-addon-other implements cp and mv (quick and dirty, but works) too much work, I type mv then change the name and hit I also
        Message 3 of 11 , Dec 4, 2013
        • 0 Attachment
          Excerpts from Chris Stankevitz's message of Wed Dec 04 02:24:00 +0100 2013:
          > Hello,
          >
          > I wish I worked with a vim guru because I would devote a day to just watching him work. I have tried to find "vim guru" videos on youtube but that hasn't really panned out. So instead I'll turn to the group.
          >
          > In the attached files, I start with a class TCTest and I add a default constructor, a copy constructor, and an assignment operator.
          >
          > Regarding the change from test1.cpp -> test2.cpp, will you please do one of the following:


          > a) come to my office and change test1.cpp into test2.cpp so I can see how you do it.
          > b) record yourself changing test1.cpp -> test2.cpp and send me the video
          > c) tell me the characters you would type to change test1.cpp ->test2.cpp
          github.com/MarcWeber/vim-addon-other implements \cp and \mv (quick and dirty, but works)
          too much work, I type \mv then change the name and hit <cr>

          I also have : >fd And >fn mappings

          cmap >fn <c-r>=expand('%:p')<cr>
          cmap >fd <c-r>=expand('%:p:h').'/'<cr>

          to insert the directory of the current file and the current file to the
          command line.

          > d) give me some buzzwords and thoughts about how you would change test1.cpp -> test2.cpp
          That's enough :)

          > Bonus points if your approach is O(1) with respect to the number of members in the class.
          ... But what about makefiles etc? Do you want this too?

          I'ev mapped \gr to grep -r in current dir which is fast enough for many
          use cases. (also see vim-addon-other)

          Marc Weber

          --
          --
          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.
        • hermitte@...
          Hello, ... First of all. You know that in your particular case, you don t need nor you don t want any of these ? (because the default copy-constructor and
          Message 4 of 11 , Dec 4, 2013
          • 0 Attachment
            Hello,

            > Regarding the change from test1.cpp -> test2.cpp, will you please do
            > one of the following:

            First of all.
            You know that in your particular case, you don't need nor you don't want any of these ? (because the default copy-constructor and assignment operator will be more efficient)
            Well. The default constructor is almost acceptable, but I tend to prefer init-constructor.

            Otherwise, with lh-cpp (see my sig), expecting you have an up-to-date ctag database, you can put the cursor within your class definition, and type:
            :Constructor
            It will open a dialog buffer where you'll have to select (by hitting <space>) the attributes you want in the init-constructor. Then hit <enter>, et voilà.

            BTW, I've a little issue with your naming policies. The default settings will automatically convert m_Foo to foo (regarding parameters names), but not mFoo. I have to find out how to fix strip_re (defined with:
            b:cpp_naming_strip_re='^\%(get\|set\|[mgsp]_\|_\+\)\=\(.\{-}\)\%(_\=\)$' )
            So that substitute('mFoo', {b:cpp_naming_}strip_re, '\l\1') will also work correctly
            (you can play with :DOX to automatically generate the doxygen comment associated to the new function)

            Any way.

            At that time, I've haven't written (yet) neiher a wizard for a swap() function, nor for the copy-constructor. It should be easy to do on the same model of the one of :Constructor
            Regarding the assignment operator, lh-cpp (through mu-template) provide several snippets:
            - copy-and-swap
            - assignment-operator -- you may want to use :MOVETOIMPL to move the inlined assignment operator to the .cpp file
            - copy-constructor
            - destructor

            HTH,
            (more latter I guess)
            --
            Luc Hermitte
            http://lh-vim.googlecode.com/

            --
            --
            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.
          • hermitte@...
            ... OK. Now it s done. install lh-cpp (preferably with VAM, unless you want to do decrypt the multiple dependencies of my plugin suite) You ll have: -
            Message 5 of 11 , Dec 4, 2013
            • 0 Attachment
              > [...]
              > At that time, I've haven't written (yet) neiher a wizard for a swap()
              > function, nor for the copy-constructor. It should be easy to do on
              > the same model of the one of :Constructor
              > Regarding the assignment operator, lh-cpp (through mu-template)
              > provide several snippets:
              > - copy-and-swap
              > - assignment-operator -- you may want to use :MOVETOIMPL to move the
              > inlined assignment operator to the .cpp file
              > - copy-constructor
              > - destructor

              OK.
              Now it's done. install lh-cpp (preferably with VAM, unless you want to do decrypt the multiple dependencies of my plugin suite)
              You'll have:
              - :Constructor, or :ConstructorInit, or :Constuctor init
              - :Constructor default, or :ConstructorDefault
              - :Constructor copy, or :ConstructorCopy
              - :Constructor assign, or :AssignmentOperator

              They'll do what you asked for.
              An up-to-date ctag database is still required

              Regarding assignment operators, I'd instead recommend you use copy-and-swap idiom. (expand the snippet assignment-operator with mu-template), it'll do the trick -- except, I haven't written a Class::swap() generator yet)

              You may have to define a local_vimrc (or an equivalent project oriented feature) to tune your naming conventions -- mu-template should assist you regarding this issue (still in a beta stage).


              I'll take care C++11 forward constructor another day.

              HTH

              --
              Luc Hermitte
              http://lh-vim.googlecode.com/

              --
              --
              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.
            • hermitte@...
              ... Marc, Actually, OP s question is about smart generation of C++ functions (constructors, and assignment operator) given the class attributes. It s not about
              Message 6 of 11 , Dec 4, 2013
              • 0 Attachment
                > > Regarding the change from test1.cpp -> test2.cpp, will you please
                > > do one of the following:
                > > [...]
                > github.com/MarcWeber/vim-addon-other implements \cp and \mv (quick
                > and dirty, but works)
                > too much work, I type \mv then change the name and hit <cr>

                Marc,
                Actually, OP's question is about smart generation of C++ functions (constructors, and assignment operator) given the class attributes. It's not about renaming refactorings.

                --
                Luc Hermitte
                http://lh-vim.googlecode.com/

                --
                --
                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.
              • Chris Stankevitz
                ... Thank you for your help! I will take a look at lh-vim. Without internet access on a new install of vim, how would a vim guru would convert this: float
                Message 7 of 11 , Dec 4, 2013
                • 0 Attachment
                  On Wed, Dec 4, 2013 at 9:30 AM, <hermitte@...> wrote:
                  > Actually, OP's question is about smart generation of C++ functions (constructors, and assignment operator) given the class attributes. It's not about renaming refactorings.


                  Thank you for your help! I will take a look at lh-vim.

                  Without internet access on a new install of vim, how would a vim guru
                  would convert this:

                  float mTemperature;

                  unsigned char mType;

                  double mDistanceFromCenter;

                  long long int mId;

                  std::string mName;

                  Into this:
                  mTemperature(Other.mTemperature),
                  mType(Other.mType),
                  mDistanceFromCenter(Other.mDistanceFromCenter),
                  mId(Other.mId),
                  mName(Other.mName),

                  I suspect, the guru would do one of:

                  1. copy the parameters into a blank text document. Strip the variable
                  types, semicolon, and whitespace. Past the results into a spreadsheet
                  program. Use a formula '=A1 & "(Other." & A1 & "),"'. Repeat
                  formula, copy, paste into vim.

                  2. A gnarly regular expression

                  3. Some clever 'q' gymnastics

                  I tried vimgolf, but for some reason cannot create a twitter account
                  at the moment, which is a requirement.

                  Thank you again for your help everyone,

                  Chris

                  --
                  --
                  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.
                • Marcin Szamotulski
                  ... In most cases one has to type a bit more, usually macros are more efficient. ... (And you still need to delete the lines) ... Indeed, it seems a macro
                  Message 8 of 11 , Dec 4, 2013
                  • 0 Attachment
                    On 14:02 Wed 04 Dec , Chris Stankevitz wrote:
                    > Thank you for your help! I will take a look at lh-vim.
                    >
                    > Without internet access on a new install of vim, how would a vim guru
                    > would convert this:
                    >
                    > float mTemperature;
                    >
                    > unsigned char mType;
                    >
                    > double mDistanceFromCenter;
                    >
                    > long long int mId;
                    >
                    > std::string mName;
                    >
                    > Into this:
                    > mTemperature(Other.mTemperature),
                    > mType(Other.mType),
                    > mDistanceFromCenter(Other.mDistanceFromCenter),
                    > mId(Other.mId),
                    > mName(Other.mName),
                    >
                    > I suspect, the guru would do one of:
                    >
                    > 1. copy the parameters into a blank text document. Strip the variable
                    > types, semicolon, and whitespace. Past the results into a spreadsheet
                    > program. Use a formula '=A1 & "(Other." & A1 & "),"'. Repeat
                    > formula, copy, paste into vim.
                    >
                    > 2. A gnarly regular expression
                    In most cases one has to type a bit more, usually macros are more
                    efficient.
                    :%s/\v\w.*\s+(\w+);/\1(Other.\1),
                    (And you still need to delete the lines)
                    > 3. Some clever 'q' gymnastics
                    Indeed, it seems a macro might be a good idea:
                    qq$Bd^yeea(Other. ") lr,
                    ddq

                    And then play the macro with 4@q .

                    Cheers,
                    Marcin

                    --
                    --
                    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.
                  • Chris Stankevitz
                    ... Thank you. ) lr, seems to not work (I assume email stripped the correct characters)... but I took your idea and did this:
                    Message 9 of 11 , Dec 4, 2013
                    • 0 Attachment
                      On Wed, Dec 4, 2013 at 5:44 PM, Marcin Szamotulski <mszamot@...> wrote:
                      > qq$Bd^yeea(Other. ") lr,

                      Thank you. ' ") lr,' seems to not work (I assume email stripped the
                      correct characters)... but I took your idea and did this:
                      qq$Bd^yeea(Other.<ESC>plDa),<ESC>jddq4@q

                      - plDa seems wordy, but gets the job done.

                      - 4@q is nice, but I have to know the number '4'. In this case it's
                      clear, but in the general case I will have to get out my pocket
                      calculator to compute the correct number.

                      Thank you again,

                      Chris

                      --
                      --
                      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.
                    • Chris Stankevitz
                      ... Luc, I am looking at your site and am overwhelmed with fear and excitement. Fear because I understand very little of the pages... on the surface it appears
                      Message 10 of 11 , Dec 4, 2013
                      • 0 Attachment
                        On Wed, Dec 4, 2013 at 6:39 AM, <hermitte@...> wrote:
                        > Luc Hermitte
                        > http://lh-vim.googlecode.com/

                        Luc,

                        I am looking at your site and am overwhelmed with fear and excitement.
                        Fear because I understand very little of the pages... on the surface
                        it appears to be english, but it's really some kind of
                        english-vim-hybrid that I don't understand. Excitement because it
                        seems like you have really set up your "IDE" to behave exactly like
                        you want... gives me hope.

                        I'm using Eclipse CDT right now (with cmake and ninja). I'm happy
                        with the speed of navigating and compiling, and the gdb integration...
                        but I am unhappy with a few steps that require the mouse. Not just
                        unhappy... but ready to dump the entire system and just figure out how
                        to do it using vim.

                        I'd love to watch you use your IDE to get a sense of what it
                        entails... before diving in and learning the new english-vim-hybrid
                        language (including the various syntax, VAM, plugins, etc).

                        Thanks again,

                        Chris

                        --
                        --
                        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.
                      • hermitte@...
                        ... Hum... I may not have taken the more didactic way to present things. Most end-users don t need to look at what vim-lib or UT does. They ll mainly be
                        Message 11 of 11 , Dec 5, 2013
                        • 0 Attachment
                          > Luc,
                          >
                          > I am looking at your site and am overwhelmed with fear and
                          > excitement.
                          > Fear because I understand very little of the pages... on the surface
                          > it appears to be english, but it's really some kind of
                          > english-vim-hybrid that I don't understand.

                          Hum... I may not have taken the more didactic way to present things. Most end-users don't need to look at what vim-lib or UT does. They'll mainly be interested in lh-cpp, refactor, local_vimrc. May be BuildWrapperTools (which is poorly documented). lh-tags if they already know what tags are. mu-template may be years ago -- now trendy template-expander plugins have "snip" in their name, but I still use and maintain mu-template because I have a lot of template/snippet files which are able to "call" other template files with ... parameters.

                          > Excitement because it
                          > seems like you have really set up your "IDE" to behave exactly like
                          > you want... gives me hope.

                          Almost. I still have a few adjustments to make to have a generic plugin that wrap CMake and CTest.


                          > I'm using Eclipse CDT right now (with cmake and ninja). I'm happy
                          > with the speed of navigating and compiling, and the gdb
                          > integration...
                          > but I am unhappy with a few steps that require the mouse. Not just
                          > unhappy... but ready to dump the entire system and just figure out
                          > how to do it using vim.
                          >
                          > I'd love to watch you use your IDE to get a sense of what it
                          > entails... before diving in and learning the new english-vim-hybrid
                          > language (including the various syntax, VAM, plugins, etc).

                          I have started thinking for a scenario for a screencast, but first I need to finish 2-3 things in order to automate as many steps as possible (at that point, i'd like to help the generation of CMakeLists files, and their integration with what I use to manage "projects").
                          Knowing myself, there won't be any screencast before a couple of years ... :(

                          Regarding VAM, it's actually Marc Weber's vim-addon-manager : one of the two plugins manager that handle dependencies. Unfortunately, my plugins are an headache to install without solutions like VAM.

                          --
                          Luc Hermitte
                          http://lh-vim.googlecode.com/

                          --
                          --
                          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.