← Back

Vim Configuration

March 08, 2019


Configuring VIM is kind of like an addiction. Once you get started, you can catch yourself configuring and configuring until the day is over. Or maybe that’s just me. Anyway, here’s a few things that I’ve found throughout my time configuring the best text editor that there is — vim.

My personal dotfiles are housed on my git repo at github.com/pottsga/dotfiles. You’ll find my .vimrc there.

Plugin Manager

The only plugin manager you should use in 2019 is Vim-Plug. It is minimalist and very easy to get started with. Use the following bash script to download vim-plug onto your unix-like machine:

curl -fLo ~/.vim/autoload/plug.vim \
  --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Then you can configure ~/.vimrc to download plugins like this:

call plug#begin()

  Plug 'scrooloose/nerdtree'

call plug#end()

And call vim-plug by restarting vim and running :PlugInstall inside of vim and vim-plug will download the plugin and install it.

Sane Defaults

The following settings should be in practically every vim configuration file since they are pretty universally usable:

filetype plugin indent on
set nocompatible " Use VIM settings not VI settings
set noswapfile " Disable .swp files
set nobackup " Disable backup files
set backspace=indent,eol,start " Sane backspacing (make backspace behave as expected)
set confirm " Ask before closing a file if it's been used
set autoread " Automatically read files changed outside vim
set encoding=utf-8 " Editor's encoding is UTF8
syntax enable " Enable syntax
set expandtab " Use spaces instead of tabs when pressing tab
set shiftwidth=2 " Use 2 spaces per tab
set tabstop=2 " Use 2 spaces per tab
set smarttab  " Set 'tabstop' number of spaces on tab press
" Python-specific indentation
autocmd BufRead,BufNewFile
  \ *.py
  \ setlocal tabstop=4 shiftwidth=4 softtabstop=4
set number " Show line numbers
set nowrap " Don't wrap lines
set ruler " Always show cursor's position
set splitbelow " Split horizontally below the current pane for sanity
set splitright " Split right of the current pane for sanity
set showcmd " Show command in the bottom bar
set wildmenu " Visual complete in command menu
set colorcolumn=80 " Show a visual colored column for where code should break
if !has('gui-running')
  set t_Co=256 " It's 2019...we can have 256 colors in the terminal

" Navigation between panes with vim-like keys
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>