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

Search And Yank

Expand Messages
  • Vigil
    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
    Message 1 of 14 , Feb 1, 2006
      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 am thinking something like:

      :/this/,/find/normal "ey

      but that puts ":s/~@kb~@kbg/^[" into "e and wouldn't work if the cursor was
      behind the first "this".

      --

      .
    • A. J. Mechelynck
      ... From the keyboard: / v / e ey 1. search 2. start Visual mode 3. search again 4. forward to end of word 5. yank In a script (untested, all
      Message 2 of 14 , Feb 1, 2006
        Vigil wrote:
        > 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 am thinking something like:
        >
        > :/this/,/find/normal "ey
        >
        > but that puts ":s/~@kb~@kbg/^[" into "e and wouldn't work if the cursor
        > was behind the first "this".
        >

        From the keyboard:

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

        1. search
        2. start Visual mode
        3. search again
        4. forward to end of word
        5. yank


        In a script (untested, all on one line):

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

        Notice the use of single-quoted and double-quoted strings, depending on
        whether \ must be special and whether we want to quote quotes. I'm using
        \< and \> to mark word boundaries in the search.


        Best regards,
        Tony.
      • 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 3 of 14 , Feb 1, 2006
          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
        • Tim Chase
          ... 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 ... which will
          Message 4 of 14 , Feb 1, 2006
            > 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
          • 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 5 of 14 , Feb 1, 2006
              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 6 of 14 , Feb 1, 2006
                >> 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 7 of 14 , Feb 1, 2006
                  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 8 of 14 , Feb 1, 2006
                    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 9 of 14 , Feb 1, 2006
                      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 10 of 14 , Feb 1, 2006
                        > 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 11 of 14 , Feb 2, 2006
                          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 12 of 14 , Feb 2, 2006
                            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 13 of 14 , Feb 2, 2006
                              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 14 of 14 , Feb 3, 2006
                                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.