Display Relative Paths in taglist.vim

While the “Tag List” plug-in for Vim is really great, there is one peculiarity that I wasn’t so happy about. By default the displayed directory names are absolute paths. Hence, working in a little bit (depending on the displayed width of your tag window) deeper subdirectory already yields the issue that the displayed directory information is not particularly helpful; personally, I don’t care about knowing that I am working somewhere beneath “/home/foo/bar/my-sources…” while the actual interesting information would be to know that I work on “./project-a”, “./a-different-project”, etc. Admittedly, this may also be caused by my personal workflow, but well, at least for me this was a little bit inconvenient.
To fix this issue I had a look at the taglist.vim source code and came up with a small patch that changes the displayed path from an absolute to a relative one. Note that I just commented the original line of code.

--- Downloads/taglist/plugin/taglist.vim  2007-09-21 18:11:20.000000000 +0200
+++ .vim/plugin/taglist.vim 2012-03-12 13:34:10.907582194 +0100
@@ -1917,7 +1917,8 @@ function! s:Tlist_Window_Refresh_File(fi
endif

let txt = fnamemodify(s:tlist_{fidx}_filename, ':t') . ' (' .
-                \ fnamemodify(s:tlist_{fidx}_filename, ':p:h') . ')'
+                \ fnamemodify(s:tlist_{fidx}_filename, ':.:h') . ')'
+"                \ fnamemodify(s:tlist_{fidx}_filename, ':p:h') . ')'
if g:Tlist_Compact_Format == 0
silent! put =txt
else

For more details about what’s going on there and what other options you have see “:help fnamemodify” and “:help filename-modifiers”.

Advertisement
This entry was posted in Snippets and tagged , , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.