Andrew Fontaine

Mostly code

Development on Windows - Vim

14 Jul 2015

Look, I know you like to program. I also know you like to play video games. I know that gaming on Linux and Mac OS X isn’t too bad, but I know that the big ones are only on Windows.

Dual-booting is an okay solution. It’s okay, SSDs make rebooting pretty quick, but for less than the amount of work of getting a decent dual-boot set up, we can pretty much just do the development in Windows.

First step in Windows is a nice editor, and we’re going to talk about setting up VIM, because writing about setting up VIM is more interesting than writing about setting up Atom or Sublime. First, get the VIM installer from their downloads page and install it with all the bells and whistles enabled (especially the path and command prompt support).

There are three steps for the rest of this.

  1. Use Powershell
  2. Use ConEmu
  3. Get it set up properly.

Powershell

It’s just better than cmd. That’s all there is to it. It is nicer than cmd, the pipelines are fancier than cmd, and a lot of the commands are aliased to their Linux variants out of the box. All in all, it should probably be your go-to command tool. Then you won’t have to worry about maintaining a giant Cygwin or MinGW install.

To manage any environment variables, use the Get and SetEnvironmentVariable commands, detailed here. By default, your $HOME or %UserProfile% or whatever you would like to call it, lives at C:\Users\$USERNAME. It’s even aliased to ~ in Powershell!

ConEmu

ConEmu is a pretty decent terminal emulator. It can run a variety of different terminals, it has tabs and splits, and it supports 256 colours! I’ll leave looking through the various settings up to you, with the exception of a few colour-related ones here. To get 256 colours working, you must enable the following settings:

  • ‘TrueMod (26bit color) support’ on the Colours page
  • ‘ANSI x3.64 / xterm 256 colors’ on the Features page
  • ‘Inject ConEmuHk’ on the Features page

This will let you use 256 colour support across pretty much all terminal applications that support it cough VIM cough. Which brings us to the last part of this guide:

VIM

Now, I don’t love vim. I like it well enough to maintain a decent config, but it’s not the most perfect editor. It is, however, still super handy. To get all those pretty bells and whistles working on Windows can be a pain, but I’m going to tell you how to do it right now.

256 colours in vim.

First you need to follow the above and set up ConEmu, then add this very important snippet to your _vimrc:

set term=xterm
set t_Co=256

" Stupid Windows settings
if has('win32') && !has('gui_running') && !empty($CONEMUBUILD)
 let &t_AB="\e[48;5;%dm"
 let &t_AF="\e[38;5;%dm"
endif

NOTE: It is a _vimrc, not a .vimrc. It is also vimfiles/, not .vim/. Also, that whole snippet is important, not just the “Stupid Windows settings.”

You may then proceed to apply your favourite 256 colour scheme and use it in the terminal. I’ve noticed the base16 ones don’t like to play nice with Windows, as they seem to rely on some terminal colours being set. I recommend the good ol’ molokai.

Using Powerline/Airline/*line and the Unicode Symbols

First, you must either monkey-patch a font with the powerline symbols, or conveniently download already made ones. Your choice, really. I won’t tell you what to do.

Once you choose a font, set it as your font in ConEmu. Then, add these delicate lines to remind both VIM and Windows that it is the 21st century, and we can show cool symbols.

In your Powershell profile, $ vim $PROFILE:

chcp 65001

In your _vimrc:

" Stupid terminal settings
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8

" Airline stuff (figure out your own *line settings)
let g:airline_powerline_fonts=1

That should do the trick. You can also set guifont=... if you ever want to use gvim without your eyes bleeding. The rest is roughly the same. Use Pathogen or Vundle or whatever the kids are using these days.

There you go. YMMV. Next up: Ruby on Windows.

I ❤ feedback. Let me know what you think of this article on Twitter @afontaine_ca