How does one get vim to replace a character within the visual selection only and not elsewhere on the line? Example:
- Line:
int arr[] = { 00 01 02 03 04 05 05 /* ... lots more like this*/};
- Visual Selection:
{ 00 01 02 03 04 05 05 /*... lots more like this*/}
- Command:
:'<,'>s/\ /\,0x/g
- Expected:
int arr[] = {0x00,0x01,0x02,0x03 /* and so on*/};
After performing these actions however, the actual result is:
int,0xarr[],0x=,0x{0x00,0x01,0x02,0x03 /* and so on*/};
Is there a way to modify the command above to produce the expected result? Doesn't '<
and '>
define the range on which the search (and replace) commands work?
:substitute
operatores on a line by line basis, which explains what you are seeing in your example.