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

Re: vim word matching when moving

Expand Messages
  • Bahadir Balban
    ... Hi, Thank you these were very useful. The reason I wanted to use motion rather than /regex was that, I am recording a set of actions with Q, and then
    Message 1 of 7 , Nov 4, 2005
    • 0 Attachment
      On 11/4/05, Tim Chase <vim@...> wrote:
      > Hope these give you something to work with.
      >
      > -tim
      >

      Hi,

      Thank you these were very useful. The reason I wanted to use motion
      rather than /regex was that, I am recording a set of actions with Q,
      and then repeating it on many functions. So my recordings are like, go
      to the first argument, replace it with x, get back, go down 3 lines to
      the next function, match the same argument ... etc. I guess I can also
      do the same using /regex.

      Thanks,
      Bahadir
    • Tim Chase
      ... It may be easier to use just a regular :global or :substitute command. The general format would be something like ... If your args only fall on these
      Message 2 of 7 , Nov 4, 2005
      • 0 Attachment
        > Thank you these were very useful. The reason I wanted to use
        > motion rather than /regex was that, I am recording a set of
        > actions with Q, and then repeating it on many functions. So my
        > recordings are like, go to the first argument, replace it
        > with x, get back, go down 3 lines to the next function, match
        > the same argument ... etc. I guess I can also do the same
        > using /regex.

        It may be easier to use just a regular :global or :substitute
        command. The general format would be something like

        :g/regex_for_line/s/regex_for_arg/replacement/

        If your args only fall on these function lines, then it can
        easily be done in a single substitute pass, such as

        :%s/old_arg_regex/new_arg_regexp

        Alternatively, you can use back references such as

        :%s/^\(function .\{-}\)arg_regex/\1replacement

        Thus, if you had code of the form

        function foo(somearg) {
        dostuff
        }
        function bar(otherarg) {
        morestuff
        }

        and you wanted to change "somearg" to "sSomearg" and "otherarg"
        to "sOtherarg" you'd use

        :%s/^\(function .\{-}\)\(\a*arg\)/\1s\u\2

        Or maybe that just muddies the waters for you :)

        Just a few thoughts,

        -tim
      • Bahadir Balban
        ... I usually use sed to replace things, and just copy-paste replacement one-liners I find on the web :) Need to read more on sed to understand these. Is your
        Message 3 of 7 , Nov 4, 2005
        • 0 Attachment
          On 11/4/05, Tim Chase <vim@...> wrote:
          > and you wanted to change "somearg" to "sSomearg" and "otherarg"
          > to "sOtherarg" you'd use
          >
          > :%s/^\(function .\{-}\)\(\a*arg\)/\1s\u\2
          >
          > Or maybe that just muddies the waters for you :)
          >
          > Just a few thoughts,
          >
          > -tim
          >

          I usually use sed to replace things, and just copy-paste replacement
          one-liners I find on the web :) Need to read more on sed to understand
          these. Is your example calling sed to do it, or is it a vim feature,
          or a universal thing that both sed and vim supports?
        • Tim Chase
          ... Vim isn t calling sed in this case (though you can do that too). Both vim and sed support this feature. They share common ancestory (sorta[*]) to ed as
          Message 4 of 7 , Nov 4, 2005
          • 0 Attachment
            > I usually use sed to replace things, and just copy-paste
            > replacement one-liners I find on the web :) Need to read more
            > on sed to understand these. Is your example calling sed to do
            > it, or is it a vim feature, or a universal thing that both sed
            > and vim supports?

            Vim isn't calling sed in this case (though you can do that too).
            Both vim and sed support this feature. They share common
            ancestory (sorta[*]) to "ed" as vim traces a lineage somewhat like

            ed -> ex -> vi -> vim

            while sed descends more directly

            ed -> sed

            However, the "s/regexp/replacement/options" command is common to
            them all. The "regexp" portion has far more flexibility in vim
            than in the others, but a strong knowledge of regexps can help
            switch between them fairly uneventfully.

            -tim

            [*] I'm not sure if any code or libraries were shared between
            them, but many of the ideas from one carried into its "ancestors".
          Your message has been successfully submitted and would be delivered to recipients shortly.