Skip to content

Compiling vim with Ruby on Windows

My favorite text editor is Vim even on Microsoft Windows (which am I forced to use sometimes at work). I also like the Lusty plugin. This plugin is written in Ruby.

And that's the problem. Vim on Windows is compiled with dynamic Ruby support. Which means that Vim loads the Ruby library at runtime, if it's available. So Vim ships without Ruby and if you install it, it can use it. So the theory. In practice, that works well with other scripting languages like Python or Tcl. But Ruby seems to change its ABI very often. On Linux, everything is compiled by the distribution, so everything fits together.

At the result I was unable to find a suitable Ruby for the binary distribution of Vim. So I compiled my own Vim in MinGW. I tried Visual Studio, but that's much more complicated.

So here are the steps to compile Vim with proper Ruby support:

  1. Download and install MinGW with following packages:
    • mingw-base
    • developer-tools
    • msys-base
    • msys-gcc-c++
  2. Download and install Ruby. I'm using "2.0.0 p364 (x86)". The important thing is that it's the 32 bit version, not the 64 bit version.
  3. Download and install Mercurial.
  4. Add c:\mingw\bin to the %PATH%.
  5. Add c:\mingw\bin to the %PATH%.
  6. Now change into the vim directory you just cloned and execute in the src subdirectory
    the build commands
    c:\> make -f Make_ming.mak RUBY=c:\\ruby200 RUBY_VER=20 RUBY_VER_LONG=2.0.0 GUI=no
    c:\> make -f Make_ming.mak RUBY=c:\\ruby200 RUBY_VER=20 RUBY_VER_LONG=2.0.0
    This will produce a vim.exe and gvim.exe.
  7. Now just copy the executables in the already installed program files directory of vim and enjoy your vim with Ruby support!

Use an Apple keyboard on Linux

I have to admit that I use a Mac at home as my primary workstation. I also like the Apple keyboard (the one with a cable). That keyboard is hard-wired for Macs, which means that on a PC
  • one cannot use the function keys without pressing fn
  • the tilde (in the English/International layout) is not left of the 1 key but right of the left Shift key
  • Alt and Windows are swapped (if you type blindly and ignore the labels).
The good news is that Linux comes with a hid_apple kernel driver which can “fix” all that issues. By default, that driver doesn't change the behavior, you have to set some kernel parameters. On recent Linux distributions, all you have to do is to create a file /etc/modprobe.d/hid-apple.conf with following contents:
options hid_apple fnmode=2 iso_layout=0 swap_opt_cmd=1
I the driver is loaded in initramfs (e.g. you have an encrypted root partition, so you need to enter your password in the early boot phase), then you have to re-create the initramfs, e.g. by mkinitcpio -p linux on Arch Linux.

Mounting NFS shares on Mac OS

When trying to mount a NFS share that is exported by a Linux NFS server (the kernel implementation), I got a "Permission denied" error. There are lots of explanations around in the internet that recommend to use the resvport mount option like

$ sudo mount -t nfs -o resvport,rw kepler:/home/bwalle /Volumes/kepler

However, I didn't want to change the settings on the client but on the server. This has the advantage that I can still use Finder to mount NFS which isn't able to provide special mount options.

The solution was to use insecure in /etc/exports like

/home/bwalle *(rw,no_subtree_check,insecure)

What is insecure about that option? Well, the check comes from the early days of Unix where only the system administrator had the root password. So only applications running as root can open TCP connections with privileged source ports (below 1024). However, nowadays everybody knows that NFS in its versions 2 and 3 are insecure by design and removing the check for the source port doesn't make it more insecure.

Swap Alt and Windows key in Windows

I use VirtualBox on Mac OS. Windows guest, Mac OS host. On the Mac, the keyboard layout is a bit different: While on the PC the three first keys in the last row on the keyboard are Ctrl, Windows and Alt, the Mac has Ctrl, Alt and Command. From the key code perspective, Command and Windows are the same.

The problem is now that the Windows guest gets the key codes, i.e. Alt and Windows are swapped. Of course the label stays, the same, but if you type blind, this doesn't matter. So to use Alt+Tab (to switch between different windows) one needs to press the second key, not the third key. Maybe some people like that behavior, but I don't. There are feature requests, but VirtualBox developers don't want to implement it.

So I decided to look for a solution inside the VM. There are many tools in Windows to swap keys, but most of them are way too overloaded. Searching around in the web, I found a much simpler solution which consists only of adding a value in the registry.

There's a so-called Scan-code mapper for keyboards described in the MSDN documentation. All you need to do is to add a value called HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout\Scancode Map with following value:

00 00 00 00  00 00 00 00 
03 00 00 00  38 00 5b e0
5b e0 38 00  00 00 00 00

After that, just reboot. No need to install tools, no autostart. If you want to get rid of the behavior, just delete the registry key and you're done.

Using a dark background with CoIDE

At work I had to develop some firmware for two different ARM micro controllers (LPC and STM32). Although I don't like IDEs in general, after some search I've chosen CoIDE for that task.

It works well with Segger JLink, supports a broad list of micro controllers (including the ones our hardware had)  and it's free (in terms of beer, not speech). Well, it only works on Microsoft Windows, but as long as I only have to work under Windows and not for Windows, that's okay for a while. "Using a dark background with CoIDE" vollständig lesen