I have the current file (current location being [n])
The [p]hilosophical chicken saw the street
The red dog saw the street
The red dog crossed the street
The apple was red
The red dog crossed the street
The red dog was sleeping
I want to change the next 4 lines that contain red dog to philosophical chicken
This is a situation I routinely run into and end up using the mouse.
What is the quickest way to do this with minimal keystrokes?
I have attempted so far
- Counted the lines by pushing Ctrl+g, counting the next lines and doing
:2,5s:red dog:philosophical chicken:g
- Lot of time, thinking and typing
- Macro ->
qu
/red dog
Enter
c2W
philosophical chicken
Esc
/red dog
Enter
q
2@u
- Once complete, about as fast as using substitute (:s)
2yW j P 2dE
- Yank two words (ignoring punctuation), go down 1 line, paste before the cursor and delete two words- Quickly completes one line, but now my buffer contains red dog, so I have to go back and recapture the buffer.
- Highlight philosophical chicken with mouse in terminal, hit
Ctrl+Shift+C
,j 2cW
+ Ctrl+Shift+V,Esc
- Copy text, go down one line, change two words and enter Insert mode and paste, Esc escapes insert mode- Mouse in vim? :(
c2W
philosophical chicken
Esc
?red dog
Enter
.N.N.
- Change two words, type "philosophical chicken" escape, reverse search for "red dog", do last action (change 2 words to philosophical chicken), repeat- Have to type two full words again
So far using the mouse, copying and pasting with change has been the fastest way for me. This cannot be the right way.
How should I be doing this?
Ideally, I'd like to yank 2 words, navigate to red dog
and replace 2 words with the yanked buffer.
"0p
or"0P
(that is zero, not the letter o) to paste last yanked text...