Navigation and multiple files with vim

I love vim, and I use it for programming whenever I can, however I have never used it in a professional environment since I have been programming at work with other editors like Sublime Text or Visual Studio (uggh).

Once you get used to a bunch of vim shortcuts your coding speed increases and you can't get back to other editor.
However, for me working with vim only at home on my personal projects made me stay in a zone of comfort where I knew there was some really innefficient ways for doing some tasks but I didn't had the pressure that a real job gives you in order to review and improve every single of those points.

This changes a few days ago when I had to do a working day test at a company and I chose vim for it.
The problem came specially to file navigation, as I was feeling nervous and I had to navigate throgh a lot of files and directories I started opening tabs, then I opened new terminals and after a couple of hours I had a terminals + tabs chaos where I didn't know where I was and what files I had already opened.

My brain is full of fuck

Yeah, I new I had a problem with file navigation but I didn't know this could come to that mess in a real working environment. Time to optimize this once for all.

The first rule I'm now apply when working with vim:

Never ever have various terminals with multiple vim instances opened.

Vim has its own system for managing multiple files, like tabs and splits. Having various terminals opened for multiple files at the same time could be nosense for a vim expert but I used to do it from time to time with two or three terminals.
In the test I did the other day I ended up having like 9 or 10.

Become a tab + split master.

I was used to tabs but I didn't liked splits and found easiest opening multiple terminals, mistake. Plus, I used commands like :tabn, :tabp or :tabfind for working with tabs. This is extremely slow and I have stopped using them, now I am getting used and practicing these other shortcuts:

  • gt goes to next tab.
  • gT goes to previous tab.
  • {i}gt goes to tab in position i.

Still I needed a replacement for :tabfind, for me one of the nicest thing when working with sublime was the Command+P functionality, that looks for a file under the project's directory and makes opening files fast as lightning. This should be the perfect replacement for vim's :tabfind and fortunatelly there is a plugin that is doing exactly the same thing (yay!).
https://github.com/kien/ctrlp.vim

Now my productivity has increased a lot, but there is something else left.
As I said before, opening more than a terminal should be avoided and when you need to execute some shell command it seems the only way to do it. Well, as it is explained in this article it is not.

  • :! Executes a shell command.

Is a superfast way of executing a shell command like rspec without leaving vim.
Also I am checking tmux for having things like a bash terminal opened the whole time since is also possible to seamlessly navigate vim and tmux splits.

tmux

And talking about splits is also mandatory practicing this splitting shortcuts:

  • :sp will split the Vim window horizontally. Can be written out entirely as :split.
  • :vsp will split the Vim window vertically. Can be written out as :vsplit .
  • Ctrl-w Ctrl-w moves between Vim viewports.
  • Ctrl-w j moves one viewport down.
  • Ctrl-w k moves one viewport up.
  • Ctrl-w h moves one viewport to the left.
  • Ctrl-w l moves one viewport to the right.
  • Ctrl-w = tells Vim to resize viewports to be of equal size.
  • Ctrl-w - reduce active viewport by one line.
  • Ctrl-w + increase active viewport by one line.
  • Ctrl-w q will close the active window.
  • Ctrl-w r will rotate windows to the right.
  • Ctrl-w R will rotate windows to the left.

Wich are more natural if you are used to the vim's directional moving shortcuts.

With these set of tools I'm increasing my speed a lot in the points I knew it was very poor.

And as general lessons learned from these days I get those:

Always always look for working smarter, not harder.

Always push yourself out of your comfort zone in order to review and improve your skills. Even if you are good enough for your daily work, don't stop there.

Work smarter, not harder

Finally, as a general vim advice, don't read the command list like a book and instead practice a lot, force yourself to use those commands one by one and you will remember them perfectly, when dealing with vim practising and not studying is the only way of learing.

Don't get stressed or overwhelmed and you wil see good results.