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

Re: current cursor position to end of line

Expand Messages
  • Yakov Lerner
    ... You can try following macros. They do what you want by splitting the line into two, doing substitutions, then joining the line back into single line.
    Message 1 of 8 , Mar 1, 2004
      ITG Mailing List Subsctiber wrote:
      > On Sat, 28 Feb 2004, Paul Jolly wrote:
      >
      >
      >>ITG Mailing List Subsctiber wrote:
      >>
      >>> I want to substitute a pattern from current cursor position to the end
      >>>of line. How do I do it?
      >>
      >
      > If I use
      >
      > :s/<old pattern>/<new pattern>/g,
      >
      > <old pattern> is substitued with <new pattern> for the entire line. But
      > instead of doing so, I want to do substitution from current cursor
      > position to end of line.

      You can try following macros. They do what you want by splitting
      the line into two, doing substitutions, then
      joining the line back into single line.

      Mapping #1: it asks for the substitution to apply. It came out long but it works.

      fu! MySubst()?
      let c=input("Edit substitution command: ", "s///g")
      map \;; i<cr>
      norm \;;
      exec c
      norm kgJ
      endfu
      map <F3> :call MySubst()<cr>

      Mapping #2: It uses '&' which means 'repeat last substitution'.

      map <F11> i<cr><esc>:&g<cr>kgJ

      Yakov
    • Yakov Lerner
      ... ^ Correction. There shall be no question mark here. Some bothched cut-and-paste. Yakov
      Message 2 of 8 , Mar 1, 2004
        Yakov Lerner wrote:
        > ITG Mailing List Subsctiber wrote:
        >
        >> On Sat, 28 Feb 2004, Paul Jolly wrote:
        >>
        >>
        >>> ITG Mailing List Subsctiber wrote:
        >>>
        >>>> I want to substitute a pattern from current cursor position to
        >>>> the end
        >>>> of line. How do I do it?
        >>>
        >>>
        >>
        >> If I use
        >>
        >> :s/<old pattern>/<new pattern>/g,
        >>
        >> <old pattern> is substitued with <new pattern> for the entire line. But
        >> instead of doing so, I want to do substitution from current cursor
        >> position to end of line.
        >
        >
        > You can try following macros. They do what you want by splitting
        > the line into two, doing substitutions, then
        > joining the line back into single line.
        >
        > Mapping #1: it asks for the substitution to apply. It came out long but
        > it works.
        >
        > fu! MySubst()?
        ^
        Correction. There shall be no question mark here. Some bothched cut-and-paste.
        Yakov
      • Charles E. Campbell, Jr.
        ... With the cursor on the 3rd abc below: abc def abc def abc def abc def The substitute yields: abc def abc def newpattern Regards, Chip Campbell
        Message 3 of 8 , Mar 1, 2004
          ITG Mailing List Subsctiber wrote:

          > I want to substitute a pattern from current cursor position to the end
          >of line. How do I do it?
          >
          >

          :s/\%#.*$/newpattern/


          With the cursor on the 3rd "abc" below:

          abc def abc def abc def abc def

          The substitute yields:

          abc def abc def newpattern

          Regards,
          Chip Campbell
        • ITG Mailing List Subsctiber
          ... If I use ... is substitued with for the entire line. But instead of doing so, I want to do substitution from current cursor
          Message 4 of 8 , Mar 1, 2004
            On Sat, 28 Feb 2004, Paul Jolly wrote:

            > ITG Mailing List Subsctiber wrote:
            > > I want to substitute a pattern from current cursor position to the end
            > > of line. How do I do it?
            >
            > I am not certain I understand what you are trying to achieve.
            >
            > By replace do you mean "delete a matching pattern and place it at the
            > end of the line"?
            >
            > Post an example of what you are trying to achieve and hopefully I will
            > be able to get a better handle on the problem.

            If I use

            :s/<old pattern>/<new pattern>/g,

            <old pattern> is substitued with <new pattern> for the entire line. But
            instead of doing so, I want to do substitution from current cursor
            position to end of line.

            Regards,
            Seenu.
            -----------------------------------------------------------------------------
            If not here, you can reach me at seenutn@... or seenutn@...

            C-DOT, 71/1, Sneha Complex, Miller Road, Bangalore - 560 052
            Ph: 226 3399 Ext: 268/Direct: 238 3951 (Off) 363 1707 (Resi)
          Your message has been successfully submitted and would be delivered to recipients shortly.