Sorry for the summer hiatus. Work, vacation, and mountain biking put a serious squeeze on my free time hacking and blogging activities. I have been working on some cool stuff lately and the cold weather is starting to arrive here in Spokane, so I should have plenty of blog posts coming up.
Anyway, quick vim tip #1. If I have a chunk of a code with a string:
var blah = "Some string that I want to replace" + previouslyDefinedVariable
I want to replace it with “new string”. In vim, do:
- Put your cursor on the first character inside the quotes of the string you want to end up with, in our case, the n from “new string”.
- Type yi” – yank inbetween quotes
- Navigate to the string you want to replace
- Type di” – delete inbetween quotes
- “0P – paste content from yank buffer
- Marvel at your vim prowess.
Got any great vim tips? I would love to here about them. Send them to vimtips@fzysqr.com. Check out my full vim config fork of scrooloose’s config on github (here)[https://github.com/jslatts/vimfiles].
Updated Cory Schmitt wrote in with a helpful suggestion that saves two keystrokes!
- Put your cursor on the first character inside the quotes of the string you want to end up with, in our case, the n from “new string”.
- Type yi” – yank inbetween quotes
- Navigate to the string you want to replace
- Type vi”p – visual mode select inbetween quotes and paste over
- Congratulate yourself for being awesome.