In my previous post I told that I successfully switched to VIM and why I did it. In this post I want to explain how to do it in the easiest way, since my way wasn’t that easy when I was learning VIM 🙂
The problem with switching to VIM is the same as you switch to 10 fingers typing ( I hope you did it already ). You want to start with it and keep beeing productive with your normal work procedures all your work with it. But this is very hard to achieve. My first advice is to plan and prepare the VIM migration and not to just try it randomly in an unorganized way. A huge amount of necessary VIM knowledge will fall down on you.
So how do you prepare it?
I figured out that there are the major steps you should think about and process them separatelly, only then is the migration to VIM easier.
Before I start describing them. My assumption is that you run on Mac and use MacVim. I advice to install it using HomeBrew with:
brew install macvim
1. Use a prepared VIM installation
Use a prepared plugins setup as well as the vim configuration, dont do it yourself.
I learned it the hard way buy searching the VIM plugins and installing them, as well as the doing the VIM configuration. To avoid this I can recommend you to use the awesome installation package called JANUS.
2. Clearly understand the vim basics
It is important to diffirentiate between the bare minimum features you need to know, nice to haves and advanced stuff. In my opinion this is what you should do:
- understand the modes concept of VIM (Navigation, Insert and Visual modes)
- take the VIM Cheat Sheet or this sheet as the minimal information amount that you would need
- dig deeper into basics in an agile loop using this AWESOME blogpost
Try to don’t bother with other advanced topics for now, proceed to the next step, otherwise you will be overwhelmed by the information about VIM.
3. Know the editor features you cant live without upfront
a) Files lookup
Looking up files in a project folder tree in the fastest way, use the CommandT plugin that is bundled with Janus and press “Command + T”. The amazing advantag about it that it finds files even with a given folder structure. So if I have a file that is in my_rails_project/app/controller/users_controller.rb it is enough to write something like apcousconrb 🙂 thats it! I cant get enought of this feature. Yes it is kind of taken from Textmate but…. textmate doesnt do the search on the folder tree.
b) Global search for a String in the Project
This is the feature I missed the most in textmate because you cant restrict the types of files you want to look in for the string. The bundled Janus Plugin for it is called “Ack”. Just press “Schift + Command + F” and give the string you want to search for. Say I want to search all occurences of “my_function” in all ruby files, so I just have to type “my_function –ruby” after you triggered the search with Ack.
c) String find/replace
Find and replace string in a file or in the complete project. This one is needed very often but at the beginning while you are overwhelmed with all the VIM knowledge you have a trouble to have it handy, so here it the command pattern how to do it in the whole file:
I am still thinking that this is too complicated and will come up with a plugin solution for that.
d) Autocomplete function
All java developers usually love it and are proud of it and I think that if you wrote something once you should not type it again so here it is:
Press “Control + n” to see your options to autocomplete in your code. Of course you should be in the Inser mode before.
e) Formating the file
Which means go to the top of the file (gg) intend (=) to the end (G).
So thats basically it. I am sure if you adress this topics in the mentioned way you will have a much easier way to adapt VIM. I promise you once you used the VIM functions described in step 3 you will never want to use something else again 😉 .