Using Vim in Windows

I have a love affair with Vim. It’s the programmers text editor: with just a few key-strokes you can do just about anything. This is what programmers live for! We share a collective belief that the answer to all of the world’s problems, lay just a few key-strokes away. Vim–ever so slightly–confirms our mutual delusion. Without moving your hands away from the keyboard, you can edit, paste, search, replace, undo, redo, automate, and this and more, and so much more.

Vim is especially popular among the Unix\Linux crowd where Vi(m) originated. However, there’s no need for windows power-users to lag behind. gVim (graphical vim) is a great port of Vim for windows. In this article I will go over my _vimrc (windows version of .vimrc) and my basic setup.

I based my vimrc file on Yan Pritzker’s, and I recommend you check his setup up (especially if you’re running on a mac).

  • The first thing you want to check is to ensure that your $HOME directory is set to C:/Users/[username]. If it’s not, then some of the features in this setup may not work properly.
  • Next you’ll want to create the folder $HOME/vimfiles/, $HOME/vimfiles/backups, $HOME/vimfiles/ftplugin, $HOME/vimfiles/views
  • Finally, you’ll want to create a “_vimrc” in the $HOME directory


_vimrc Contents with Detailed Comments

” Begin with ensuring that we are running in vim mode not vi
set nocompatible” Set the color scheme of choice.
” In vim ‘:colorscheme
‘ to see more options
colorscheme pablo

” Start in documents folder [WINDOWS specific] ” (this is not as useful if you start vim from cmd line since
” in that case you may want the pwd to be the dir where you
” loaded vim from; however, since most of us start gVim from
” the start menu then starting off in yoru documents folder
” is a good choice)
cd ~\Documents

” The following two lines turn on highlight for search (1st
” line) and allow you to use to turn off highlight
” for that search. The highlight will return on your next
” search.
set hlsearch
nnoremap :nohlsearch:echo

“Line numbers are good–turn them on
set number

“Allow backspace in insert mode
set backspace=indent,eol,start

“Store lots of :cmdline history
set history=1000

“Show incomplete cmds down the bottom
set showcmd

“Show current mode down the bottom
set showmode

“No sounds
set visualbell

“Reload files changed outside vim
set autoread

“Modeline option enabled for custom vim settings per file
set modeline

” This makes vim act like all other editors, buffers can
” exist in the background without being in a window.
set hidden

“turn on syntax highlighting
syntax on

” ================ Turn Off Swap Files ==============
set noswapfile
set nobackup
set nowb

” ================ Persistent Undo ==================
” Keep undo history across sessions, by storing in file.

set undodir=~/vimfiles/backups
set undofile

” ================ Indentation ======================

set autoindent
set smartindent
set smarttab
set shiftwidth=2
set softtabstop=2
set tabstop=2
set expandtab

filetype on
filetype plugin on
filetype indent on

set list listchars=tab:\ \ ,trail:·

set nolist

“Don’t wrap lines
set wrap

“Wrap lines at convenient points
set linebreak

” ================ Folds ============================

set foldmethod=indent “fold based on indent
set foldnestmax=3 “deepest fold is 3 levels
set nofoldenable “dont fold by default

” The following lines save the view of the file including
” the folds and automatically saves and opens them. The
” next time that you open up the same file it will
” remember where you closed and open all the folds!
set viewdir=~/vimfiles/views
autocmd BufWinLeave *.* mkview!
autocmd BufWinEnter *.* silent loadview

” ================ Completion =======================

set wildmode=list:longest
set wildmenu “enable ctrl-n and ctrl-p to scroll thru matches
set wildignore=*.o,*.obj,*~ “stuff to ignore when tab completing
set wildignore+=*vim/backups*
set wildignore+=*sass-cache*
set wildignore+=*DS_Store*
set wildignore+=vendor/rails/**
set wildignore+=vendor/cache/**
set wildignore+=*.gem
set wildignore+=log/**
set wildignore+=tmp/**
set wildignore+=*.png,*.jpg,*.gif

” ================ Scrolling ========================

“Start scrolling when we’re 8 lines away from margins
set scrolloff=8

set sidescrolloff=15
set sidescroll=1


That’s it.

Leave a Reply

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