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

Substitute within a highlight group.

Expand Messages
  • sergio
    Hello. Is there a way to substitute within a highlight group? I have file, with detected filetype and applied syntax. Syntax gives the group. And I want to
    Message 1 of 19 , Dec 28, 2010
    • 0 Attachment
      Hello.

      Is there a way to substitute within a highlight group?

      I have file, with detected filetype and applied syntax. Syntax gives the
      group. And I want to make a substitution, for that text, that matches
      this group. (Really this is a bindzone file, and I want to adjust serial
      value)

      --
      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. Is there a way to substitute within a highlight group? I have file, with detected filetype and applied syntax. Syntax gives the group. And I want to
      Message 2 of 19 , Dec 28, 2010
      • 0 Attachment
        Hello.

        Is there a way to substitute within a highlight group?

        I have file, with detected filetype and applied syntax. Syntax gives the
        group. And I want to make a substitution, for that text, that matches
        this group. (Really this is a bindzone file, and I want to adjust serial
        value)

        --
        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
      • Charles E Campbell Jr
        ... See if David Fishburn s SrchRplcHiGrp plugin does what you want: http://www.vim.org/script.php?script_id=848 Regards, Chip Campbell -- You received this
        Message 3 of 19 , Dec 29, 2010
        • 0 Attachment
          sergio wrote:
          > Hello.
          >
          > Is there a way to substitute within a highlight group?
          >
          > I have file, with detected filetype and applied syntax. Syntax gives
          > the group. And I want to make a substitution, for that text, that
          > matches this group. (Really this is a bindzone file, and I want to
          > adjust serial value)
          >
          See if David Fishburn's SrchRplcHiGrp plugin does what you want:

          http://www.vim.org/script.php?script_id=848

          Regards,
          Chip Campbell

          --
          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
          ... Yes, it does. But it s buggy and old. Can vim do this without plugins? -- sergio. -- You received this message from the vim_use maillist. Do not
          Message 4 of 19 , Dec 30, 2010
          • 0 Attachment
            On 12/30/2010 05:13 AM, Charles E Campbell Jr wrote:

            > See if David Fishburn's SrchRplcHiGrp plugin does what you want:
            > http://www.vim.org/script.php?script_id=848

            Yes, it does. But it's buggy and old.

            Can vim do this without plugins?

            --
            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
          • Charles E Campbell Jr
            ... No. If you find a bug, send a note to David Fishburn. His email address is contained in the header portion of the plugin. Chip -- You received this
            Message 5 of 19 , Dec 30, 2010
            • 0 Attachment
              sergio wrote:
              > On 12/30/2010 05:13 AM, Charles E Campbell Jr wrote:
              >
              >> See if David Fishburn's SrchRplcHiGrp plugin does what you want:
              >> http://www.vim.org/script.php?script_id=848
              >
              > Yes, it does. But it's buggy and old.
              >
              > Can vim do this without plugins?
              >
              No. If you find a bug, send a note to David Fishburn. His email
              address is contained in the header portion of the plugin.

              Chip

              --
              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
              ... Old does not make a plugin useless. No changes have been made to it since it has so far done what I and others have needed. As Chip mentioned, I definitely
              Message 6 of 19 , Dec 30, 2010
              • 0 Attachment
                On Dec 30, 2010, at 7:04 PM, Charles E Campbell Jr <drchip@...> wrote:

                > sergio wrote:
                >> On 12/30/2010 05:13 AM, Charles E Campbell Jr wrote:
                >>
                >>> See if David Fishburn's SrchRplcHiGrp plugin does what you want:
                >>> http://www.vim.org/script.php?script_id=848
                >>
                >> Yes, it does. But it's buggy and old.
                >>
                >> Can vim do this without plugins?
                >>
                > No. If you find a bug, send a note to David Fishburn. His email address is contained in the header portion of the plugin.
                >
                >

                Old does not make a plugin useless.

                No changes have been made to it since it has so far done what I and others have needed.

                As Chip mentioned, I definitely want to know of any bugs. Please provide explicit instructions so that I can reproduce this issue and include your Vim version.

                --
                David Fishburn

                --
                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
                ... 1) I ve not understand how to select highlight group from script. (For example I need to select zoneSerial group) 2) % vim bindzone ...
                Message 7 of 19 , Dec 30, 2010
                • 0 Attachment
                  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

                  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.


                  --
                  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
                  Hi sergio! ... Without having used the mentioned script, I would probably use something ... (one line) As you can see, I made the regex more strict, since .*
                  Message 8 of 19 , Dec 31, 2010
                  • 0 Attachment
                    Hi sergio!

                    On Fr, 31 Dez 2010, sergio wrote:

                    > 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

                    Without having used the mentioned script, I would probably use something
                    like this:
                    :%s/\<\d\+\>/\=synIDattr(synID(line('.'),col('.'),1),'name')=~'zoneSerial?'__'.submatch(1).'__':submatch(1)/g
                    (one line)

                    As you can see, I made the regex more strict, since .* will probably
                    always match a whole line and could obviously be part of several
                    different syntax items.

                    If you need this more often, this can probably be scripted or put into
                    functions for easier use.

                    > 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.

                    Don't understand, what you are trying to do here.

                    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
                    Can you provide the text of the file you are editing. -- David Fishburn ... -- You received this message from the vim_use maillist. Do not top-post! Type
                    Message 9 of 19 , Dec 31, 2010
                    • 0 Attachment
                      Can you provide the text of the file you are editing.

                      --
                      David Fishburn


                      On Dec 30, 2010, at 10:41 PM, sergio <mailbox@...> 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
                      >
                      > 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.
                      >
                      >
                      > --
                      > 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

                      --
                      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
                      ... Forgot to say, I m using vim 7.3.35 from debian sid. -- sergio. -- You received this message from the vim_use maillist. Do not top-post! Type your reply
                      Message 10 of 19 , Dec 31, 2010
                      • 0 Attachment
                        On 12/31/2010 05:32 PM, David Fishburn wrote:
                        > Can you provide the text of the file you are editing.

                        Forgot to say, I'm using vim 7.3.35 from debian sid.

                        --
                        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
                        ... 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 11 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 12 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 13 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 14 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 15 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 16 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 17 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 18 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 19 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.