Sunday, February 16, 2014

Vim Tip - Search Current Word

VIM is my favorite editor. Why? What should be a programmer's favorite editor? My answer would be one that's programmable and behold there is VIM for you*. It's so versatile that it amazes me. I keep on learning new stuff all the time.

Without further ado here is a quick tip. How do you search for the current word under your cursor with one keystroke? Use '*' or '#' to search forward and backwards respectively.

It's pretty neat and you will find it using more often then you can imagine. Whenever you're figuring out what some code does you always want to know where the current variable is being used next or previously and highlighting all of it's usage is a very common use case, that's where you can use this most often. You may find use cases for your own needs that fit the bill which is awesome.

For those folks who use XCode (it's a good enough IDE) along with XVim to get the VIM bindings for Xcode you can still use the above functionality. The only caveat is that it doesn't highlight all the instance as vim does, it would just take you to the next/previous one.


* This is based on my own feeling. You might like Emacs which again is a great editor. I've had some experience working on it but the <Ctrl> just didn't fit in.