3 ms·
Regarding the replace thing: If you are used to sed it should be easy, as it is pretty much the same. I keep using this pattern over and over again: :%s/sea
by JepZ 8y ago
Regarding the replace thing:
If you are used to sed it should be easy, as it is pretty much the same. I keep using this pattern over and over again:
:%s/search/replace/gc
The '%' is some sort of reference to the file you are currently editing and therefore you are doing a replace on the whole file. You can see the difference in combination with some visual selection. When you select some text and press ':' it opens as ":'<,'>"
:% # replace in the whole file
:'<,'> # replace in the current selection
The 'gc' flags at the end are:
g=global to replace multiple times per line
c=confirm to let vim ask you about every replacement
Sometimes its just easier to let vim ask you a few times than to spend 5 minutes to figure out the 100% correct regex.
- bArray 8y agoThank you for explaining this! I will have to practice, replace is something I don't do very often enough to remember but do it often enough that it annoys me each time.