The best collection of VIM tips I've seen so far
Sep 28, 2010
Dick Brouwer
3 minute read

The best collection of VIM tips I’ve seen so far: http://stevelosh.com/blog/2010/09/coming-home-to-vim/

See my current .vimrc and required dependencies below.

Ack

sudo cpan -i App::Ack

CTags

curl -O http://superb-west.dl.sourceforge.net/sourceforge/ctags/ctags-5.7.tar.gz
tar xzvf ctags-5.7.tar.gz
cd ctags-5.7
./configure
make
make install

.vimrc

filetype off
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
filetype plugin indent on

set nocompatible
set modelines=0

let mapleader = ","
inoremap jj <ESC>

" Manage buffers more effectively
set hidden

" Add bottom scrollbar
set go+=b

" Color scheme and font
set background=dark
colorscheme molokai
set guifont=Monaco:h14

" Autocomplete settings
autocmd FileType python set omnifunc=pythoncomplete#Complete ft=python.django textwidth=79
let python_highlight_all = 1
au FileType python syn keyword pythonDecorator True None False self
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags|set textwidth=200 "ft=html.django_template
autocmd FileType htmldjango set omnifunc=htmlcomplete#CompleteTags|set textwidth=200 "ft=html.django_template
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
" set completeopt=longest,menuone

" show incomplete command in the lower right corner for when i forget insane vim commands
set showcmd

" Tab settings
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4

" Syntax Highlighting on
syntax on

" * General Settings
scriptencoding utf-8
set encoding=utf-8
set scrolloff=3
set autoindent
set showmode
set showcmd
set hidden
set wildmenu
set wildmode=list:longest
set visualbell
set cursorline
set ttyfast
set ruler
set backspace=indent,eol,start
set laststatus=2
set number
set numberwidth=3
try
    set relativenumber
    set undofile
catch
endtry

" Tame searching/moving
set ignorecase
set smartcase
set gdefault
set incsearch
set showmatch
set hlsearch
nnoremap <leader><space> :noh<cr>
nnoremap <tab> %
vnoremap <tab> %

set autowrite

" Set the terminal title
set title

" Scroll the viewport faster
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>

" Set to auto read when a file is changed from the outside
set autoread

" Handle long lines
set nowrap
set textwidth=79
set formatoptions=qrn1
try
    set colorcolumn=80
catch
endtry

" Make saving easier
au FocusLost * :wa
nmap <leader>w :w!<cr>
nmap <M-s> <ESC> :w<CR>

" Folding
set nofoldenable
set fdm=indent

" Taglist
set tags=./tags;/.
map <F4> :TlistToggle<CR>
autocmd BufWritePost *.py :TlistUpdate

" Shortcuts for adding a blank line
"nnoremap + maO<esc>`a
"nnoremap - mao<esc>`a

" Strip all trailing whitespace
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>

" Fold tag
nnoremap <leader>ft Vatzf

" Reselected pasted text
nnoremap <leader>v V`]

" Search
nnoremap <leader>a :Ack

" When pressing <leader>cd switch to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>

" Modify default VCSCommand mappings
let VCSCommandMapPrefix='<leader>f'

" Easier window navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

" Command-T
let g:CommandTMaxHeight = 15
set wildignore+=*.o,*.obj,.git,*.pyc
noremap <leader>y :CommandTFlush<cr>

" Execute Pyhon file being edited with <Shift> + e:
map <buffer> <S-e> :w<CR>:!/usr/bin/env python % <CR>

" Center screen around cursor with SPACE
nmap <space> zz

" JSlint highlighting
map <Leader>l :JSLintLight<CR>

" Open current document in browser
map <Leader>p :!open %<CR><CR>


comments powered by Disqus