tags:

views:

114

answers:

4
A: 

Try this:

:s//new_value

Why the downvote? You can map something like:

:nmap \s :s///<cr>``i

then search for your text, hit the mapping and you'll be in insert mode where your search text used to be. You can't use . but you can just use n\s for the next match.

There is no builtin text-object describing the text found by a search as far as I know.

kemp
+1  A: 

If you want to visually approve each change you could do

:%s/old/new/gc

Edit: From the other answers sounds like there's no way to get the selection easily. Maybe you could use the python scripting capability in Vim to write a command to do what you want?

nathan
No, this is not something I am looking for.
Quintin Par
I don't think I fully understand the question then. Are you looking something like a macro?
nathan
@nathan: question updated
Quintin Par
+1 I see no reason for the downvote. And I second this answer.
jeffjose
And I believe `%s/old/new/gc` is the closest you can come to visually do something or not.
jeffjose
+1  A: 

Searching for a string with / does not select it - it only highlights it.

To select a region of text click and drag the mouse over it or use the v, V or ctrl-v keys in normal mode (to select a normal region, by lines or rectangular region respectively) then navigate with the usual movement keys to extend the selection. This will put you into visual selection mode.

Once you have some text highlighted and are in visual selection mode you can use the normal editing commands to change the highlighted text, e.g. c will delete the text and put you into insert mode, y will yank the text, gU will change the text uppercase, g? will ROT13 it, etc.

Once you have entered the edit command you will go back into normal mode and the visual highlight will vanish. You can reselect the same region with gv.

Dave Kirby
+1  A: 

Find your text with /foo as usual, then use c//e - but make sure you use // instead of just / or n to find the subsequent matches.

(//e means the last search is repeated, but the cursor is placed at the end of the word, not the beginning. However, the e flag is remembered for the next search, which is why you need to use // afterwards.)

Matthew Slattery