tags:

views:

131

answers:

1

Hi,

we can perform vim substitute on a set of lines by selecting them in visual mode and entering command mode. it auto populates the selected range
:'<,'>

and we can perform substitute like :'<,'>s/TestSubstitute//gc

I would like to know is it possible in vim to perform substitute command on a partial line selected in visual mode, so something like

:`<,``> [followed by substitute command]

Generally,i will copy a set of field names separated by delimeter "," in vim and would like to calculate the column count which can be determined by the number of comma occurrences once all the field names are selected in visual mode.

select fname,lastmodtime,lastaccesstime from fileInfo;

If i select the text from fname to lastaccesstime in visual mode and would like to know the number of commas in the selected text.

Thanks in advance,
Naga Kiran

+8  A: 

Use \%V modifier in pattern expression. It will force vim to match only within visual block you're currently in or were in before. Use the modifier like this:

:s/\%Vpattern/substitution/

In visual mode this will be shown as:.

:'<,'>s/\%Vpattern/substitution/
Pavel Shved