Setting some options for gvim

Around 4 years ago I wrote a post that gave my .vimrc settings. This new post is a bit of an addendum for those who use gvim, the graphical mode of our favorite text editor.

Although I don’t get to use graphical editors in my sysadmin work, I’ve found them a great help when I switch into developer mode.

Right now Gnome’s gedit and gvim are the gui editors I use most frequently on Linux, Notepad++ and gvim on Windows. I’d really like to standardize on gvim across the board and probably will in the not too distant future.

Most graphical editors make it easy to change various preferences like font size and type, backgrounds, etc. The gui version of vim is no different.

Although you could put gui-centric settings in .vimrc, most recommend that you use its companion, .gvimrc, instead. This allows you to use .vimrc for your cross-platform settings while leaving you with .gvimrc for things that are more likely to differ between systems like Linux and Windows.

This is what my current .gvimrc on Linux looks like:

"My .gvimrc
set guifont=DejaVu\ Sans\ Mono\ Bold\ 11
colorscheme default

The guifont directive allows you to set something other than the system default as the display font. In my case I chose DejaVu Sans Mono Bold at 11 points. The escapes (“\”) are intentional, being required for gvim to properly handle whitespace in the value set.

The colorscheme directive tells gvim to use the scheme specified in displaying background and foreground colors. The correct syntax is not to use an equals sign between the command and the value (there are many other vim commands like that). When in gvim you can change the color scheme from the drop-down menu (“Edit… Color Scheme”) or by hitting the ESC key and typing “:colorscheme darkblue” (without the quotes). The terms “colo” or “color” are synonomous for “colorscheme” in vim’s world.

A variation on this would be controlling the colors directly. For example:

"My .gvimrc
set guifont=DejaVu\ Sans\ Mono\ Bold\ 11
highlight Normal guifg=LightGray guibg=Black

This would result in unhighlighted text in light gray on a black background (this particular combination will cause syntax highlighting to use the koehler color scheme). For whatever reason I’m not happy with any of the shipping color schemes and so have stuck with the default black text on a white background.


A few differences arise when you’re doing this for the Windows version of vim.

Most importantly you need to make sure that the %HOME% environment variable (the Windows shell uses percent symbols to denote variables) is defined in Advanced System Settings and points to your real local home directory, usually C:\Users\[username] (for example, C:\Users\plembo). This is a good practice when running any software ported from Unix/Linux.

Next, the “dotfile” names will have underscores in place of the dots. So .vimrc will be named _vimrc, and .gvimrc will be _gvimrc. Your custom versions of these files will go in your HOME directory just like on Unix/Linux. In most cases that will be C:\Users\[username] as explained above.

It’s important to check the gvim for Windows settings window for differences in how some values are rendered. On Windows I recommend using the gui to debug problems in your configuration. One value I can guarantee will be different is that of any gui font you want to set. For example, on Linux you’ll use the following to specify DejaVu Sans Mono Bold 12:

set guifont=DejaVu\ Sans\ Mono\ Bold\ 12

On Windows this would be the corresponding directive:

set guifont=DejaVu_Sans_Mono:h12:b:cANSI

Also, don’t expect Windows to handle utf-8… at all.

This entry was posted in Development, System Administration on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).