rc3.org

Strong opinions, weakly held

Navigating among tabs in Vim

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:

:Rmodel store

To open that model in a new tab, you type:

:RTmodel store

Navigating among tabs using the keyboard is easy as well:

<tab number>gt

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.

4 Comments

  1. In Soviet Russia, tools master you!

  2. Are you using a GUI version of vim or using it in a terminal window?

    I’m looking forward to going back to Eclipse real soon now after a sojourn in the lands of IDEA and Visual Studio. IDEA is good but too quirky for me and Visual Studio is too underpowered and ugly, relying on third-party plugins of dubious quality and high price for things like decent refactoring and code-formatting support.

    (Eclipse’s code formatter is a thousand times better than VS’s built-in formatter, which cannot be trusted to fix even basic line-breaking.)

    Can’t see taking up vim again. Obviously I still use it on remote systems but that’s about it.

  3. I’m using MacVim (the GUI for OS X). For Java development, I absolutely would not give up Eclipse for Vim (or MacVim). Once you have a strong working knowledge of Eclipse, it is an incredibly powerful tool. But for editing simpler stuff, I’m finding Vim to be preferable to other text editors like TextMate.

  4. I would suggest you ignore tabs in Vim and just focus on buffers. It is a lot simpler, and there are a lot more plugins to help you 🙂

    At the moment I am using Lusty Juggler (https://github.com/sjbach/lusty). Pressing the key combo to bring it up (I have it mapped to ,b) replaces the status bar with a list of open buffers, which you can then jump to by double pressing a number key. The results are even ordered by which buffer you opened last, so switching between two buffers is as simple as pressing ,b22. Thinking about it now, maybe I should remap that….

Leave a Reply

Your email address will not be published.

*

© 2024 rc3.org

Theme by Anders NorenUp ↑