Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim using last searched for regex in :s command

Tags:

vim

I am using slash for searching for stuff within vim. I'd like to use the regex that I used for search in a command (a substitute command to be exact). Is there a simple way to do it?

like image 970
Bartosz Radaczyński Avatar asked Sep 07 '09 09:09

Bartosz Radaczyński


People also ask

What does S do in vim?

s (substitute) will delete the current character and place the user in insert mode with the cursor between the two surrounding characters. 3s , for example, will delete the next three characters and place the user in insert mode. c (change) takes a vi/vim motion (such as w , j , b , etc.).

How do we search for old and replace it with new in vim?

To search in the current file, you just need to type / in normal mode. Then, you need to type your search pattern, press enter , and the result becomes highlighted in your file. To go backward and forward through the results, you can type n and N (for n ext) respectively. Using / will search forward in the file.

How do I go to the last line in vim?

On a character in the first line, press Ctrl-V (or Ctrl-Q if Ctrl-V is paste). Press jj to extend the visual block over three lines. Press $ to extend the visual block to the end of each line.


1 Answers

the subtitute command will use the last search if you do not specify it, so just use:

:s//<replacement>
like image 119
heijp06 Avatar answered Oct 18 '22 13:10

heijp06