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!!!
April 27th, 2010 at 2:32 pm
Great stuff! I am looking forward to using this plugin!
May 24th, 2010 at 7:57 pm
Indeed, good stuff. Vim is a great tool, it’s actually my preference when it comes to editors.
September 9th, 2010 at 8:21 pm
excellent tip. even without the RDP session check, just has(‘gui_running’) and set guifont= is worth it.
January 30th, 2011 at 8:34 pm
A bit of a late reply to this post, but it’s worth noting that using a .gvimrc is preferable to using has(“gui_running”).
January 31st, 2011 at 1:50 am
Maybe so, I just prefer having it all in .vimrc, for both console and GUI use, instead of using two files.
April 12th, 2011 at 10:39 pm
If you’re scripting with Python and have the win32 package installed you can just do remote session check in the Python code:
import win32api
win32api.GetSystemMetrics(4096)
April 26th, 2012 at 3:36 am
offers…
[...]Everything old is new again » Blog Archive » Vim stuff[...]…