:: home : bio : blog
A storm in the distance, hopefully receding.
September
Sun Mon Tue Wed Thu Fri Sat
         
9

Contact


 

Archives

Recent Posts

Sat, 09 Sep 2023
WILL: Substituting Within Vim Visual Selection Only
# 16:00 in ./tech

In vim you can be in a visual selection mode, perhaps selecting only parts of the text file. Normally, a substitution operation (e.g. replace string "2022" with "2023") operates on a whole line (or range of lines). To restrict this to operate only on the visual selection you have, use the "\%V" pattern at the start of your search.

So, assuming a visual selection is highlighted and within this I want to change "-" to " " :

:'<,'>s/\%V\-/ /g

A highlight containing "This-is-a-test" becomes "This is a test".

See Vim help %V

Reference :


© Alastair Sherringham 2023
Powered by Blosxom.
Still going after all these years.