Coding Productivity Over 9000
Posted on July 9, 2016
Tags: vim, productivity
Why you should learn and use vim keybindings.
It started 2 years ago when I decided to invest in vim. The first weeks with vim were hell, I wasn’t productive at all. So I consider it as an investment, and it pays well. Let me show you a simple example, let’s say I have this code (written in Swift).
func add(x: Int, y: Int) -> Int {
return x + y;
}
and I want to add another function, that is a multiply function
func multiply(x: Int, y: Int) -> Int {
return x * y;
}
The old days
In the old days, I would need around 10-12 seconds by doing these:
- Move my right hand off the keyboard towards my mouse
- Select the
addfunction - Press
⌘ + c - Move my right hand to the keyboard again, press arrow down then
⌘ + v - Use my mouse to place the cursor at
+operator and replace it with* - Double click
addfunction name and replace it withmultiply
Vim’s way
Let’s see with the approach that I would’ve take with vim, this time it takes around 7-8 seconds:
- Go to visual mode with
vthen press%to block all theaddfunction ctrl + c(yes I have a custom mapping for copy)- Go to the bottom line of
bufferwithG ctrl + v(custom mapping for paste)- Press
kf+s*<ctrl>-{
kmove cursor 1 line up.f+find+operator and move the cursor to its*replace+with*<ctrl>-{back to normal mode
- Press
kHwcwthen typemutiply
kmove cursor 1 line upH(custom mapping) move to the first character at the current linewmove 1 word (toaddfunction name)cwand typemultiplywill replaceaddwithmutiply
Step 1-6 combined would take 7-8 seconds for me (let’s make it 8 seconds). There it is, I just saved 2-4 seconds of my life. I think it’s really worth it. The previous example is a simple one, consider these coding-related operations:
- Jump between lines
- Move code from line x-y to line z
- Change code inside curly braces (in vim you can use
ci{, yes that’s only 3 strokes) - Etc..
Note: You can cheat on step 5 and 6 if you use Vim Easymotion.
I don’t know how much time I’ve saved for myself, but indeed the investment pays really well. Some people will tell you that you should use a real IDE and I couldn’t agree more with them, I would tell you the same. With vim in your toolbox, you can install a vim keybindings plugin for your IDE, so you’ll get the power of IDE and vim keybindings.
Personally I use XVim for XCode, Ideavim for Jetbrains. Sometimes depending on my mood, I use Spacemacs (Pre-configured emacs with a lot of useful packages) with vim keybindings for other stuffs. Feel free to see/copy my vimrc.