Partial line Vim permanent replacement

we can replace vim with a set of strings by selecting them in visual mode and entering command mode. it automatically fills the selected range
: '& L;' >

and we can do the replacement like: '& L;' > s / TestSubstitute // ds

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

: `<,` `> [then replace the command]

As a rule, I copy a set of field names separated by "," metrics in vim, and would like to calculate the number of columns, which can be determined by the number of comma entries, when all field names are selected in visual mode.

select fname, lastmodtime, lastaccesstime from fileInfo;

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

Thanks in advance,
Naga Kieran

+5
source share
1 answer

Use the modifier \%Vin the template expression. This will make vim fit only inside the visual block that you are in or were in before. Use the modifier as follows:

:s/\%Vpattern/substitution/

In visual mode, this will display as :.

:'<,'>s/\%Vpattern/substitution/
+11
source

All Articles