Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I rarely use global find and replace nowadays (just for complex regex replaces). I hold Ctrl-D until all occurrences are selected and type the replacement string (assuming occurrences are low in quantity, which they usually are in most cases).


You know crt + H (global find and replace) takes what's highlighted and uses the last thing you looked for it nothing is highlighted.


Ctrl+cmd+g is cmd+d for all occurrences on the page.


visual selection replacement is good too.

:'<,'>s/this/to that/g

I think vim does that automatically when you have a selection active and hit :


Note that this will replace over the entirely lines even if it's a blockwise selection.

So you might consider using :'<,'>s/\%Vthis/to that/g


It might be a setting or something but it definitely doesn't do that on my machine or the linux machine I have in the cloud.

this ipsum dolor sit amet

this ipsum dolor sit amet

this ipsum dolor sit amet

this ipsum dolor sit amet

this ipsum dolor sit amet

select the middle 3 lines and do what I said will give you:

this ipsum dolor sit amet

to that ipsum dolor sit amet

to that ipsum dolor sit amet

to that ipsum dolor sit amet

this ipsum dolor sit amet


That sounds like a lot more work...


No it's not! Plus, you'd get to see the replacement targets while you're holding the keys, so you'd be more confident about the final result.

Just give Ctrl-D a try for a couple of days.. It's a total different user experience compared to the traditional find/replace method.


Do you mean it's a lot of work to type in that prefix? Because vim automatically inserts it for you when you enter command mode while something is visually selected. A making a visual selection is very quick and easy.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: