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

Re: Substitute within a highlight group.

Expand Messages
  • David Fishburn
    ... This one is tough. What the plugin does, it is positions the cursor to the required highlight group and then runs Vim s standard regex. Since you said .*,
    Message 1 of 19 , Jan 1, 2011
    • 0 Attachment

      On 12/30/2010 10:41 PM, sergio wrote:
      On 12/31/2010 06:13 AM, David Fishburn wrote:

      As Chip mentioned, I definitely want to know of any bugs.

      1)
      I've not understand how to select highlight group from script.
      (For example I need to select zoneSerial group)

      2)
      % vim bindzone
      :source incoming/srhg/plugin/SrchRplcHiGrp.vim
      <GOTO zone serial>
      :SRChooseHiGrp
      SRHiGrp - Group ID: 97  Name: zoneSerial
      :SRHiGrp '\(.*\)','__\1__'
      .* also includes comment, that exists on this line: so I get:
      __2007031901 ; serial__
      instead of:
      __2007031901__ ; serial


      This one is tough.

      What the plugin does, it is positions the cursor to the required highlight group and then runs Vim's standard regex.

      Since you said .*, that means until the end of the line.

      I think what you wanted to do in your case was simply:
      :SRHiGrp '\(\w\+\)','__\1__'
      or
      :SRHiGrp '\(\d\+\)','__\1__'

      This took care of the entire file:
      :%SRHiGrp '\(\d\+\)','__\1__'


      3)
      <GOTO ip address>
      :SRChooseHiGrp
      SRHiGrp - Group ID: 94  Name: zoneIPAddr
      :SRSearch
      goes to the next octet of selected ip address, not to the next ip address.

      <GOTO zoneDirective>
      :SRChooseHiGrp
      SRHiGrp - Group ID: 89  Name: zoneDirective
      :SRSearch
      first SRSearch (from neutral space) goes to '$' of next directive,
      second --- to the first letter after $ of the same directive.

      I agree.

      I have uploaded a new version 5.0 to address this.
      http://www.vim.org/scripts/script.php?script_id=848

      Please provide further feedback if you have more.
      Dave

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • sergio
      ... I guessed. ... Yes, in my case this will work fine. But what if group may have spaces? some c code /* comment with spaces */ some c code; And you want to
      Message 2 of 19 , Jan 1, 2011
      • 0 Attachment
        On 01/01/2011 11:03 PM, David Fishburn wrote:

        > What the plugin does, it is positions the cursor to the required
        > highlight group and then runs Vim's standard regex.
        I guessed.

        > This took care of the entire file:
        > :%SRHiGrp '\(\d\+\)','__\1__'
        Yes, in my case this will work fine.
        But what if group may have spaces?
        some c code /* comment with spaces */ some c code;
        And you want to remove this comment? Or something else.
        Of course you can write something like this:
        :%SRHiGrp '\/\*.*\{-}\/\*',''
        But this only adds difficulty to regex and makes it dependent on case.
        I know, this is dumb example, but I can't find good one.

        > I have uploaded a new version 5.0 to address this.
        > http://www.vim.org/scripts/script.php?script_id=848
        Thank you. Now search works good.

        And how to select group for replace from script (without cursor
        positioning)?

        --
        sergio.

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • sergio
        Hello, David. I did not understand how how to select group from script. For example I still want to substitute zoneSerial in bindzone file.
        Message 3 of 19 , Jan 15, 2011
        • 0 Attachment
          Hello, David.

          I did not understand how how to select group from script.
          For example I still want to substitute zoneSerial in bindzone file.
          <GOTO zone serial>
          :SRChooseHiGrp
          :%SRHiGrp '\(\d\+\)','test'
          How to do this from script?

          --
          sergio.

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • David Fishburn
          ... You simply run those commands from within your script. Have you tried it? If so, what kind of problems did you run into? Dave -- You received this message
          Message 4 of 19 , Jan 17, 2011
          • 0 Attachment
            On 1/15/2011 1:20 PM, sergio wrote:
            Hello, David.

            I did not understand how how to select group from script.
            For example I still want to substitute zoneSerial in bindzone file.
             <GOTO zone serial>
             :SRChooseHiGrp
             :%SRHiGrp '\(\d\+\)','test'
            How to do this from script?

            You simply run those commands from within your script.

            Have you tried it?
            If so, what kind of problems did you run into?

            Dave

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • sergio
            ... No. Because I don t know how to select zoneSerial group from script. The first action that I need to do it is put my cursor to serial group. I do this with
            Message 5 of 19 , Jan 17, 2011
            • 0 Attachment
              On 01/18/2011 05:55 AM, David Fishburn wrote:

              >> <GOTO zone serial>
              ^^^^^^^^^^^^^^^^^^
              >> :SRChooseHiGrp

              > You simply run those commands from within your script.
              > Have you tried it?
              No. Because I don't know how to select zoneSerial group from script.
              The first
              action that I need to do it is put my cursor to serial group. I do this
              with my
              ←↓→↑ keys. And than I say SRChooseHiGrp to select it. I can do SRChooseHiGrp
              from script, but I can't do the first action from script.

              --
              sergio.

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • Christian Brabandt
              ... You need to script a little bit. Something like this: fu! FindzoneSerial() try let stop=0 let wv=winsaveview() 1 while line( . )
              Message 6 of 19 , Jan 18, 2011
              • 0 Attachment
                On Tue, January 18, 2011 8:40 am, sergio wrote:
                > On 01/18/2011 05:55 AM, David Fishburn wrote:
                >
                >>> <GOTO zone serial>
                > ^^^^^^^^^^^^^^^^^^
                >>> :SRChooseHiGrp
                >
                >> You simply run those commands from within your script.
                >> Have you tried it?
                > No. Because I don't know how to select zoneSerial group from script.
                > The first
                > action that I need to do it is put my cursor to serial group. I do this
                > with my
                > keys. And than I say SRChooseHiGrp to select it. I can do
                > SRChooseHiGrp
                > from script, but I can't do the first action from script.

                You need to script a little bit. Something like this:

                fu! FindzoneSerial()
                try
                let stop=0
                let wv=winsaveview()
                1
                while line('.') < line('$') && !stop
                if search('\<\d\{9,10}\(\s\|;\|$\)\@=') > 0 &&
                \ synIDattr(synID(line('.'), col('.'),1), 'name') =~ 'zoneSerial'
                let stop=1
                XXX
                endif
                endwhile
                finally
                call winrestview(wv)
                endtry
                endfun

                This searches for the pattern, that is defined as zoneSerial in
                $VIMRUNTIME/syntax/bindzone.vim
                (see yourself and adjust pattern as you like. You could also
                simply search for \d\+, that should work as well.)

                The part that is marked with XXX needs to be replaced with your
                code :SRChooseHiGrp or whatever you want to do with the zoneSerial
                highlighting.

                regards,
                Christian

                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • David Fishburn
                ... SRSearch optionally takes parameters. So you can do something like this: SRSearch vimFuncName SRSearch vimF to complete the names. Obviously, the list
                Message 7 of 19 , Jan 28, 2011
                • 0 Attachment
                  On 1/18/2011 2:40 AM, sergio wrote:
                  On 01/18/2011 05:55 AM, David Fishburn wrote:

                  <GOTO zone serial>
                     ^^^^^^^^^^^^^^^^^^
                  :SRChooseHiGrp

                  You simply run those commands from within your script.
                  Have you tried it?
                  No. Because I don't know how to select zoneSerial group from script. The first
                  action that I need to do it is put my cursor to serial group. I do this with my
                  ←↓→↑ keys. And than I say SRChooseHiGrp to select it. I can do SRChooseHiGrp
                  from script, but I can't do the first action from script.

                  SRSearch optionally takes parameters.

                  So you can do something like this:
                  SRSearch vimFuncName

                  SRSearch vimF<Tab> to complete the names.

                  Obviously, the list of names varies based on what type of file you are editing and what syntax objects are already available.

                  So, if you cursor keyed to zoneSerial Group, and ran:
                  SRChooseHiGrp

                  The output displayed is:
                  SRHIGrp - Group ID: 270 Name: vimFuncName

                  This means in your script, you can do:
                  SRSearch VimFuncName


                  For a new feature, I think making that function publicly available like this:

                  if( SRSearch('vimFuncName') > 0 then ...

                  Might be useful so that the script has some feedback that something was found. 
                  What you have to do right now is save the current line and column position:
                          let curcol    = col(".")
                          let curline   = line(".")

                  Call SRSearch, then check to see if the current column position has changed.  If so, assume the find was successful.

                  HTH,
                  Dave



                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php
                • David Fishburn
                  -- David Fishburn Solutions Architect iAnywhere Solutions / Sybase ... Just for the archives, see my previous response, this code is not necessary since you
                  Message 8 of 19 , Jan 28, 2011
                  • 0 Attachment


                    --
                    David Fishburn
                    Solutions Architect
                    iAnywhere Solutions / Sybase
                    On 1/18/2011 4:01 AM, Christian Brabandt wrote:
                    On Tue, January 18, 2011 8:40 am, sergio wrote:
                    
                    On 01/18/2011 05:55 AM, David Fishburn wrote:
                    
                    
                    <GOTO zone serial>
                    
                        ^^^^^^^^^^^^^^^^^^
                    
                    :SRChooseHiGrp
                    
                    You simply run those commands from within your script.
                    Have you tried it?
                    
                    No. Because I don't know how to select zoneSerial group from script.
                    The first
                    action that I need to do it is put my cursor to serial group. I do this
                    with my
                     keys. And than I say SRChooseHiGrp to select it. I can do
                    SRChooseHiGrp
                    from script, but I can't do the first action from script.
                    
                    You need to script a little bit. Something like this:
                    
                    Just for the archives, see my previous response, this code is not necessary since you can do everything from what the plugin provides for you.

                    Dave

                    --
                    You received this message from the "vim_use" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php
                  • sergio
                    ... Oh. I v already done without srhg. May be it will be usefull for someone. This function finds DNS zone serial and increments it. function AdjustSerial()
                    Message 9 of 19 , Jan 30, 2011
                    • 0 Attachment
                      On 01/28/2011 07:27 PM, David Fishburn wrote:

                      > SRSearch optionally takes parameters.
                      Oh.

                      I'v already done without srhg.

                      May be it will be usefull for someone. This function finds DNS zone
                      serial and
                      increments it.

                      function AdjustSerial()
                      let l:pos = getpos( '.' )
                      call cursor( 1, 1 )
                      while search( '\D\zs\d', 'W' ) > 0
                      if synIDattr( synID( line('.'), col('.'), 1 ), 'name' )
                      \ == 'zoneSerial'
                      s/\(\d\+\)/\=IncSerial( submatch( 1 ) )/
                      break
                      endif
                      endwhile
                      call setpos( '.', l:pos )
                      endfunction
                      function IncSerial( s )
                      let l:today = strftime( "%Y%m%d", localtime() )
                      if match( a:s, '^' . l:today ) == 0
                      return str2nr( a:s ) + 1
                      else
                      return l:today . '01'
                      endif
                      endfunction

                      --
                      sergio.

                      --
                      You received this message from the "vim_use" maillist.
                      Do not top-post! Type your reply below the text you are replying to.
                      For more information, visit http://www.vim.org/maillist.php
                    Your message has been successfully submitted and would be delivered to recipients shortly.