Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make a visual block the current search term?

Tags:

vim

Lets say there is some block of text that I want to search for in the file. Is there a way to make a visual-block selection of that text and then make it the current search term? That way I'd be able to do s//replacementText/g without typing the whole thing on the left side of the substitute command.

like image 657
Chris Avatar asked Sep 08 '12 13:09

Chris


1 Answers

Make a visual block and yank it to the unnamed register "": with a visual block selected, type y to yank. Begin the search with / - or :s/ and type Ctrl-r then " to insert the contents of the unnamed register as the search term.

This won't make the block the current search, but it's nearly as easy.

Ctrl-r can be used anywhere in the command-line, so you can also use this e.g. to fill in the substitution or replacement text, or in insert mode.

like image 145
pb2q Avatar answered Sep 21 '22 10:09

pb2q