Getting Vim, Git, and Ctags Working in Harmony

by Daniel Convissor at 2015-09-22 09:30:00

A few years ago, I bit the bullet and started using Vim, cold turkey. It's been rewarding. My first step was forking Andrei Zmievski's vim-settings repository.

One very handy thing in Andrei's setup is Yegappan Lakshmanan's Tag List plugin. To that I added Tim Pope's Fugitive plugin. Combining those together with installing Darren Hiebert's Exuberant Ctags and the Git hook concepts in SeƱor Pope's "Effortless Ctags with Git" moves Vim from a good source code editor to an excellent one.

You can jump from where a function is used to where it is declared by hitting CTRL-]. Hitting F5 produces a pane on the left listing functions in the current file. Tab completion is available. Tag lists are automatically updated when git checkouts, pulls or commits are done.

But, there were a handful of annoying shortcomings. I'll address the bigger issues in separate blog posts. Below are resolutions for the small stuff...

Opening Tags Use Buffers

The default process of jumping to a tag opens the file in a new buffer in the current window. I have yet to learn to use The Force, so find tabs easier to use. Therefore, I adjust the tag jump to open a new tab:

nnoremap <C-]> :tab tjump <C-r><C-w><CR>

Syntax Highlighting Chokes on Large Files

It seems the syntax highlighter is inefficient or buggy. Large PHP files make vim very slow to respond. An easy fix is to disable syntax highlighting in big files:

au BufReadPost * if getfsize(bufname("%")) > 102400 | set syntax= | endif

MatchParen Color Confusion

Maybe it's just me, but the default colors of MatchParen are very simliar to some colors used by syntax highlighting. This made it difficult to figure out what's what. Tweaking the colors is pretty simple:

highlight MatchParen ctermbg=Blue ctermfg=White

Matchpairs Made Me Less Than Happy

I tend to write more PHP and text than HTML. So having matchpairs add a > everytime I type a < got annoying pretty fast. Placing the following to .vimrc increased my glee:

autocmd BufRead * set matchpairs=(:),{:},[:]

Putting it All Together

Part of what my Ubuntu Laptop Installation script does is put all of these components in place.

Tags: ctags, vim, git, php

View all posts

Email me a comment:

(I'll append it here when I get a chance.)

Your Name:
Your Email Address:
Subject:
Message:
(1000 chars. max.)