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

swap word

Expand Messages
  • STL-BOOST
    Hi all, is there any wat do this : p == NULL change to NULL == p. --~--~---------~--~----~------------~-------~--~----~ You received this message from the
    Message 1 of 5 , Jan 30, 2008
    • 0 Attachment
      Hi all, is there any wat do this : p == NULL change to NULL
      == p.


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Charles E. Campbell, Jr.
      ... Take a look at: http://vim.sourceforge.net/tips/tip.php?tip_id=329 Regards, Chip Campbell --~--~---------~--~----~------------~-------~--~----~ You
      Message 2 of 5 , Jan 30, 2008
      • 0 Attachment
        STL-BOOST wrote:

        > Hi all, is there any wat do this : p == NULL change to NULL
        >== p.
        >
        >
        >

        Take a look at:
        http://vim.sourceforge.net/tips/tip.php?tip_id=329

        Regards,
        Chip Campbell


        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • John Beckett
        ... We have a new tip on just this topic (although it s assignment, not equality): http://vim.wikia.com/wiki/Swap_LHS_and_RHS_of_an_Assignment_statement Here
        Message 3 of 5 , Jan 30, 2008
        • 0 Attachment
          STL-BOOST wrote:
          > is there any wat do this : p == NULL change
          > to NULL == p.

          We have a new tip on just this topic (although it's assignment, not
          equality):
          http://vim.wikia.com/wiki/Swap_LHS_and_RHS_of_an_Assignment_statement

          Here is a related tip that has a spectacular regex to exchange adjacent
          words:
          http://vim.wikia.com/wiki/Exchanging_adjacent_words

          On the wiki, the tip that Chip mentioned (tip 329) has been merged into
          "Swapping characters, words and lines":
          http://vim.wikia.com/wiki/VimTip47

          John


          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Gene Kwiecinski
          ... Literally, yeah, should be easy, just ... but if you want to unify the spacing, etc., and make sure you grab only p and not frap , etc., you can
          Message 4 of 5 , Jan 31, 2008
          • 0 Attachment
            >Hi all, is there any wat do this : p == NULL change to NULL == p.

            Literally, yeah, should be easy, just

            :g/p == NULL/s//NULL == p/g

            but if you want to "unify" the spacing, etc., and make sure you grab
            only "p" and not "frap", etc., you can embellish it with

            :g/\(\<p\>\)\( *\)\(==\)\( *\)\(NULL\)/s//\5 \3 \1/g

            :g/ global command
            \(\<p\>\) look for a complete word "p"
            \( *\) ...and optional space (0 or more)
            \(==\) ...and the equalequal
            \( *\) ...and another optional space
            \(NULL\) ...and the "NULL"
            /s// and substitute that just-matched pattern with
            \5 \3 \1 the 5th/3rd/1st fields, fixed single-space
            between
            /g and do it more than once per line should any
            more exist

            The tweaks with the spacing will also find

            p==NULL
            p == NULL
            P == NULL

            and so on, and replace any occurrence with

            NULL == p

            ie, only a single space between.


            'Though if this is C, you might wanna cast the NULL to whatever p
            happens to be, so something like

            (const char *)NULL == p
            (struct foo *)NULL == p
            (FILE *)NULL == p
            (void *)NULL == p

            etc., if it's a pointer to character data, a struct, a file, or a
            generic nothing. Fwiw...

            And I happen to turn on *all* warnings, so even leaving it as-is will
            trigger the "possible assignment in conditional" or whatever the warning
            would be, in the compiler stage.

            Can never be too anal-retentive in programming. :D

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Gene Kwiecinski
            ... warning ... Well, yeah, but the *reason* you do it backwards , ie, compare the constant with the variable instead of the variable to the constant, is in
            Message 5 of 5 , Feb 1, 2008
            • 0 Attachment
              >>'Though if this is C, you might wanna cast the NULL to whatever p
              >>happens to be, so something like

              >> (const char *)NULL == p
              >> (struct foo *)NULL == p
              >> (FILE *)NULL == p
              >> (void *)NULL == p

              >>etc., if it's a pointer to character data, a struct, a file, or a
              >>generic nothing. Fwiw...

              >>And I happen to turn on *all* warnings, so even leaving it as-is will
              >>trigger the "possible assignment in conditional" or whatever the
              warning
              >>would be, in the compiler stage.

              >I hope not! It's not an assignment, it's a comparison. It has == not =.

              Well, yeah, but the *reason* you do it "backwards", ie, compare the
              constant with the variable instead of the variable to the constant, is
              in case you accidentally forget one '=', a newbie mistakee, but hey,
              typos happen... So mistyping it as

              if( p = NULL )...

              will quietly assign NULL to p, finish the compilation and hand you the
              compiled executable just fine, but that if() will always be false, and
              the condition will never be taken, as well as irreparably munging p,
              obviously a bug. But having

              if( NULL = p )...

              will try to assign the value of p to a constant, a clear error, and
              *not* let you go beyond that. So you see the error, wonder "Wtf
              happened?? Oh, forgot the 2nd '='... silly me.", fix it, recompile, and
              everyone's happy. :D

              I was never crazy about assigning things "backwards", so I still do it
              the

              if( p == (whatever)NULL )...

              way, only I turn on practically every allowable warning in existence. I
              got nicknamed "the human 'lint'" for casting practically *everything* to
              make sure there was absolutely no misinterpretation of what I was
              comparing/assigning.

              Hey, worx for me...

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