Setup Vim

Setup for editing Python

set ruler
set textwidth=78
filetype plugin indent on
set tabstop=4
set shiftwidth=4

" delete 4 spaces with backspace
set softtabstop=4

set nowrap

" no tabs, just spaces
set expandtab

" pretty colours
syntax on

" after enter, start at same indentation as previous line
set autoindent

Setup black theme for gvim

set background=dark
syntax on

colorscheme ir_black

This theme does not play well with the console, so consider installing the linux.vim theme (, and configuring vim as follows:

" pretty colours for both gvim and terminal
syntax on
if has('gui_running')
   set background=dark
   colorscheme ir_black
   colorscheme linux

If you are using spacehi.vim, modify the background color to black instead of gray, otherwise the highlight is not visible:

I.e., inside ~/.vim/colors/linux.vim:

hi Normal 		ctermbg=Black ctermfg=LightGrey gui=bold guifg=LightGrey guibg=black

Highlight trailing spaces

" Highlight whitespace
let g:spacehi_tabcolor="ctermfg=Gray"
let g:spacehi_tabcolor=g:spacehi_tabcolor . " guibg=DarkGray"
let g:spacehi_spacecolor="ctermbg=Gray"
let g:spacehi_spacecolor=g:spacehi_spacecolor . " guibg=DarkGray"
autocmd syntax * SpaceHi

Here is a shortcut for deleting trailing whitespace by pressing F5:

:nnoremap <silent> <F5> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>

Code folding

" Python code folding
autocmd FileType python,pyrex set foldmethod=indent foldminlines=3

Use zm to fold, forward arrow to unfold (see ":help fold" for more info).

Pyflakes integration

" Pyflakes integration with F5 (in insert mode: Ctrl-V F7 == ^[[18~)
autocmd FileType python let &mp = 'echo "*** running % ***" ; pyflakes %'
autocmd FileType python imap <Esc>[18~ <C-O>:make!
autocmd FileType python map  <Esc>[18~ :make!
autocmd FileType python set autowrite

Toggle auto-indentation for pasting

This switches autoindent on and off, so that you can easily paste pre-formatted code:

" Toggle autoindent when pasting
nnoremap <F2> :set invpaste paste?<CR>
imap <F2> <C-O><F2>
set pastetoggle=<F2>


While editing a file, use Ctrl-X Ctrl-F to complete a filename.

sub-sahara africa
sahara trip IanKnot rainbow