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
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With