Visual Studio ViEmu and “the Dark Side” all happy together
So, if you like vi as an editor and you use Visual Studio, pony up the money and get ViEmu. Best money invested in my productivity and ergonomic efforts of this past year, hands down. If you love to hate your mouse you owe it to yourself to investigate ViEmu. There is also another free emulator that is available as an extension from the extensions online gallery called VsVim. However the rest of this blog has to do with configuring ViEmu to work with your particular choice of Visual Studio color scheme.
First choose a color scheme. I recently moved back to a dark theme son-of-obsidian. I usually feel the need to change up the scheme once or twice a year to give my eyes something different to look at. Extra motivation was added in dealing with OpenXml a lot lately and, as a result,parsing and comparing tons of xml files. I found a dark theme in gVim made the xml a bit easier to digest and I wanted to same experience in Visual Studio.
Here is a screen shot of Visual Studio with both an xaml and a vb file open.
I like the overall theme, but right away I see some issues with usability as highlighted by the numbered arrows.
- The line numbers are too dark. Whoever created this theme probably doesn’t have line numbers turned on so it would be easy to miss.
- The flashing, black on black, cursor is almost invisible.
- The default ViEmu search highlight color, yellow, stands out nicely but depending on what content is highlighted, the foreground color may not have enough contrast to be readable. The highlights in the right file fall in string literals and the Orange font comes thru well enough, but in the left file, the White foreground Method name combines with the Yellow to create a retina-searing glare.
Good news is that fixing all of these issues is fairly straightforward and also is a good exercise in learning how to configure the hybrid vim/Visual Studio environment.
Fixing the line number foreground color turns out to be the easiest of the bunch, as it is just a setting in the Visual Studio Options. Go to Tools >> Options >> Fonts and Colors and look for the Line Numbers item under the Text Editor settings. Pick a custom color that makes you feel better about your line numbers.
Setting the cursor color.
This one is a bit more work. Visual Studio does not expose a setting to change this color. However, vim has options that can be set to change these colors. Vim is configured, in the real vim, using the .vimrc (or _vimrc) file in the program path. ViEmu has its own version of the file called viemurc. The biggest challenge you will face is figuring out just where this file should be created in order for ViEmu to find it when it loads up.
The ViEmu support says to simply save the file to the folder indicated by your HOMEDRIVE Or HOMEPATH environment variables. So, just where, exactly, are they? Well on my Windows 7 machine that equates to “C:\” and “Users\Andreas” respectively. However in my work environment one, or both, of these variables are set to network share paths. To find out for sure what folders are HOME for you, open up a CMD prompt and run the “set” command. This will list the current state of all environment variables.
Now that you know where, create the what. Create a file called viemurc, no extension. Once it is created you can add the following lines that will configure the cursor colors.
1: highlight Cursor guifg=white guibg=black
2: highlight iCursor guifg=white guibg=steelblue
3: set guicursor=n-v-c:block-Cursor
4: set guicursor+=i:ver100-iCursor
5: set guicursor+=n-v-c:blinkon0
6: set guicursor+=i:blinkwait10
Ok, so that takes care of line numbers and cursors, now for the last item:
Vim search highlights:
The interesting thing about this one is that it looks easy at first but doesn’t seem to work. The same options screen we used for the line numbers above also has some ViEmu specific options, all prefixed with ViEmu (go figure). The HL Search Adornment and HL Search Font are what we are looking for.
However, when you update these you will see the background change, but not the foreground. What gives? Seems that ViEmu respectfully defaults to not altering the Visual Studio configured foreground for search highlights and instead just paints an adorner behind the pattern text with the selected background color. That may work for you. If not, you need to turn this “polite” feature off in the ViEmu settings. Under the ViEmu menu in Studio, make sure the “use adornments” checkbox is unchecked and click Ok.
That’s it, now the background and foreground you set for vim searches will be honored.
So, just a few minutes to make peace between ViEmu and a dark Visual Studio Theme.
ViEmu documentation that includes how to set up viemurc file options
Stack Overflow question that shows how to change cursor colors
Posted on ASP.NET Weblogs © Copyright 2011 - Andreas Zenker