From 0642385224930683fdb00bc3f7f6cbd6ddc81611 Mon Sep 17 00:00:00 2001 From: alterdepp Date: Thu, 26 May 2011 13:07:23 +0000 Subject: [PATCH] update SrchRplHiGrp git-svn-id: https://vimsuite.svn.sourceforge.net/svnroot/vimsuite/trunk@199 eb2d0018-73a3-4aeb-bfe9-1def61c9ec69 --- vimfiles/doc/SrchRplcHiGrp.txt | 16 +++++++++++++--- vimfiles/plugin/SrchRplcHiGrp.vim | 26 +++++++++++++++----------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/vimfiles/doc/SrchRplcHiGrp.txt b/vimfiles/doc/SrchRplcHiGrp.txt index 979bf8b..081d3ec 100644 --- a/vimfiles/doc/SrchRplcHiGrp.txt +++ b/vimfiles/doc/SrchRplcHiGrp.txt @@ -1,6 +1,6 @@ *SrchRplcHiGrp.txt* Search and Replace Restricted to a Highlighting Group -Author: David Fishburn January 22, 2008 +Author: David Fishburn January 1, 2011 ============================================================================== @@ -80,6 +80,10 @@ Author: David Fishburn January 22, 2008 selected via SRChooseHiGrp and begin the search. If no valid group name was specified, an error message will be reported. + Running SRSearch a second time will ensure the cursor is + positioned on the next separate highlight matched text. + There must be a gap between the two groups. + SRHiGrp[!] *SRHiGrp* This command will perform a search and replace over a visual range. It works in all visual modes, characterwise (v), @@ -114,9 +118,15 @@ Author: David Fishburn January 22, 2008 ------- First place your cursor on an item that is syntax colored the way - you want: + you want. Notice the command takes an optional !. If your first + search and replace doesn't work, you can undo the change and reselect + the group using the ! and try again. > :SRChooseHiGrp + SRHiGrp - Group ID: 562 Name: sqlStatement + or + :SRChooseHiGrp! + SRHiGrp - Group ID: 51 Name: Statement < Next, visually select a block of text (all visual modes are supported) @@ -141,7 +151,7 @@ Author: David Fishburn January 22, 2008 highlighted yellow (based on my colorscheme). After I visually select the area and run the command taking default prompts: > - :'<,'>SRHiGrp + :'<,'>SRHiGrp < The result is: > diff --git a/vimfiles/plugin/SrchRplcHiGrp.vim b/vimfiles/plugin/SrchRplcHiGrp.vim index 8e06ea2..f28e4c1 100644 --- a/vimfiles/plugin/SrchRplcHiGrp.vim +++ b/vimfiles/plugin/SrchRplcHiGrp.vim @@ -1,8 +1,8 @@ " SrchRplcHiGrp.vim - Search and Replace based on a highlight group " -" Version: 4.0 -" Author: David Fishburn -" Last Changed: Mon 21 Jan 2008 06:17:14 PM Eastern Standard Time +" Version: 5.0 +" Author: David Fishburn +" Last Changed: 2011 Jan 01 " Created: Tue Dec 02 2003 10:11:07 PM " Description: Search and Replace based on a syntax highlight group " Script: http://www.vim.org/script.php?script_id=848 @@ -20,7 +20,7 @@ if exists('g:loaded_srhg') || &cp || !exists("syntax_on") finish endif -let g:loaded_srhg = 1 +let g:loaded_srhg = 5 " Default the highlight group to 0 let s:srhg_group_id = 0 @@ -427,16 +427,20 @@ function! SRSearch(fline, lline, ...) "{{{ endif while line(".") <= s:srhg_lastline - let curcol = col(".") - let curline = line(".") - let cursynid = (s:srhg_group_id < 0) ? - \ -synID(line("."),col("."),1) : - \ synIDtrans(synID(line("."),col("."),1)) - let cursynid = (s:srhg_group_id < 0) ? synID(line("."),col("."),1) : synIDtrans(synID(line("."),col("."),1)) + let curcol = col(".") + let curline = line(".") + let cursynid = (s:srhg_group_id < 0) ? synID(line("."),col("."),1) : synIDtrans(synID(line("."),col("."),1)) + let prevsynid = (s:srhg_group_id < 0) ? synID(line("."),(col(".")-1),1) : synIDtrans(synID(line("."),(col(".")-1),1)) " Useful debugging statement: " echo col(".").':'.getline(".")[col(".")-1].':'.cursynid.':'.getline(".") - if line(".") == curline + " if line(".") == curline + " Check the current syn id against the previous columns syn id. + " If they are the same, assume we are still part of the same "string" + " and we need to continue searching until we find a gap between the + " highlight groups indicating we are actually on our next match + " (Sergio). + if line(".") == curline && (cursynid != prevsynid) if cursynid == gid call s:SRDispHiGrp( "SRSearch - Match found - Group ID: " . \ gid . " Name: " . synIDattr(gid,"name")