Recently I took some time off to improve my Vim skills. My rule of thumb is whenever you find yourself doing a repetitive task that’s a hint there might be a better way of doing it. I’ve learned some tricks and about a few extensions.
First, I rediscovered exuberant ctags. Exuberant ctags is an external tool that creates a dictionary of data from source code. Then you can navigate through code more comfortably. First run ctags from the project home folder:
$ ctags -R -f.tags
Then open a source code file. Position the cursor over a function call, and press Ctrl + ] to jump to the declaration of that function. Press Ctrl + T to come back.
By default, Vim search for a file named tags. I like to name it .tags, so I adjusted my .vimrc file like this:
set tags=./tags,./.tags,tags,.tags;
As a side note, another great discovery was using Ubuntu One for synchronizing my .vimrc file and .vim folder on my desktop and laptop.
With regard to Vim new commands I discovered ci{. Amazing, I think I won’t be able to live without it now. It removes all the code within an inner block code. A similar trick can be applied to a conditional on an if by typing ci(.
With regard to plugins I installed a few and I still trying most of them, but there are some that I consider now a must on any Vim setting.
- Pathogen. To handle vim plugins.
- NERDTree. To navigate through the filesystem. Ctrl + N to open the navigation window makes it very convenient. Before NERDTree what I used to do was open a shell with !sh, located the file, back to Vim and open.
- NERDCommenter. This is so good! A syntax that understands how to proper comment something in a myriad of programming languages. Just simply visual select a block and type “\c
” to comment, do the same to uncomment. Very convenient for programming languages that allow only per-line comments, such as Perl. - Fugitive. A nice git plugin. At first I thought I won’t use it as I like Disintegrated Development Environments, but the :GBlame command is so good, it already makes it worth. I’m eager to learn more features about this plugin.
- Supertab. Text completion by typing tab. Before I used a function I had copied somewhere on my .vimrc.
- SnipMate. A snippet manager. I think it’s an implementation of the same feature from TextMate. I got to learn how to use it more, but it’s already saving me some typing, specially for loops.
- ZenCoding. I knew about it a long time ago, although I never used it much. Zen Coding is a special syntax for writing CSS and HTML. The result is that you can write more with less typing and the syntax follows very much the same principles as CSS selectors. So, if you know jQuery or CSS you’ll get it very fast. The syntax was created by and there’s support for various editors.
And this is what I’m using now. Now that I know about these things, I ask myself why I’ve waited so long to pause and learn about these topics. However, I think I know the answer.
Once we learn how to do something, although it’s not the most efficient way of doing it, we stuck to it as it allow us to get our way through. It does the job and at the end of the day that’s what really matters. The point is that we never think about how much time we waste daily when we are not doing things in the best way possible. And that’s particularly true when doing things better doesn’t cost a big effort.
Summarizing, next time you get absorbed by a software project, don’t fool yourself and think that only doing project’s code is work. Work is also everything that allow us to work better and that includes learning a new tool, learning more about your favourite editor or reading a book or an article.