" -*- vim -*- " FILE: "c:/vim/Vimfiles/plugin/multipleRanges.vim" {{{ " LAST MODIFICATION: "Sat, 27 Jul 2002 21:02:33 Eastern Daylight Time" " (C) 2002 by Salman Halim, " $Id:$ }}} " Version history: " " 1.65: Removed the keyword from the internal script mappings; Vikas " Agnihotri pointed out that this was causing a problem with potential " reloading of the script while not adding anything to the ease of use. " " 1.6: Added support for user-defined highlights for the ranges (GUI only; " will do cterm if asked). Suggested by Vikas Agnihotri. " " 1.5: Changed the variables within to be buffer-specific instead of " window-specific. This was causing problems when another buffer was opened in " the same window. " " Forgot to add dependency information; depends on my variableSort.vim and " getVar.vim scripts. " " Main feature addition: New mapping to invert the ranges (all bits that were " in a range become deselected and everything else becomes part of a range). " Warning: can be slow in a large file because of all the highlighting that " has to be done. Suggested by Dan Sharp. " " 1.2: Cleans up better once a set of ranges is cleared (the variables are " unlet). " " Added an option (buffer or global variable called 'consolidateRanges') " which, if set to 1, will cause Rangecommand to first sort and then " consolidate overlapping ranges into a single range before executing the " command. The ranges will remain consolidated once the command is done. (The " default is NOT to do the consolidation.) " " 1.1: Added the Showranges command to spew the currently added ranges. " " Cleaned it up to be more plugin-aware (checks to make sure it isn't already " loaded and allows for mappings to be changed by the user); also, changed " method signatures to be contained within the script to avoid possible naming " conflicts elsewhere. " 1.0: Initial upload " " Usage: " " Maps (default): " ar (visual mode): add selected lines as a new range " ar (normal mode): add current line as a new range " cr (normal mode): clear all ranges " ir (normal mode): invert ranges " " Commands: " Rangecommand: executes the arguments as an ex command across all the ranges " specified. " Showranges: spews the list of ranges in the list (in case they've scrolled " of the screen or something); just a convenience feature. Not a particularly " pretty display or anything. " " Options (can be set globally as g: or on a per-buffer basis as " b:): " consolidateRanges (default 0): whether or not to sort and consolidate " overlapping ranges before executing commands " " multipleRangesGuifg (default 'grey90'): default highlight background color " for range " multipleRangesGuibg (default 'black'): default highlight foreground color " for range " multipleRangesGui (default 'reverse'): default highlight gui for range " " Note that substitute operations (such as through the :s command) should " probably be ended with the 'e' flag (no error if nothing found) since each " range is acted upon individually and it's possible that a particular range " will not have any matches. The script will not abort but each failed " substitute will generate an error which may not be what the user wants. " " Range highlighting is done through the Ranges syntax item; this can " obviously be changed to anything the user desires. Suggestion: a slightly " lighter background than used in Visual mode. " TODO: " Allow for range inversion. " " Possible options (if people actually ask for them): " " Consolidate ranges (overlapped ranges become one range) -- only works for " sorted ranges -- not consolidating allows for recursive action (easily " avoided by not specifying overlapped ranges) " " Sort ranges (whether commands should be applied to the ranges in the order " they were specified or whether the range list should be sorted) " " Initially, don't consolidate or sort ranges if exists("loaded_multipleRanges") finish endif let loaded_multipleRanges = 1 if ( !hasmapto( 'AddRange', 'v' ) ) vmap ar AddRange endif vmap