Vim stuff
Posted on 28th of August 2009Vim is a nice editor, but I never liked the way it handles files. Thankfully I recently found a great script, which adds great quick browsing capabilities to Vim, called lusty-explorer.vim. Since 7, Vim has supported not just it’s own homegrown (and honestly fairly bastardized language) called VimScript, but also it has included bindindgs for popoular scripting languages such as Ruby and Python, so extending this script with some extra functionality was a great way to see how Vims extensibility works. And with lusty-explorer written in Ruby, this was a nice chance to learn these new aspects of Vim.
Anyway, lusty-explorer adds quick ways to browse either the loaded buffers, or browse the filesystem, but doing both in a way which blows away the built-in directory browser in Vim. But the way I like to browse files is basicly with a “recently used” file list, which should include currently open files. So with some changes to the lusty-explorer script, it now has a great “recently used” explorer, which I find totally eliminates any need to check currently loaded buffers. Want to open a file you know you’ve opened recently? Just hit <leader>lu, and the last many files you opened are there, easy to get to. If the file is alredy open, Vim just switches to that buffer, just like if you had entered :e file.
Remote Desktop, Consolas and ClearType, oh my
Something else which I’ve found a need for, is a capability to detect when Vim is used in a remote desktop session. Since I spend maybe half of all my time working in a RD, where ClearType is usually disabled, that means that my preferred font, Consolas looks like shit. While not the same as having ClearType disabled, I found that the easiest way out was to check if the current session was via Remote Desktop (look for the SM_REMOTESESSION.) Thankfully that’s pretty easy to check. Here’s a minuscule C program which does this.
#include <windows.h>
#pragma comment(lib, "user32.lib")
int main(void) {
if (GetSystemMetrics(SM_REMOTESESSION)) {
printf("1");
} else {
printf("0");
}
return 0;
}
The precompiled file here is compiled for 32bit, on WinXP, but tested on 64bit 2008 Server as well, where it should work just fine, through the miracle of WOW. You can use this small executable, by dropping it in the path of computers where you use Vim, and where you might also log in via Remote Desktop, and then you can tweak your _vimrc like this:
if has("gui_running") " gvim is running
if has('win32')
set guifont=Consolas:h11:cANSI
if system("remotesession") == "1"
set guifont=Lucida_Console:h10:cANSI
endif
endif
endif
Lets you get the best of both worlds, Consolas, when ClearType is (probably) present, and Lucida when not (Lucida Console is still fairly decent.)
Tags: editor, remotedesktop, vim

March 1st, 2010 at 12:50 am
Rescue party for Teenee, rescue party for Teenee. Gief cool new programming posts!!!