Categories
geek opensource software tools vim

setting up vim on windows

So you want to make the plunge and check out what that awesome Vim editor is all about on a Windows machine? I did about a year ago, and this time I actually stuck with it. I tried it 2 times before already, but I gave up every time after a few hours or days because of the steep learning curve and the fact that nothing seemed to work the way I’m used to.

The goal here is to get Vim set up on a Windows box, make it work like a Windows app and make it look like something you aren’t afraid of being seen with (that default layout, euhm, seriously…).

installing Vim on Windows

The easiest way to install gVim (the non-console version) on Windows is by using the Vim Chocolatey package. It installs the Cream Windows flavored Vim for you from Sourceforge and sets up your system path so you can run “vim” and “gvim” to start the editor from the command line if you want to.

Chocolatey itself is like apt-get for Windows. It’s a NuGet based software package manager and if you’re a software developer or have to install systems a lot, I’m sure you’ll love it.

To install using Chocolatey, type this from a command shell (run in administrator mode):

    choco install vim

Easy isn’t it?
If you really don’t want to setup Chocolatey (but you should really) you can also get the Windows binaries from vim.org, or the Cream ones. You’ll get the Cream editor with that based on Vim, but I didn’t want that cause it’s not quite pure Vim anymore (not modal for example).

first steps

Before you start configuring Vim you should start with getting to know it. Whatever comes next will be a lot easier once you know how to move around, save files etc. You know, those typical things you do in a text editor anyway.
So basically you have to RTFM. Or at least, the short version of it.

Find the Vim tutor in your start menu and run it. Once you’ve completed that, you know enough to get around in Vim and find out how to get help for other stuff. Also, don’t bother with doing it the hardcore way. Just learn Vim at your own pace, use the cursor keys and the mouse if you want. You’ll pick up more advanced stuff as you go along.
Just like this guy said.

configuring Vim

Vim uses vimrc configuration files to store settings. There is a default vimrc file in your Vim installation folder, but you shouldn’t touch that one because it can be overwritten when you install a Vim update. Your own settings go into a new _vimrc file containing only the things you want. You can “source” or include other vimrc files, to avoid duplication or organize your configuration.

On a Windows machine this goes into your user folder (c:\users\username\_vimrc).

To see and edit your current vimrc (the one use by vim when it starts) type:

    :edit $MYVIMRC

Once you’ve created your own config file, the above command will automatically open it. So let’s do just that, like this. “e” is short for “edit” btw:

    :e ~\_vimrc

That tilde character (~) stands for the path to you home folder, which on Windows is normally set to c:\users\<username>.

On Windows the folderĀ  ~\vimfiles is used to store custom plugins. I put my vimrc in ~\vimfiles and source it from the ~\_vimrc file. That way I easily sync my whole setup to another machine by simply copying the whole vimfiles folder. So my ~\vimrc file contains only this line.

source ~\vimfiles\nj-vimrc.vim

You can keep everything in _vimrc of course if you want.

You can test Vim statements from the command bar before you put them in your vimrc file. A handy way to test and see if it really does what you want it to without having to restart Vim and reload your configuration.

making Vim behave like a Windows editor

If you install the Windows gVim version this will normally be setup in your vimrc configuration file automatically, but it’s always handy to know what settings are making the magic happen.
Vim doesn’t use the typical Windows key binding like CTRL-S to save, CTRL-C,V,X to copy, paste and cut. As a hardcore Windows user you expect these to work for all applications, no matter how geeky they are. If you check out the original vimrc in the Vim installation folder you’ll see the same statements as below.
You can copy these into your own vimrc file.

" Activate all the handy Windows key-bindings we're used to.
source $VIMRUNTIME/mswin.vim

behave mswin

Or you can source the original config in yours:

source $VIM/_vimrc

Now your Vim should (still) behave pretty much like a regular Windows editor, making things a lot easier to use it for all your basic editing.

making it look good

gvim_fugly

Man, it does look ugly doesn’t it? All white and with that terrible font? Now let’s make it look pretty so you don’t have to be ashamed of all those hipsters sporting their fancy Sublime.

This depends on your personal preference of course, but I like it when my editor doesn’t look like it’s from the 80’s. I pasted some of my esthetic config changes below. Each has some comments on it explaining what they do. Use the help feature (:h ) if you want to find out more, and remember to only put things in your vimrc that you understand.

" Display line and column number in bottom ruler.
set ruler

" Display the line numbers.
set number

" Activate syntax highlighting.
syntax enable

" Set a nice theme.
color slate

Check out all the themes you have installed by using CTRL-D (auto-complete) after you typed in :color on the command bar.

if has("gui_running")
  " Set a nicer font.
  set guifont=Consolas:h11:cDEFAULT
  " Hide the toolbar.
  set guioptions-=T
endif

gvim looking pretty

You can exclude hiding the toolbar, but I just find it ugly and never use those buttons anyway. This is very minimal, and there are plenty of other themes and plugins available to change Vim’s appearance, but that’ll be for another post. For more vim customization tips, check out what I have in my _vimrc file.

Hopefully this gets you going in the wonderful world of the Vim editor on Windows. Just keep at it I’d say and feel free to drop any questions or remarks in the comments.

2 replies on “setting up vim on windows”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.