Using a text editor inside a terminal really sucks. It’s really lame that it’s 2012, and we’re still doing it this way.

So I resolved to try to run MacVim locally to do my work. It has a netrw module that lets you do certain things like open a sftp:// url directly, and browse remote trees. Great. But what about ctags?

Turns out ctags file format is pretty simple.

tag<tab>filename<tab>bunch of other stuff...

It also turns out that if in the filename field, you have a “sftp://…” style string, vim doesn’t freak out! Sweet!

So my hack for the night was to write a script that:

  1. logs in remotely and kicks of a ctags run
  2. copies that tags file locally
  3. munges that file to replace relative paths in the remote fs with sftp://… prefixed paths that a local vim could use to access remote files
  4. write some .vimrc to load that tags file

And it works! I can use :tj to search for tags, and vim will automatically open up the right file over sftp and show me the tag. 

The only thing I can’t seem to work out is how to disable the extra “press Enter to continue” prompt that happens every time vim needs to open a new remote file. If I can get rid of that, this is almost a perfect solution.

Actually, one other problem is that vim doesn’t seem to be able to tab-complete sftp://… urls, which seems a little silly, since it has a pretty sophisticated directory browser built in.

For those who are curious, here’s my lame script to munge the tags file:

sftp_prefix = 'sftp://dev/www/'
infile = file('/Users/kdeeter/workstate/tags.raw', 'r')
outfile = file('/Users/kdeeter/workstate/tags', 'w')
lines = infile.readlines()
cnt = 0
for line in lines:
   tag, fname, rest = line.split('t', 2)
   if not tag[0:5] == '!_TAG':
     outfile.write(tag + 't' + sftp_prefix + fname + 't' + rest)
   else:
     outfile.write(line)
   cnt += 1
   if cnt % 1000 == 0:
      print '%s tags mungedr' % (cnt * 1000),
outfile.close()
infile.close()

Leave a comment

Your email address will not be published. Required fields are marked *