SrchRplcHiGrp.vim


Ⅰ. 插件描述

Search and/or replace based on a syntax highlight group

Ⅱ. 基本信息

创建日期:  2004-01-09
使用用户:  1
Github星:  5
插件作者:  David Fishburn

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin '/srchrplchigrp-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle '/srchrplchigrp-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug '/srchrplchigrp-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/vim-scripts/SrchRplcHiGrp.vim

Ⅳ. 文档说明

SR = Search and/or Replace

This plugin defines some commands to allow you to:
1.  Search for characters with a particular syntax highlight group
2.  Search and replace characters with a particular syntax highlight group

Commands:

SRDispHiGrp                
    Displays the syntax id and name the of the syntax group 
    which has been chosen.

SRChooseHiGrp[!]                   

                Before you can run the search and replace command (:SRHiGrp),
                you must choose which syntax group id you want to operate on.  
                The top level syntax id of the current cursor position is
                chosen (ie. the top-level one versus the final one).

                The optional bang lets SRChooseHiGrp use the translated
                syntax ID. This is final one versus the top-level one.

                Assuming we were using a SQL file and placed the cursor on the
                FROM word, then using the SyntaxAttr plugin
                (http://vim.sourceforge.net/script.php?script_id=383)
                it displays both the top-level and translated
                (or final) highlight group as follows:
                  group: sqlKeyword->Statement guifg=#ffff00(#ffff00)

    Examples: 
      :SRChooseHiGrp 

                      Will operate on only sqlKeyword syntax groups

      :SRChooseHiGrp! 

                      Will operate on all Statement syntax groups.  Based on
                      |group-name|, the Statement group will highlight the
                      same color for the following highlight groups:
                            Conditional
                            Repeat
                            Label
                            Operator
                            Keyword
                            Exception
                      Therefore SRChooseHiGrp! will operate over all of the
                      above syntax groups.

SRHiGrp[!]                                  

                This command will perform a search and replace over a visual
                range.  It works in all visual modes, characterwise (v),
                linewise (V) and blockwise (<C-V>).

    It optionally takes takes 2 parameters.

                Parameter 1 controls what characters are matched.  The default
                for this value is (w+>).  This expression is appended to
                the %# which starts the match from the current cursor
                position.  This expression must specify a submatch (...).

    Parameter 2 controls what to do with the matched string.  The
    default for this value is \U\1.  This expression will cause
    the matched string to be UPPER cased.  The \1 refers to the 

                submatch from the first parameter.

    If the parameters are not supplied, the user will be prompted
    to enter the expression(s).

                The optional bang (!) works the same as SRHiGrp, but will
                operate on all syntax groups that are NOT the chosen one
                (SRChooseHiGrp).

    Syntax: 
    [range]SRHiGrp[!] 'from-pattern','to-string'
SRSearch[!]                                   

                This command will perform a forward search starting at the current
                cursor position for a specified highlight group name.  The range defaults
                to the entire file.  It supports all visual modes, characterwise (v),
                linewise (V) and blockwise (<C-V>).

                It will optionally take a regular expression and match on both the syntax
                group and the regular expression.

                When using SRSearch! it NOT match the syntax group.

==============================================================================

  1. Examples srchrplchigrp-examples

   SRHiGrp
   -------

First place your cursor on an item that is syntax colored the way
you want:
    :SRChooseHiGrp

Next, visually select a block of text
(all visual modes are supported)
    :SRHiGrp
    or
    :SRHiGrp '\(\w\+\>\)'
    or
    :SRHiGrp '\(\w\+\>\)', '\U\1'

If you had the following in a SQL file:
    if exists( select 1
                from sys.sysprocedure sp
                 key join sys.sysuserperm sup
               where sp.proc_name = 'sp_http_course_detail'
                 and sup.user_name = user_name()             ) then
        drop procedure sp_http_course_detail;
    end if;

Where the keywords (if, exists, select, from ...) are all 
highlighted yellow (based on my colorscheme).  After I visually
select the area and run the command taking default prompts:
    :'<,'>SRHiGrp 

The result is:
    IF EXISTS( SELECT 1
                FROM sys.sysprocedure sp
                 KEY JOIN sys.sysuserperm sup
               WHERE sp.proc_name = 'sp_http_course_detail'
                 AND sup.user_name = user_name()             ) THEN
        DROP PROCEDURE sp_http_course_detail;
    END IF;

Where the keywords (if, exists, select, from ...) are all 
highlighted yellow (based on my colorscheme).  After I visually
select the area and run the command taking default prompts: 
    :'<,'>SRHiGrp!

The result is:
    if exists( select 1
                from SYS.SYSPROCEDURE SP
                 key join SYS.SYSUSERPERM SUP
               where SP.PROC_NAME = 'SP_HTTP_COURSE_DETAIL'
                 and SUP.USER_NAME = USER_NAME()             ) then
        drop procedure SP_HTTP_COURSE_DETAIL;
    end if; 

   SRSearch
   --------------

SRSearch simply does a forward search for the specified highlight

        group.  You must first use SRChooseHiGrp to choose a highlight group.
        Find the next item highlighted as that syntax group:  

    :SRSearch 
    :1,5SRSearch 
    :'<,'>SRSearch 

        Find the next item highlighted that is NOT that syntax group:

    :SRSearch!
    :1,5SRSearch! 
    :'<,'>SRSearch! 

        Find the next item highlighted as that syntax group and matches
        the regular expression supplied:

    :SRSearch something
    :SRSearch \(first\|second\|word\)

        Find the next item highlighted that is NOT that syntax group and
        matches the regular expression supplied:

    :SRSearch! \(first\|second\|word\)

        The results of the search is displayed in the command line and is
        highlighted in the color of the syntax group.  This will remind you
        which group was searched for.
            SRSearch - Match found - Group ID: 171  Name: sqlKeyword
            SRSearch - Match NOT found - Group ID: 171  Name: sqlKeyword
            SRSearch - Match found - Group ID: 171  Name: sqlKeyword  Regex: (first|second|word)
            SRSearch - Match NOT found - Group ID: 171  Name: sqlKeyword  Regex (first|second|word)

添加新评论