So I’m a Ruby guy , but rather than subject my team to a trove of bad Ruby, I figured I’d leave them some bad Python instead. That way everyone can hate on it. Seeing as if you ignore that Mike can do Ruby then working in Python seems a more team player option. Anyway, I digress.
I’m a well documented un-fan of Python. I find it smug, unwieldy and claustrophobic. I figured a bunch of this is because it looks so flat and compressed in my editor, Vim, because clearly, I could never be at fault. So clearly the fix to this is to spend a day swagging out my vimrc. I use Vim from Homebrew which gets me a Vim 7.4 with Ruby, Python and a bunch of other things that normally it is a pain to configure on OSX. Also, I’m using the Python in homebrew, so I can pip install things more easily too.
This actually really helped, so I figured I’d be that guy and do yet another post on basic vim stuff that you already know…
First off, you need to use:
What either of those do is manage your vim plugins, because just copying crap to your ~/.vim is so a few years ago. Vundle does it in a lovely self contained way, where as Pathogen was first. If you want do it all via the cluster fuck of git submodules, then use Pathogen. Otherwise use Vundle.
Here’s the top of my .vimrc, which is more or less the same as the installation bit for Vundle, because copying that here is better than just linking to the installation notes.
(laptoppen:~)% head -14 .vimrc " From https://github.com/gmarik/vundle set nocompatible " be iMproved filetype off " required! let vundledir = expand[ '~/.vim/bundle/vundle/' ] if isdirectory[vundledir] set rtp+=~/.vim/bundle/vundle/ call vundle#rc " let Vundle manage Vundle " required! Bundle 'gmarik/vundle' Bundle '...' " other bundles end
You then throw your “crap I found on github” plugins after that…
Yes, the Pythonic things.. Good call. The ones I’m most using are:
What do they do. Python-mode makes it all very python like and enabled Rope for telling you where you need to fix your code. This means you too can have PEP-8 compliant code…
let g:pymode_rope = 1 " Documentation let g:pymode_doc = 1 let g:pymode_doc_key = 'K' "Linting let g:pymode_lint = 1 let g:pymode_lint_checker = "pyflakes,pep8" " Auto check on save let g:pymode_lint_write = 1 " Support virtualenv let g:pymode_virtualenv = 1 " syntax highlighting let g:pymode_syntax = 1 let g:pymode_syntax_all = 1 let g:pymode_syntax_indent_errors = g:pymode_syntax_all let g:pymode_syntax_space_errors = g:pymode_syntax_all
Is a decent start. Plus, you’ll want this, unless you want people shouting at you for using tabs instead of space:
augroup vimrc_autocmds autocmd! " highlight characters past column 120 autocmd FileType python highlight Excess ctermbg=DarkGrey guibg=Black autocmd FileType python match Excess /\%78v.*/ autocmd FileType python set nowrap autocmd FileType python setlocal number tabstop=4 expandtab shiftwidth=4 softtabstop=4 autocmd FileType python colorscheme vividchalk augroup END
The colourscheme is the vividchalk from Tim Pope, which, personally, I found excellent for making clear the otherwise flat format of Python code. Why must there be spaces at the beginning of the line, but not inside s… Anyway. That leads me nicely on to Rainbow parentheses. It merely cycles the colours of parentheses in your code. I enable it with the following:
" Rainbow parentheses if isdirectory[expand('~/.vim/bundle/rainbow_parentheses.vim']) " rainbow parentheses always on au VimEnter * RainbowParenthesesActivate au Syntax * RainbowParenthesesLoadRound au Syntax * RainbowParenthesesLoadSquare au Syntax * RainbowParenthesesLoadBraces end
Which kinda brutes force it in to place, but seems to work so far.
So I’m really loving ‘Lokaltog/powerline’ and I even went so far as to install the fonts for use in iTerm2. It’s actually worth it if you get over the ridiculousness of installing custom fonts for some status line plugin for your text only editor. Of course, Inconsolata reigns supreme, IMHO.
Some of this is stolen from ever wonderful Mike Arpaia’s Chef repo but we differ on some opinions on things.