I spent most of the day today getting comfortable using Vim. If you are not familiar with it or some of the other high octane text editors available and you spend most of your time at the computer writing text files, you might want to check them out. Vim and it’s ilk are highly configurable text editing programs made for productivity and extensibility. The pertinent information in this post falls into the “write this down for next time” category, but I thought I’d take a moment to also share why I am jumping into Vim after 6 years of writing code in IDEs.
Additionally, I’ve found that the text editor is the most important part of my toolchain. A good editor that doesn’t distract yet is responsive is essential. I like TextMate quite a lot. However, I have reached a point where I want to fine tune my environment beyond what TextMate offers and Vim seems to be the tool for that.
Being able to use Vim from the command line is a major plus for me. If you have Mac, it is most likely already installed on your computer. Just open the Terminal and type
vim. If you immediately attempt to enter text you might be a little shocked. Instead, re-open Terminal and type
vimtutor. I am actually using a program called iTerm2 which is a more advanced version of the Terminal.
Here are the first things I set out to do on my first day using Vim and some impressions or tips on each.
A quick intro that focusses on learning through doing and teaches all of the basics you need to know in order to get going. This is definitely the place to start out.
Set up Solarized color scheme
This proved to be pretty simple and required me to learn a little about Vim’s plugin structure and configurability. You can get the Solarized theme for Vim complete with installation instructions here: https://github.com/altercation/vim-colors-solarized
Customize behavior for certain languages
One thing that I really like about Vim is how the plugin and syntax highlighting system works. All configuration settings and plugins are contained within the root directory of your computer in a folder called
.vim. Within this directory you can add sub-dirs that contain
.vim files that define indentation, syntax and color schemes. There is also a file at the root called
.vimrc. This file defines global settings for Vim.
So far my .vimrc file looks like this:
syntax on colorscheme solarized filetype indent on filetype plugin on set background=dark set nu
The last line from that snippet turns on line numbers in Vim.
Another helpful trick I learned when trying to load plugins was to list all of the loaded scripts. Keep in mind that scripts are loaded as they are needed. So if you are trying to load a python script the syntax file for python may not have loaded yet and won’t appear in the list. To view loaded scripts type
:scriptnames from within Vim.
I also need to update the indentation behavior for Python code. To do this I added a file called
python.vim to the
~/.vim/indent. The contents of that file look like this:
set expandtab set textwidth=0 set tabstop=4 set softtabstop=4 set shiftwidth=4 set autoindent set backspace=indent,eol,start set ignorecase set smarttab
This seems to work pretty well for all of my existing Python code. It sets indentation at 4 spaces which is compliant with the PEP 8 style guide.