Vim Editing - how to edit a selected search segment or convert to a visual block

In vim, if I have the following text:

Hi there

Let's say I'm looking for hell in the text above.

/hell

and press n to go to the next instance.

hell about

hell is now highlighted in vim and my cursor is at "h".

What is the most efficient way to now output / delete selected text.

Is there a way to "jump to the end of the selected text"? Or "create a visual block from selected text"?

I know that I can use% s / hell / whatever / gc to transition as an alternative.

Tia tom

+4
source share
2 answers

y//e , or d//e should do the trick.

:let @" = @/ even if you move the cursor.

+8
source

I don't know about the built-in mapping ( Change ), but see below, as Luc Hermitte, as this is a much better solution than my Aunts End Edit ), but you can do yank or select with a few mappings:

 nmap ,yy/<CR>/\zs<CR> nmap ,vv/<CR>/<BS>\zs<CR> 

In comparison ,y uses the "/" register to search for the last search query, adds \zs so that the search point is the end, and yank is to this point. Display ,v makes a visual choice, but it needs to remove the last search character (using <BS> ) so that it ends in the right place.

Why can you simplify the %s/hell/whatever/gc that you suggested by refining your search with / , and then using the short form:

 /hell :%s//whatever/gc 

This is because :s uses the last search query by default.

+1
source

All Articles