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

Re: Using internal-variables in regexp

Expand Messages
  • V.Chandrasekaran
    Hi Dave, Here is what I am trying to do. This basically came to my mind after reading tip#769 http://www.vim.org/tips/tip.php?tip_id=769 . I wanted to
    Message 1 of 19 , Oct 2, 2004
    • 0 Attachment
      Hi Dave,
      Here is what I am trying to do. This basically came to my mind after
      reading
      tip#769 http://www.vim.org/tips/tip.php?tip_id=769 . I wanted to highlight a
      line and keep it highlighted for reference till I voluntarily turn it off or
      choose
      some other line for highlighting. That tip suggests usage of \%# which
      changes
      with every cursor movement and so doesn't serve this purpose (If I had
      understood
      that tip correctly). So I was thinking if we fixed the syntax match pattern
      to the output
      of getline (".") and apply a highlight group to it, it will remain
      highlighted till we changed
      it.
      To that effect, I was planning to try the following,

      :hi MyPattern guifg=red gui=bold
      :let thisline=getline(".")
      :match MyPattern ?????? (not sure what ?????? would have to be)

      Would appreciate your thoughts on this.

      Thanks,
      chandra.


      ----- Original Message -----
      From: "Dave Silvia" <dsilvia@...>
      To: "V.Chandrasekaran" <chandrasekaran_v@...>; <vim@...>
      Sent: Saturday, October 02, 2004 6:04 PM
      Subject: RE: Using internal-variables in regexp


      > The mechanics for using variables in execution are pretty much the same
      for
      > all commands:
      >
      > :execute '<cmd-name> '.<variable-arg>
      >
      > Your basic example would use:
      >
      > :execute '/'.thisline
      >
      > If you're doing searches and substitutes, use the functions, e.g.:
      >
      > let lnum=search(thisline)
      > call substitute(someline,thisline,thatline,'')
      >
      > See
      > :h search(
      > :h substitute(
      >
      > HTH:
      >
      > Also, if you want to experiment with regular expressions, give
      VimRegEx.vim
      > (beta) a try.
      >
      > http://www.vim.org/account/profile.php?user_id=5397 VimRegEx.vim and
      > vsutil.vim
      >
      > thx,
      > Dave S.
      >
      > P.S. I'm beginning to see a picture form out of your postings. Why not
      > just formulate a description of the task you're trying to perform and the
      > stumbling blocks you're having and post that? You may find it less time
      > (and bandwidth) consuming and discover many tools out there that exist to
      > help you accomplish your task. It's also easier to correctly and more
      > precisely answer your questions if we have the big picture.
      >
      > Just a thought,
      > Dave S.
      >
      > *** -----Original Message-----
      > *** From: V.Chandrasekaran [mailto:chandrasekaran_v@...]
      > *** Sent: Saturday, October 02, 2004 7:21 PM
      > *** To: vim@...
      > *** Subject: Using internal-variables in regexp
      > ***
      > ***
      > *** Hi all,
      > *** 1. Can I use internal-variables in regular expression? For eg.,
      > *** If I do something like, let thisline=getline(".")
      > ***
      > *** How can I use the internal-variable "thisline" in a regular
      > *** expression ?
      > ***
      > *** 2. Is there a way to set the current cursor position for a file to
      > *** a value given by an internal-variable?
      > ***
      > *** Thanks a lot.
      > *** chandra.
      >
      >
    • Dave Silvia
      Look at the function s:patHilite()in VimRegEx.vim (http://www.vim.org/account/profile.php?user_id=5397). It does exactly what you re speaking of for the top
      Message 2 of 19 , Oct 2, 2004
      • 0 Attachment
        Look at the function s:patHilite()in VimRegEx.vim
        (http://www.vim.org/account/profile.php?user_id=5397). It does exactly what
        you're speaking of for the top window generated by the Vimrex command.

        function! s:patHilite(pat,grp)
        let thePat='\%('.escape(a:pat[0],'\[^*$~"').'\)'
        let idx=1
        let lidx=strlen(a:pat)
        while idx < lidx
        let theGrp='\%('.escape(a:pat[idx],'\[^*$~"').'\)'
        let thePat=thePat.theGrp.'\@='.theGrp
        let idx=idx+1
        endwhile
        execute 'syntax match '.a:grp.' "'.thePat.'"'
        syntax sync fromstart
        endfunction

        It takes _any_ sequence of characters, regardless of what they may be, and
        sets them to a syntax match for a group. Search through the file for
        when/how it's called. That should supply you with tools for what you want
        to do. It makes a rather involved regex, but it's necessary to allow _any_
        sequence to be syntax match'd. Try out the Vimrex command to see how it
        works. It basically highlights the current pattern being executed/analyzed
        (in the top window) until a different pattern is selected and
        executed/analyzed (in the top window).

        HTH:

        thx,
        Dave S.

        *** -----Original Message-----
        *** From: V.Chandrasekaran [mailto:chandrasekaran_v@...]
        *** Sent: Saturday, October 02, 2004 10:12 PM
        *** To: Dave Silvia; vim@...
        *** Subject: Re: Using internal-variables in regexp
        ***
        ***
        *** Hi Dave,
        *** Here is what I am trying to do. This basically came to my mind after
        *** reading
        *** tip#769 http://www.vim.org/tips/tip.php?tip_id=769 . I wanted
        *** to highlight a
        *** line and keep it highlighted for reference till I voluntarily
        *** turn it off or
        *** choose
        *** some other line for highlighting. That tip suggests usage of \%# which
        *** changes
        *** with every cursor movement and so doesn't serve this purpose (If I had
        *** understood
        *** that tip correctly). So I was thinking if we fixed the syntax
        *** match pattern
        *** to the output
        *** of getline (".") and apply a highlight group to it, it will remain
        *** highlighted till we changed
        *** it.
        *** To that effect, I was planning to try the following,
        ***
        *** :hi MyPattern guifg=red gui=bold
        *** :let thisline=getline(".")
        *** :match MyPattern ?????? (not sure what ?????? would have to be)
        ***
        *** Would appreciate your thoughts on this.
        ***
        *** Thanks,
        *** chandra.
        ***
        ***
        *** ----- Original Message -----
        *** From: "Dave Silvia" <dsilvia@...>
        *** To: "V.Chandrasekaran" <chandrasekaran_v@...>; <vim@...>
        *** Sent: Saturday, October 02, 2004 6:04 PM
        *** Subject: RE: Using internal-variables in regexp
        ***
        ***
        *** > The mechanics for using variables in execution are pretty
        *** much the same
        *** for
        *** > all commands:
        *** >
        *** > :execute '<cmd-name> '.<variable-arg>
        *** >
        *** > Your basic example would use:
        *** >
        *** > :execute '/'.thisline
        *** >
        *** > If you're doing searches and substitutes, use the functions, e.g.:
        *** >
        *** > let lnum=search(thisline)
        *** > call substitute(someline,thisline,thatline,'')
        *** >
        *** > See
        *** > :h search(
        *** > :h substitute(
        *** >
        *** > HTH:
        *** >
        *** > Also, if you want to experiment with regular expressions, give
        *** VimRegEx.vim
        *** > (beta) a try.
        *** >
        *** > http://www.vim.org/account/profile.php?user_id=5397 VimRegEx.vim and
        *** > vsutil.vim
        *** >
        *** > thx,
        *** > Dave S.
        *** >
        *** > P.S. I'm beginning to see a picture form out of your
        *** postings. Why not
        *** > just formulate a description of the task you're trying to
        *** perform and the
        *** > stumbling blocks you're having and post that? You may find
        *** it less time
        *** > (and bandwidth) consuming and discover many tools out there
        *** that exist to
        *** > help you accomplish your task. It's also easier to correctly and more
        *** > precisely answer your questions if we have the big picture.
        *** >
        *** > Just a thought,
        *** > Dave S.
        *** >
        *** > *** -----Original Message-----
        *** > *** From: V.Chandrasekaran [mailto:chandrasekaran_v@...]
        *** > *** Sent: Saturday, October 02, 2004 7:21 PM
        *** > *** To: vim@...
        *** > *** Subject: Using internal-variables in regexp
        *** > ***
        *** > ***
        *** > *** Hi all,
        *** > *** 1. Can I use internal-variables in regular expression? For eg.,
        *** > *** If I do something like, let thisline=getline(".")
        *** > ***
        *** > *** How can I use the internal-variable "thisline" in a regular
        *** > *** expression ?
        *** > ***
        *** > *** 2. Is there a way to set the current cursor position for a file to
        *** > *** a value given by an internal-variable?
        *** > ***
        *** > *** Thanks a lot.
        *** > *** chandra.
        *** >
        *** >
      • V.Chandrasekaran
        Hi Dave, I will explore your function and try to put it to my use. However, ... Is the above method completely useless, then? thanks, chandra. ... From: Dave
        Message 3 of 19 , Oct 2, 2004
        • 0 Attachment
          Hi Dave,
          I will explore your function and try to put it to my use. However,

          :hi MyPattern guifg=red gui=bold
          :let thisline=getline(".")
          :match MyPattern ?????? (not sure what ?????? would have to be)

          Is the above method completely useless, then?

          thanks,
          chandra.

          ----- Original Message -----
          From: "Dave Silvia" <dsilvia@...>
          To: "V.Chandrasekaran" <chandrasekaran_v@...>; <vim@...>
          Sent: Saturday, October 02, 2004 8:30 PM
          Subject: RE: Using internal-variables in regexp


          > Look at the function s:patHilite()in VimRegEx.vim
          > (http://www.vim.org/account/profile.php?user_id=5397). It does exactly
          what
          > you're speaking of for the top window generated by the Vimrex command.
          >
          > function! s:patHilite(pat,grp)
          > let thePat='\%('.escape(a:pat[0],'\[^*$~"').'\)'
          > let idx=1
          > let lidx=strlen(a:pat)
          > while idx < lidx
          > let theGrp='\%('.escape(a:pat[idx],'\[^*$~"').'\)'
          > let thePat=thePat.theGrp.'\@='.theGrp
          > let idx=idx+1
          > endwhile
          > execute 'syntax match '.a:grp.' "'.thePat.'"'
          > syntax sync fromstart
          > endfunction
          >
          > It takes _any_ sequence of characters, regardless of what they may be, and
          > sets them to a syntax match for a group. Search through the file for
          > when/how it's called. That should supply you with tools for what you want
          > to do. It makes a rather involved regex, but it's necessary to allow
          _any_
          > sequence to be syntax match'd. Try out the Vimrex command to see how it
          > works. It basically highlights the current pattern being
          executed/analyzed
          > (in the top window) until a different pattern is selected and
          > executed/analyzed (in the top window).
          >
          > HTH:
          >
          > thx,
          > Dave S.
          >
          > *** -----Original Message-----
          > *** From: V.Chandrasekaran [mailto:chandrasekaran_v@...]
          > *** Sent: Saturday, October 02, 2004 10:12 PM
          > *** To: Dave Silvia; vim@...
          > *** Subject: Re: Using internal-variables in regexp
          > ***
          > ***
          > *** Hi Dave,
          > *** Here is what I am trying to do. This basically came to my mind
          after
          > *** reading
          > *** tip#769 http://www.vim.org/tips/tip.php?tip_id=769 . I wanted
          > *** to highlight a
          > *** line and keep it highlighted for reference till I voluntarily
          > *** turn it off or
          > *** choose
          > *** some other line for highlighting. That tip suggests usage of \%# which
          > *** changes
          > *** with every cursor movement and so doesn't serve this purpose (If I had
          > *** understood
          > *** that tip correctly). So I was thinking if we fixed the syntax
          > *** match pattern
          > *** to the output
          > *** of getline (".") and apply a highlight group to it, it will remain
          > *** highlighted till we changed
          > *** it.
          > *** To that effect, I was planning to try the following,
          > ***
          > *** :hi MyPattern guifg=red gui=bold
          > *** :let thisline=getline(".")
          > *** :match MyPattern ?????? (not sure what ?????? would have to be)
          > ***
          > *** Would appreciate your thoughts on this.
          > ***
          > *** Thanks,
          > *** chandra.
          > ***
          > ***
          > *** ----- Original Message -----
          > *** From: "Dave Silvia" <dsilvia@...>
          > *** To: "V.Chandrasekaran" <chandrasekaran_v@...>; <vim@...>
          > *** Sent: Saturday, October 02, 2004 6:04 PM
          > *** Subject: RE: Using internal-variables in regexp
          > ***
          > ***
          > *** > The mechanics for using variables in execution are pretty
          > *** much the same
          > *** for
          > *** > all commands:
          > *** >
          > *** > :execute '<cmd-name> '.<variable-arg>
          > *** >
          > *** > Your basic example would use:
          > *** >
          > *** > :execute '/'.thisline
          > *** >
          > *** > If you're doing searches and substitutes, use the functions, e.g.:
          > *** >
          > *** > let lnum=search(thisline)
          > *** > call substitute(someline,thisline,thatline,'')
          > *** >
          > *** > See
          > *** > :h search(
          > *** > :h substitute(
          > *** >
          > *** > HTH:
          > *** >
          > *** > Also, if you want to experiment with regular expressions, give
          > *** VimRegEx.vim
          > *** > (beta) a try.
          > *** >
          > *** > http://www.vim.org/account/profile.php?user_id=5397 VimRegEx.vim and
          > *** > vsutil.vim
          > *** >
          > *** > thx,
          > *** > Dave S.
          > *** >
          > *** > P.S. I'm beginning to see a picture form out of your
          > *** postings. Why not
          > *** > just formulate a description of the task you're trying to
          > *** perform and the
          > *** > stumbling blocks you're having and post that? You may find
          > *** it less time
          > *** > (and bandwidth) consuming and discover many tools out there
          > *** that exist to
          > *** > help you accomplish your task. It's also easier to correctly and
          more
          > *** > precisely answer your questions if we have the big picture.
          > *** >
          > *** > Just a thought,
          > *** > Dave S.
          > *** >
          > *** > *** -----Original Message-----
          > *** > *** From: V.Chandrasekaran [mailto:chandrasekaran_v@...]
          > *** > *** Sent: Saturday, October 02, 2004 7:21 PM
          > *** > *** To: vim@...
          > *** > *** Subject: Using internal-variables in regexp
          > *** > ***
          > *** > ***
          > *** > *** Hi all,
          > *** > *** 1. Can I use internal-variables in regular expression? For eg.,
          > *** > *** If I do something like, let thisline=getline(".")
          > *** > ***
          > *** > *** How can I use the internal-variable "thisline" in a regular
          > *** > *** expression ?
          > *** > ***
          > *** > *** 2. Is there a way to set the current cursor position for a file
          to
          > *** > *** a value given by an internal-variable?
          > *** > ***
          > *** > *** Thanks a lot.
          > *** > *** chandra.
          > *** >
          > *** >
          >
          >
        • Dave Silvia
          No, it s not completely useless. It s exactly what you need to do. If you use s:patHilite, rename it to say PatHilite, what you d do is call call
          Message 4 of 19 , Oct 2, 2004
          • 0 Attachment
            No, it's not completely useless. It's exactly what you need to do. If you
            use s:patHilite, rename it to say PatHilite, what you'd do is call

            call PatHilite(thisline,'MyPattern')

            And the line would be highlighted to whatever you set in

            highlight MyPattern

            Your exact sequence would be

            highlight MyPattern guifg=red gui=bold
            call PatHilite(getline('.'),'MyPattern')

            Boom! Your line is all highlighted in bold red!;)

            This is exactly what happens in VimRegEx.vim. Take a look, it'll only take
            a minute.

            HTH:

            thx,
            Dave S.

            *** -----Original Message-----
            *** From: V.Chandrasekaran [mailto:chandrasekaran_v@...]
            *** Sent: Saturday, October 02, 2004 11:08 PM
            *** To: Dave Silvia; vim@...
            *** Subject: Re: Using internal-variables in regexp
            ***
            ***
            *** Hi Dave,
            *** I will explore your function and try to put it to my use. However,
            ***
            *** :hi MyPattern guifg=red gui=bold
            *** :let thisline=getline(".")
            *** :match MyPattern ?????? (not sure what ?????? would have to be)
            ***
            *** Is the above method completely useless, then?
            ***
            *** thanks,
            *** chandra.
            ***
            *** ----- Original Message -----
            *** From: "Dave Silvia" <dsilvia@...>
            *** To: "V.Chandrasekaran" <chandrasekaran_v@...>; <vim@...>
            *** Sent: Saturday, October 02, 2004 8:30 PM
            *** Subject: RE: Using internal-variables in regexp
            ***
            ***
            *** > Look at the function s:patHilite()in VimRegEx.vim
            *** > (http://www.vim.org/account/profile.php?user_id=5397). It
            *** does exactly
            *** what
            *** > you're speaking of for the top window generated by the Vimrex command.
            *** >
            *** > function! s:patHilite(pat,grp)
            *** > let thePat='\%('.escape(a:pat[0],'\[^*$~"').'\)'
            *** > let idx=1
            *** > let lidx=strlen(a:pat)
            *** > while idx < lidx
            *** > let theGrp='\%('.escape(a:pat[idx],'\[^*$~"').'\)'
            *** > let thePat=thePat.theGrp.'\@='.theGrp
            *** > let idx=idx+1
            *** > endwhile
            *** > execute 'syntax match '.a:grp.' "'.thePat.'"'
            *** > syntax sync fromstart
            *** > endfunction
            *** >
            *** > It takes _any_ sequence of characters, regardless of what
            *** they may be, and
            *** > sets them to a syntax match for a group. Search through the file for
            *** > when/how it's called. That should supply you with tools for
            *** what you want
            *** > to do. It makes a rather involved regex, but it's necessary to allow
            *** _any_
            *** > sequence to be syntax match'd. Try out the Vimrex command to
            *** see how it
            *** > works. It basically highlights the current pattern being
            *** executed/analyzed
            *** > (in the top window) until a different pattern is selected and
            *** > executed/analyzed (in the top window).
            *** >
            *** > HTH:
            *** >
            *** > thx,
            *** > Dave S.
            *** >
            *** > *** -----Original Message-----
            *** > *** From: V.Chandrasekaran [mailto:chandrasekaran_v@...]
            *** > *** Sent: Saturday, October 02, 2004 10:12 PM
            *** > *** To: Dave Silvia; vim@...
            *** > *** Subject: Re: Using internal-variables in regexp
            *** > ***
            *** > ***
            *** > *** Hi Dave,
            *** > *** Here is what I am trying to do. This basically came to my mind
            *** after
            *** > *** reading
            *** > *** tip#769 http://www.vim.org/tips/tip.php?tip_id=769 . I wanted
            *** > *** to highlight a
            *** > *** line and keep it highlighted for reference till I voluntarily
            *** > *** turn it off or
            *** > *** choose
            *** > *** some other line for highlighting. That tip suggests usage
            *** of \%# which
            *** > *** changes
            *** > *** with every cursor movement and so doesn't serve this
            *** purpose (If I had
            *** > *** understood
            *** > *** that tip correctly). So I was thinking if we fixed the syntax
            *** > *** match pattern
            *** > *** to the output
            *** > *** of getline (".") and apply a highlight group to it, it will remain
            *** > *** highlighted till we changed
            *** > *** it.
            *** > *** To that effect, I was planning to try the following,
            *** > ***
            *** > *** :hi MyPattern guifg=red gui=bold
            *** > *** :let thisline=getline(".")
            *** > *** :match MyPattern ?????? (not sure what ?????? would have to be)
            *** > ***
            *** > *** Would appreciate your thoughts on this.
            *** > ***
            *** > *** Thanks,
            *** > *** chandra.
            *** > ***
            *** > ***
            *** > *** ----- Original Message -----
            *** > *** From: "Dave Silvia" <dsilvia@...>
            *** > *** To: "V.Chandrasekaran" <chandrasekaran_v@...>;
            *** <vim@...>
            *** > *** Sent: Saturday, October 02, 2004 6:04 PM
            *** > *** Subject: RE: Using internal-variables in regexp
            *** > ***
            *** > ***
            *** > *** > The mechanics for using variables in execution are pretty
            *** > *** much the same
            *** > *** for
            *** > *** > all commands:
            *** > *** >
            *** > *** > :execute '<cmd-name> '.<variable-arg>
            *** > *** >
            *** > *** > Your basic example would use:
            *** > *** >
            *** > *** > :execute '/'.thisline
            *** > *** >
            *** > *** > If you're doing searches and substitutes, use the
            *** functions, e.g.:
            *** > *** >
            *** > *** > let lnum=search(thisline)
            *** > *** > call substitute(someline,thisline,thatline,'')
            *** > *** >
            *** > *** > See
            *** > *** > :h search(
            *** > *** > :h substitute(
            *** > *** >
            *** > *** > HTH:
            *** > *** >
            *** > *** > Also, if you want to experiment with regular expressions, give
            *** > *** VimRegEx.vim
            *** > *** > (beta) a try.
            *** > *** >
            *** > *** > http://www.vim.org/account/profile.php?user_id=5397
            *** VimRegEx.vim and
            *** > *** > vsutil.vim
            *** > *** >
            *** > *** > thx,
            *** > *** > Dave S.
            *** > *** >
            *** > *** > P.S. I'm beginning to see a picture form out of your
            *** > *** postings. Why not
            *** > *** > just formulate a description of the task you're trying to
            *** > *** perform and the
            *** > *** > stumbling blocks you're having and post that? You may find
            *** > *** it less time
            *** > *** > (and bandwidth) consuming and discover many tools out there
            *** > *** that exist to
            *** > *** > help you accomplish your task. It's also easier to
            *** correctly and
            *** more
            *** > *** > precisely answer your questions if we have the big picture.
            *** > *** >
            *** > *** > Just a thought,
            *** > *** > Dave S.
            *** > *** >
            *** > *** > *** -----Original Message-----
            *** > *** > *** From: V.Chandrasekaran [mailto:chandrasekaran_v@...]
            *** > *** > *** Sent: Saturday, October 02, 2004 7:21 PM
            *** > *** > *** To: vim@...
            *** > *** > *** Subject: Using internal-variables in regexp
            *** > *** > ***
            *** > *** > ***
            *** > *** > *** Hi all,
            *** > *** > *** 1. Can I use internal-variables in regular
            *** expression? For eg.,
            *** > *** > *** If I do something like, let thisline=getline(".")
            *** > *** > ***
            *** > *** > *** How can I use the internal-variable "thisline"
            *** in a regular
            *** > *** > *** expression ?
            *** > *** > ***
            *** > *** > *** 2. Is there a way to set the current cursor
            *** position for a file
            *** to
            *** > *** > *** a value given by an internal-variable?
            *** > *** > ***
            *** > *** > *** Thanks a lot.
            *** > *** > *** chandra.
            *** > *** >
            *** > *** >
            *** >
            *** >
          • Mikolaj Machowski
            ... Look one item lower in docs. Get number of line and highlight line with % l It should be faster and NULL problems with escaping special characters.
            Message 5 of 19 , Oct 3, 2004
            • 0 Attachment
              Dnia niedziela, 3 października 2004 05:11, V.Chandrasekaran napisał:
              > Hi Dave,
              > Here is what I am trying to do. This basically came to my mind after
              > reading
              > tip#769 http://www.vim.org/tips/tip.php?tip_id=769 . I wanted to
              > highlight a line and keep it highlighted for reference till I
              > voluntarily turn it off or choose
              > some other line for highlighting. That tip suggests usage of \%# which
              > changes
              > with every cursor movement and so doesn't serve this purpose (If I had
              > understood
              > that tip correctly). So I was thinking if we fixed the syntax match
              > pattern to the output

              Look one item lower in docs.

              Get number of line and highlight line with \%<number>l
              It should be faster and NULL problems with escaping special characters.

              :let thisline=line(".")
              :exe 'match MyLine /\%'.thisline.'l.*/'

              m.

              --
              LaTeX + Vim = http://vim-latex.sourceforge.net/
              Vim-list(s) Users Map: (last change 17 Sep)
              http://skawina.eu.org/mikolaj/vimlist
              CLEWN - http://clewn.sf.net
            • Dave Silvia
              The problem is still the same: highlighting changes with the search and you re constrained to Search highlight coloring. The OP is looking to highlight the
              Message 6 of 19 , Oct 3, 2004
              • 0 Attachment
                The problem is still the same: highlighting changes with the search and
                you're constrained to 'Search' highlight coloring. The OP is looking to
                highlight the line independent of any other searching that is taking place
                and in a specific color. With PatHilite() you can pretty much isolate the
                exact line an keep it highlighted the way you want until you specifically
                decide to turn it off. Of course, if there are 2 or more lines that are
                exactly the same, all are highlighted, but c'est la vie!;)

                thx,
                Dave S.

                *** -----Original Message-----
                *** From: Mikolaj Machowski [mailto:mikmach@...]
                *** Sent: Sunday, October 03, 2004 5:04 AM
                *** To: vim@...
                *** Subject: Re: Using internal-variables in regexp
                ***
                ***
                *** Dnia niedziela, 3 października 2004 05:11, V.Chandrasekaran napisał:
                *** > Hi Dave,
                *** > Here is what I am trying to do. This basically came to my
                *** mind after
                *** > reading
                *** > tip#769 http://www.vim.org/tips/tip.php?tip_id=769 . I wanted to
                *** > highlight a line and keep it highlighted for reference till I
                *** > voluntarily turn it off or choose
                *** > some other line for highlighting. That tip suggests usage of \%# which
                *** > changes
                *** > with every cursor movement and so doesn't serve this purpose (If I had
                *** > understood
                *** > that tip correctly). So I was thinking if we fixed the syntax match
                *** > pattern to the output
                ***
                *** Look one item lower in docs.
                ***
                *** Get number of line and highlight line with \%<number>l
                *** It should be faster and NULL problems with escaping special characters.
                ***
                *** :let thisline=line(".")
                *** :exe 'match MyLine /\%'.thisline.'l.*/'
                ***
                *** m.
                ***
                *** --
                *** LaTeX + Vim = http://vim-latex.sourceforge.net/
                *** Vim-list(s) Users Map: (last change 17 Sep)
                *** http://skawina.eu.org/mikolaj/vimlist
                *** CLEWN - http://clewn.sf.net
                ***
                ***
                ***
              • Dave Silvia
                My apologies! I see what you mean. Yes, this works as wanted. Best description I found was ... However, you still have to be mindful of special characters
                Message 7 of 19 , Oct 3, 2004
                • 0 Attachment
                  My apologies! I see what you mean. Yes, this works as wanted. Best
                  description I found was

                  :h CursorHold-example

                  However, you still have to be mindful of special characters

                  :h :match

                  I appreciate the info!;)

                  thx,
                  Dave S.

                  *** -----Original Message-----
                  *** From: Mikolaj Machowski [mailto:mikmach@...]
                  *** Sent: Sunday, October 03, 2004 5:04 AM
                  *** To: vim@...
                  *** Subject: Re: Using internal-variables in regexp
                  ***
                  ***
                  *** Dnia niedziela, 3 października 2004 05:11, V.Chandrasekaran napisał:
                  *** > Hi Dave,
                  *** > Here is what I am trying to do. This basically came to my
                  *** mind after
                  *** > reading
                  *** > tip#769 http://www.vim.org/tips/tip.php?tip_id=769 . I wanted to
                  *** > highlight a line and keep it highlighted for reference till I
                  *** > voluntarily turn it off or choose
                  *** > some other line for highlighting. That tip suggests usage of \%# which
                  *** > changes
                  *** > with every cursor movement and so doesn't serve this purpose (If I had
                  *** > understood
                  *** > that tip correctly). So I was thinking if we fixed the syntax match
                  *** > pattern to the output
                  ***
                  *** Look one item lower in docs.
                  ***
                  *** Get number of line and highlight line with \%<number>l
                  *** It should be faster and NULL problems with escaping special characters.
                  ***
                  *** :let thisline=line(".")
                  *** :exe 'match MyLine /\%'.thisline.'l.*/'
                  ***
                  *** m.
                  ***
                  *** --
                  *** LaTeX + Vim = http://vim-latex.sourceforge.net/
                  *** Vim-list(s) Users Map: (last change 17 Sep)
                  *** http://skawina.eu.org/mikolaj/vimlist
                  *** CLEWN - http://clewn.sf.net
                  ***
                  ***
                  ***
                • V.Chandrasekaran
                  This works great. Thanks. However, if the line number changes due to edits above this highlighted line, the highlighted line changes too. But this is ok.
                  Message 8 of 19 , Oct 3, 2004
                  • 0 Attachment
                    This works great. Thanks. However, if the line number changes due to edits
                    above this highlighted line, the highlighted line changes too. But this is
                    ok.

                    thanks,
                    -chandra.

                    #>>>>>>>>>>>>
                    #Look one item lower in docs.
                    #
                    #Get number of line and highlight line with \%<number>l
                    #It should be faster and NULL problems with escaping special #characters.
                    #
                    #:let thisline=line(".")
                    #:exe 'match MyLine /\%'.thisline.'l.*/'
                    #
                    #m.
                    #>>>>>>>>>>>
                  • Dave Silvia
                    With PatHilite() the highlighting stays with the text, not the line number. FYI, Dave S. *** -----Original Message----- *** From: V.Chandrasekaran
                    Message 9 of 19 , Oct 3, 2004
                    • 0 Attachment
                      With PatHilite() the highlighting stays with the text, not the line number.

                      FYI,
                      Dave S.

                      *** -----Original Message-----
                      *** From: V.Chandrasekaran [mailto:chandrasekaran_v@...]
                      *** Sent: Sunday, October 03, 2004 1:25 PM
                      *** To: vim@...
                      *** Subject: Re: Using internal-variables in regexp
                      ***
                      ***
                      *** This works great. Thanks. However, if the line number changes
                      *** due to edits
                      *** above this highlighted line, the highlighted line changes too.
                      *** But this is
                      *** ok.
                      ***
                      *** thanks,
                      *** -chandra.
                      ***
                      *** #>>>>>>>>>>>>
                      *** #Look one item lower in docs.
                      *** #
                      *** #Get number of line and highlight line with \%<number>l
                      *** #It should be faster and NULL problems with escaping special
                      *** #characters.
                      *** #
                      *** #:let thisline=line(".")
                      *** #:exe 'match MyLine /\%'.thisline.'l.*/'
                      *** #
                      *** #m.
                      *** #>>>>>>>>>>>
                    • V.Chandrasekaran
                      Yes. I realised that. I should give that a try as well. thanks for the help. chandra. ... From: Dave Silvia To: V.Chandrasekaran
                      Message 10 of 19 , Oct 3, 2004
                      • 0 Attachment
                        Yes. I realised that. I should give that a try as well.

                        thanks for the help.
                        chandra.

                        ----- Original Message -----
                        From: "Dave Silvia" <dsilvia@...>
                        To: "V.Chandrasekaran" <chandrasekaran_v@...>; <vim@...>
                        Sent: Sunday, October 03, 2004 4:08 PM
                        Subject: RE: Using internal-variables in regexp


                        > With PatHilite() the highlighting stays with the text, not the line
                        number.
                        >
                        > FYI,
                        > Dave S.
                        >
                        > *** -----Original Message-----
                        > *** From: V.Chandrasekaran [mailto:chandrasekaran_v@...]
                        > *** Sent: Sunday, October 03, 2004 1:25 PM
                        > *** To: vim@...
                        > *** Subject: Re: Using internal-variables in regexp
                        > ***
                        > ***
                        > *** This works great. Thanks. However, if the line number changes
                        > *** due to edits
                        > *** above this highlighted line, the highlighted line changes too.
                        > *** But this is
                        > *** ok.
                        > ***
                        > *** thanks,
                        > *** -chandra.
                        > ***
                        > *** #>>>>>>>>>>>>
                        > *** #Look one item lower in docs.
                        > *** #
                        > *** #Get number of line and highlight line with \%<number>l
                        > *** #It should be faster and NULL problems with escaping special
                        > *** #characters.
                        > *** #
                        > *** #:let thisline=line(".")
                        > *** #:exe 'match MyLine /\%'.thisline.'l.*/'
                        > *** #
                        > *** #m.
                        > *** #>>>>>>>>>>>
                        >
                      • Antoine J. Mechelynck
                        ... You might want to use a mark then (see :help mark-motions ). ( The implementation details are left as an exercise to the reader. ) Regards, Tony.
                        Message 11 of 19 , Oct 3, 2004
                        • 0 Attachment
                          V.Chandrasekaran <chandrasekaran_v@...> wrote:
                          > This works great. Thanks. However, if the line number changes due to
                          > edits above this highlighted line, the highlighted line changes too.
                          > But this is ok.
                          >
                          > thanks,
                          > -chandra.

                          You might want to use a mark then (see ":help mark-motions"). ("The
                          implementation details are left as an exercise to the reader.")

                          Regards,
                          Tony.
                        • Dave Silvia
                          That s quite an exercise for the reader. I looked in motion.txt, windows.txt, and pattern.txt for clues as well as VimgrepHelp on mark , but cannot seem to
                          Message 12 of 19 , Oct 4, 2004
                          • 0 Attachment
                            That's quite an exercise for the reader. I looked in motion.txt,
                            windows.txt, and pattern.txt for clues as well as VimgrepHelp on 'mark', but
                            cannot seem to find anything that mentions relating a mark to a
                            match/highlight/syntax. If you're thinking of:

                            :execute 'match grp "\%'.line("'Z").'l.*"'

                            the line is translated only at the time of execution, so the highlighting
                            stays with the original line number. So, I'm stumped!(

                            Can I get a hint?)

                            thx,
                            Dave S.

                            *** -----Original Message-----
                            *** From: Antoine J. Mechelynck [mailto:antoine.mechelynck@...]
                            *** Sent: Monday, October 04, 2004 1:20 AM
                            *** To: V.Chandrasekaran; vim@...
                            *** Subject: Re: Using internal-variables in regexp
                            ***
                            ***
                            *** V.Chandrasekaran <chandrasekaran_v@...> wrote:
                            *** > This works great. Thanks. However, if the line number changes due to
                            *** > edits above this highlighted line, the highlighted line changes too.
                            *** > But this is ok.
                            *** >
                            *** > thanks,
                            *** > -chandra.
                            ***
                            *** You might want to use a mark then (see ":help mark-motions"). ("The
                            *** implementation details are left as an exercise to the reader.")
                            ***
                            *** Regards,
                            *** Tony.
                            ***
                            ***
                          • Antoine J. Mechelynck
                            ... I was just to lazy to figure it out. Maybe it doesn t work after all. But if you say your function keeps the highlight with the text, no need trying to
                            Message 13 of 19 , Oct 4, 2004
                            • 0 Attachment
                              Dave Silvia <dsilvia@...> wrote:
                              > That's quite an exercise for the reader. I looked in motion.txt,
                              > windows.txt, and pattern.txt for clues as well as VimgrepHelp on
                              > 'mark', but cannot seem to find anything that mentions relating a
                              > mark to a match/highlight/syntax. If you're thinking of:
                              >
                              > > execute 'match grp "\%'.line("'Z").'l.*"'
                              >
                              > the line is translated only at the time of execution, so the
                              > highlighting stays with the original line number. So, I'm stumped!(
                              >
                              > Can I get a hint?)
                              >
                              > thx,
                              > Dave S.

                              I was just to lazy to figure it out. Maybe it doesn't work after all. But if
                              you say your function keeps the highlight with the text, no need trying to
                              figure out some fancier way of doing the same.

                              Best regards,
                              Tony.
                            • Antony Scriven
                              ... Perhaps the shomarks.vim script will help here. ... I presume that if the text changes then you ll lose the highlight. Or if the line occurs elsewhere then
                              Message 14 of 19 , Oct 4, 2004
                              • 0 Attachment
                                Antoine J. Mechelynck wrote:

                                > Dave Silvia <dsilvia@...> wrote:
                                > > That's quite an exercise for the reader. I looked in
                                > > motion.txt, windows.txt, and pattern.txt for clues as
                                > > well as VimgrepHelp on 'mark', but cannot seem to find
                                > > anything that mentions relating a mark to a
                                > > match/highlight/syntax. If you're thinking of:
                                > >
                                > > > execute 'match grp "\%'.line("'Z").'l.*"'
                                > >
                                > > the line is translated only at the time of execution,
                                > > so the highlighting stays with the original line
                                > > number. So, I'm stumped!(
                                > >
                                > > Can I get a hint?) [...]
                                >
                                > I was just to lazy to figure it out. Maybe it doesn't
                                > work after all.

                                Perhaps the shomarks.vim script will help here.

                                > But if you say your function keeps the highlight with the
                                > text, no need trying to figure out some fancier way of
                                > doing the same.

                                I presume that if the text changes then you'll lose the
                                highlight. Or if the line occurs elsewhere then you'll have
                                duplicatde highlighting. But I think this is preferable to
                                highlighting the line by its number.

                                Antony
                              • Dave Silvia
                                You presume correctly!;) thx, Dave S. *** -----Original Message----- *** From: Antony Scriven [mailto:adscriven@fastmail.fm] *** Sent: Monday, October 04, 2004
                                Message 15 of 19 , Oct 4, 2004
                                • 0 Attachment
                                  You presume correctly!;)

                                  thx,
                                  Dave S.

                                  *** -----Original Message-----
                                  *** From: Antony Scriven [mailto:adscriven@...]
                                  *** Sent: Monday, October 04, 2004 4:35 AM
                                  *** To: vim users' list
                                  *** Subject: Re: Using internal-variables in regexp
                                  ***
                                  ***
                                  *** Antoine J. Mechelynck wrote:
                                  ***
                                  *** > Dave Silvia <dsilvia@...> wrote:
                                  *** > > That's quite an exercise for the reader. I looked in
                                  *** > > motion.txt, windows.txt, and pattern.txt for clues as
                                  *** > > well as VimgrepHelp on 'mark', but cannot seem to find
                                  *** > > anything that mentions relating a mark to a
                                  *** > > match/highlight/syntax. If you're thinking of:
                                  *** > >
                                  *** > > > execute 'match grp "\%'.line("'Z").'l.*"'
                                  *** > >
                                  *** > > the line is translated only at the time of execution,
                                  *** > > so the highlighting stays with the original line
                                  *** > > number. So, I'm stumped!(
                                  *** > >
                                  *** > > Can I get a hint?) [...]
                                  *** >
                                  *** > I was just to lazy to figure it out. Maybe it doesn't
                                  *** > work after all.
                                  ***
                                  *** Perhaps the shomarks.vim script will help here.
                                  ***
                                  *** > But if you say your function keeps the highlight with the
                                  *** > text, no need trying to figure out some fancier way of
                                  *** > doing the same.
                                  ***
                                  *** I presume that if the text changes then you'll lose the
                                  *** highlight. Or if the line occurs elsewhere then you'll have
                                  *** duplicatde highlighting. But I think this is preferable to
                                  *** highlighting the line by its number.
                                  ***
                                  *** Antony
                                Your message has been successfully submitted and would be delivered to recipients shortly.