Change Around

May 15, 2012

For a while now I’ve been using the change inside command.  If you simply hit:

ci

while inside a set of “blocks”(in this case a block can be single-quotes, double-quotes, parens, square braces, etc), vim will remove all the text inside that block and you are automatically put in to insert mode to replace the text.  This is an awesome command.  Today I learned another offset command, the change around command!

Lets say you have text that is just like this:

output = 'Jason'

and you want to replace the string with a reference to a variable called name.  Normally I would probably go to the first single quote and just delete till the other quote however there is a better way!  You can simply hit:

ca

which stands for ‘change around’ and vim will remove the entire ‘block’ including the quotes and you can just type your variable name!  How hot is that?

Discussion, links, and tweets

I'm a developer at thoughtbot.

Follow me on Twitter. I rarely post anything but it can't hurt to try.