Last week I mentioned that the only thing I was struggling with in my transition to Vim for editing code was juggling multiple open files at once. Switching from one file to another is really easy, especially if you’re working on a Rails app and using rails.vim. There are a number of really nice navigation features built in that make it easy to open any file from your project and to switch among related files.
This morning I noticed that these navigation commands all have “open in new tab,” “open in new split window,” and “open in new window” variations. So to open a model called “store.rb”, in command mode you just type:
To open that model in a new tab, you type:
Navigating among tabs using the keyboard is easy as well:
So, to switch to the third tab, you just type “3gt”. In command mode you can also just type “gt” to move to the next tab.
Suddenly, my problems are solved.
I’m also getting the hang of split windows, which I should have mastered years ago. They have two advantages over tabs, the first being that they make it easy to look at multiple files at once. The second is that you can use them in terminal sessions as well. Another nice thing about split windows is that you can split your view of one file so that you can look at one section of the file while you work on another.
I think the real lesson here is that not taking the time to master your tools is false economy.