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

Re: Search And Yank

Expand Messages
  • iler_ml@fastmail.fm
    On Wed, 1 Feb 2006 11:06:57 +0000 (GMT), Vigil ... I assume you mean register e . The below works but missing checks for not
    Message 1 of 14 , Feb 1 4:02 AM
    • 0 Attachment
      On Wed, 1 Feb 2006 11:06:57 +0000 (GMT), "Vigil" <vim5632@...>
      said:
      > I know this should be simple but I can't find where to do it...
      >
      > In the above line, how would I compose a command to search for "this" and
      > put
      > everything after it but on the same line, up to "find", into buffer "e?

      I assume you mean 'register e'. The below works but missing checks for
      'not found'.
      It assigns the result to @e (register e)

      function! Z()
      let pl=strlen("this")
      let a=search("this") | let x=col('.')
      let b=search("find") | let y=col('.')
      let @e=strpart(getline(line('.')),x+pl-1,y-(x+pl))
      endfu
      " to test it:
      : call Z()
      :echo @e

      Yakov
      --

      iler_ml@...

      --
      http://www.fastmail.fm - Access your email from home and the web
    • A. J. Mechelynck
      ... He said starting at this and all after it on the same line until find . Both words were on the same line, so characterwise and blockwise (but not
      Message 2 of 14 , Feb 1 4:43 AM
      • 0 Attachment
        Tim Chase wrote:
        >> In a script (untested, all on one line):
        >>
        >> exe 'normal /\<this\>' . "\r" . '/\<find\>' . "\r" . 'e"ey'
        >
        > While I couldn't quite tell if Vigil wanted line-wise or character-wise
        > blocks, if you want it in line-wise, you can just use the ex command
        >
        > :/this/,/find/y e
        >
        > which will yank those lines into register "e". If you want
        > character-wise, Tony and Yakov's solutions are more what you'll need
        > (though more convoluted than the straight-forward line-wise ex command
        > above)
        >
        > -tim
        >
        >
        >
        >
        >
        >
        >

        He said "starting at 'this' and all after it on the same line until
        'find'". Both words were on the same line, so characterwise and
        blockwise (but not linewise) are equivalent.

        One thing I forgot was that he wanted it to work regardless of whether
        the search for "this" was forward or backward. This can be easily taken
        care of:

        exe "normal \<Home>" . '/\<this\>' . "\r" . '/\<find\>' . "\r" . 'e"ey'

        still untested, and still all on one line.


        Best regards,
        Tony.
      • Vigil
        ... Thanks, I thought I could do it with just one :stuff here command but I ll just macro it. The ultimate goal was to make a macro that would select text
        Message 3 of 14 , Feb 1 7:41 AM
        • 0 Attachment
          >> From the keyboard:
          >
          > /\<this\>
          > v
          > /\<find\>
          > e
          > "ey

          Thanks, I thought I could do it with just one ":stuff here" command but I'll
          just macro it. The ultimate goal was to make a macro that would select text
          between two words and yank it anyway.

          --

          .
        • Yegappan Lakshmanan
          Hi, ... You can also use one of the following commands: let @e = matchstr(getline( . ), . {-} ) let @e = matchstr(getline( . ),
          Message 4 of 14 , Feb 1 7:45 AM
          • 0 Attachment
            Hi,

            On 2/1/06, A. J. Mechelynck <antoine.mechelynck@...> wrote:
            > Tim Chase wrote:
            > >> In a script (untested, all on one line):
            > >>
            > >> exe 'normal /\<this\>' . "\r" . '/\<find\>' . "\r" . 'e"ey'
            > >
            > > While I couldn't quite tell if Vigil wanted line-wise or character-wise
            > > blocks, if you want it in line-wise, you can just use the ex command
            > >
            > > :/this/,/find/y e
            > >
            > > which will yank those lines into register "e". If you want
            > > character-wise, Tony and Yakov's solutions are more what you'll need
            > > (though more convoluted than the straight-forward line-wise ex command
            > > above)
            > >
            > > -tim
            > >
            > >
            > >
            > >
            > >
            > >
            > >
            >
            > He said "starting at 'this' and all after it on the same line until
            > 'find'". Both words were on the same line, so characterwise and
            > blockwise (but not linewise) are equivalent.
            >
            > One thing I forgot was that he wanted it to work regardless of whether
            > the search for "this" was forward or backward. This can be easily taken
            > care of:
            >
            > exe "normal \<Home>" . '/\<this\>' . "\r" . '/\<find\>' . "\r" . 'e"ey'
            >
            > still untested, and still all on one line.
            >

            You can also use one of the following commands:

            let @e = matchstr(getline('.'), '\<this\>.\{-}\<find\>')
            let @e = matchstr(getline('.'), '\<this\>\(\(this\)\@!\).\{-}\<find\>')

            - Yegappan
          • Charles E. Campbell, Jr.
            As frequently happens, there s often multiple ways to do things in vim. Here s another: / / ey/ / (its a one liner, starting from normal mode)
            Message 5 of 14 , Feb 1 8:04 AM
            • 0 Attachment
              As frequently happens, there's often multiple ways to do things in vim.
              Here's another:

              /\<this\>/"ey/\<find\>/

              (its a one liner, starting from normal mode)

              Regards,
              Chip Campbell
            • Charles E. Campbell, Jr.
              ... Whoops; please try / / ey/ zs/ instead (to get the find included). Regards, Chip Campbell
              Message 6 of 14 , Feb 1 8:17 AM
              • 0 Attachment
                Charles E. Campbell, Jr. wrote:

                > As frequently happens, there's often multiple ways to do things in
                > vim. Here's another:
                >
                > /\<this\>/"ey/\<find\>/
                >
                > (its a one liner, starting from normal mode)
                >
                > Regards,
                > Chip Campbell
                >
                Whoops; please try

                /\<this\>/"ey/\<find\>\zs/

                instead (to get the "find" included).

                Regards,
                Chip Campbell
              • Tim Chase
                ... Or you can use the search modifiers / /e+ instead of the zs (one-third fewer characters, lower in trans-fats, and tastes great! :*) You ll also
                Message 7 of 14 , Feb 1 8:30 AM
                • 0 Attachment
                  > Whoops; please try
                  >
                  > /\<this\>/"ey/\<find\>\zs/
                  >
                  > instead (to get the "find" included).

                  Or you can use the search modifiers

                  /\<find\>/e+

                  instead of the "\zs" (one-third fewer characters, lower in
                  trans-fats, and tastes great! :*)

                  You'll also want to hit <enter> after entering the search for
                  /\<this\>/ (which can be done instead of the closing slash) which
                  would make it

                  /\<this\><cr>"ey/\<find\>/e+

                  (where the <cr> is either literal in a mapping, or the actual
                  <enter> key if typed live)

                  -tim
                • Vigil
                  ... Maybe I have some weird setting but none of those methods work. The immediate above one says the pattern is not found: E486: Pattern not found:
                  Message 8 of 14 , Feb 2 1:27 AM
                  • 0 Attachment
                    On Wed, 1 Feb 2006, Tim Chase wrote:

                    >> /\<this\>/"ey/\<find\>\zs/
                    >>
                    >
                    > /\<this\><cr>"ey/\<find\>/e+

                    Maybe I have some weird setting but none of those methods work. The immediate
                    above one says the pattern is not found:

                    E486: Pattern not found: \<this\><cr>"ey

                    --

                    .
                  • A. J. Mechelynck
                    ... That s normal, input this way is interpreted as four characters, not one control code. Did you try my pattern? (all on one line) ... Best regards,
                    Message 9 of 14 , Feb 2 4:58 AM
                    • 0 Attachment
                      Vigil wrote:
                      > On Wed, 1 Feb 2006, Tim Chase wrote:
                      >
                      >>> /\<this\>/"ey/\<find\>\zs/
                      >>>
                      >>
                      >> /\<this\><cr>"ey/\<find\>/e+
                      >
                      > Maybe I have some weird setting but none of those methods work. The
                      > immediate above one says the pattern is not found:
                      >
                      > E486: Pattern not found: \<this\><cr>"ey
                      >

                      That's normal, <cr> input this way is interpreted as four characters,
                      not one control code. Did you try my pattern? (all on one line)

                      :exe "normal \<Home>" . '/\<this\>' . "\r" . 'v/\<find\>' . "\r" . 'e"ey'


                      Best regards,
                      Tony.
                    • Charles E. Campbell, Jr.
                      ... Hmm, the was meant to be a carriage return, not the four characters . The / is intended to get your cursor on the word this .
                      Message 10 of 14 , Feb 2 6:26 AM
                      • 0 Attachment
                        Vigil wrote:

                        > On Wed, 1 Feb 2006, Tim Chase wrote:
                        >
                        >>> /\<this\>/"ey/\<find\>\zs/
                        >>>
                        >>
                        >> /\<this\><cr>"ey/\<find\>/e+
                        >
                        >
                        > Maybe I have some weird setting but none of those methods work. The
                        > immediate above one says the pattern is not found:
                        >
                        > E486: Pattern not found: \<this\><cr>"ey
                        >
                        Hmm, the <cr> was meant to be a carriage return, not the four characters
                        < c r > .
                        The /\<this\> is intended to get your cursor on the word "this".

                        Regards,
                        Chip Campbell
                      • Vigil
                        ... It is too long O:) -- .
                        Message 11 of 14 , Feb 3 1:17 AM
                        • 0 Attachment
                          On Thu, 2 Feb 2006, A. J. Mechelynck wrote:

                          > That's normal, <cr> input this way is interpreted as four characters,
                          > not one control code. Did you try my pattern? (all on one line)
                          >
                          > :exe "normal \<Home>" . '/\<this\>' . "\r" . 'v/\<find\>' . "\r" . 'e"ey'

                          It is too long O:)

                          --

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