Skip to content

Instantly share code, notes, and snippets.

@paulmooring
Created August 10, 2012 16:48
Show Gist options
  • Save paulmooring/3315501 to your computer and use it in GitHub Desktop.
Save paulmooring/3315501 to your computer and use it in GitHub Desktop.
My vimrc
" ~/.vimrc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Author: Paul Mooring
"
" Version: 1.4
" Date: 20120925
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" => General
""""""""""""""""""""""""""""""
" Pathogen plugin manager
call pathogen#infect()
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
" Enable filetype plugin
filetype plugin on
filetype indent on
" With quick key combos (e.g. ', w' for ':w!')
let mapleader = ","
nmap <leader>w :w!<cr>
nmap <leader>q :qall!<cr>
" Sets how many lines of history VIM has to remember
set history=2048
" Set to auto read when a file is changed from the outside
set autoread
" Show position at bottom
set ruler
" Show line numbers
set number
" Fix vim's tab completion
set wildmode=longest:full
set wildmenu
" Set backspace config
set backspace=eol,start,indent
set whichwrap+=<,>,h,l,[,]
" Cool pattern matching stuff
set magic
" Searches are only case sensitive when term has an uppercase character
set ignorecase
set smartcase
" Highlight search results
set hlsearch
" ...but turn it off w/ space
map <Space> :noh<cr>
" Search highlights matches while typing
set incsearch
" Turn off lazyRedraw (don't redraw while running macros)
set nolazyredraw
" Highlight matching braces
set showmatch
" No sound on errors
set noerrorbells
set novisualbell
" Syntax highlighting
syntax enable
" Set shell to bash
set shell=/bin/bash
set encoding=utf8
try
lang en_US
catch
endtry
" Set filetypes
au BufRead,BufNewFile .followup,.article,.letter,/tmp/pico*,nn.*,snd.*,/tmp/mutt* :set ft=mail
autocmd BufEnter README,TODO if &filetype == '' | setlocal filetype=text | endif
autocmd BufEnter *.escript if &filetype == '' | setlocal filetype=erlang | endif
autocmd BufEnter *.md if &filetype == '' | setlocal filetype=markdown | endif
autocmd FileType ruby setlocal foldmethod=indent expandtab tabstop=2 shiftwidth=2
autocmd FileType c,cpp setlocal foldmethod=syntax foldnestmax=2 cinoptions=(0,g0,N-s,:0
autocmd FileType erlang,haskell,ocaml setlocal foldmethod=indent expandtab tabstop=4 shiftwidth=4 textwidth=0
autocmd FileType python setlocal foldmethod=indent
autocmd FileType text,markdown,tex,mail setlocal textwidth=72 formatoptions+=2l colorcolumn=+1 spell
autocmd FileType help setlocal nospell
""""""""""""""""""""""""""""""
" => Tab and indent
""""""""""""""""""""""""""""""
" Uses 4 spaces not tabs...
set expandtab
set shiftwidth=4
""""""""""""""""""""""""""""""
" => Visual mode related
""""""""""""""""""""""""""""""
" In visual mode when you press * or # to search for the current selection
vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>
""""""""""""""""""""""""""""""
" => Command mode related
""""""""""""""""""""""""""""""
" Bash like (emacs mode) keys for the command line
cnoremap <C-A> <Home>
cnoremap <C-E> <End>
cnoremap <C-K> <C-U>
cnoremap <C-P> <Up>
cnoremap <C-N> <Down>
func! Cwd()
let cwd = getcwd()
return "e " . cwd
endfunc
""""""""""""""""""""""""""""""
" => Moving around
""""""""""""""""""""""""""""""
" Smart way to change windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Close the current buffer
map <leader>bd :Bclose<cr>
" Close all the buffers
map <leader>ba :1,300 bd!<cr>
" Use the arrows to something usefull
map <right> :bn<cr>
map <left> :bp<cr>
" Tab configuration
map <leader>tn :tabnew<cr>
map <leader>te :tabedit
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
" When pressing <leader>cd switch to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction
" Specify the behavior when switching between buffers
try
set switchbuf=usetab
set stal=2
catch
endtry
""""""""""""""""""""""""""""""
" => Statusline
""""""""""""""""""""""""""""""
" Format the statusline
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c
function! CurDir()
let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
return curdir
endfunction
function! HasPaste()
if &paste
return 'PASTE MODE '
else
return ''
endif
endfunction
""""""""""""""""""""""""""""""
" => General Abbrevs
""""""""""""""""""""""""""""""
iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>
""""""""""""""""""""""""""""""
" => Editing mappings
""""""""""""""""""""""""""""""
"Remap VIM 0
map 0 ^
"Gundo to F5
nnoremap <F5> :GundoToggle<CR>
"Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
"Delete trailing white space, useful for Python ;)
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()
set guitablabel=%t
""""""""""""""""""""""""""""""
" => Cope
""""""""""""""""""""""""""""""
" Do :help cope if you are unsure what cope is. It's super useful!
map <leader>cc :botright cope<cr>
map <leader>n :cn<cr>
map <leader>p :cp<cr>
""""""""""""""""""""""""""""""
" => Spell checking
""""""""""""""""""""""""""""""
"Pressing ,ss will toggle and untoggle spell checking
map <leader>ss :setlocal spell!<cr>
"Shortcuts using <leader>
map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=
""""""""""""""""""""""""""""""
" => Erlang section
""""""""""""""""""""""""""""""
let g:erlang_man_path='/usr/local/share/man'
let erlang_show_errors = 0
let erlang_skel_header = {'author': 'Paul Mooring <paul@opscode.com>'}
au FileType erlang call ErlangFold()
function! ErlangFold()
let erlang_folding = 1
setl foldmethod=indent
set foldlevelstart=1
endfunction
""""""""""""""""""""""""""""""
" => Python section
""""""""""""""""""""""""""""""
let python_highlight_all = 1
au FileType python syn keyword pythonDecorator True None False self
au BufNewFile,BufRead *.jinja set syntax=htmljinja
au BufNewFile,BufRead *.mako set ft=mako
au FileType python inoremap <buffer> $r return
au FileType python inoremap <buffer> $i import
au FileType python inoremap <buffer> $p print
au FileType python inoremap <buffer> $f #--- PH ----------------------------------------------<esc>FP2xi
au FileType python map <buffer> <leader>1 /class
au FileType python map <buffer> <leader>2 /def
au FileType python map <buffer> <leader>C ?class
au FileType python map <buffer> <leader>D ?def
""""""""""""""""""""""""""""""
" => JavaScript section
"""""""""""""""""""""""""""""""
au FileType javascript call JavaScriptFold()
au FileType javascript setl fen
au FileType javascript setl nocindent
au FileType javascript imap <c-t> AJS.log();<esc>hi
au FileType javascript imap <c-a> alert();<esc>hi
au FileType javascript inoremap <buffer> $r return
au FileType javascript inoremap <buffer> $f //--- PH ----------------------------------------------<esc>FP2xi
function! JavaScriptFold()
setl foldmethod=syntax
setl foldlevelstart=1
syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend
function! FoldText()
return substitute(getline(v:foldstart), '{.*', '{...}', '')
endfunction
setl foldtext=FoldText()
endfunction
""""""""""""""""""""""""""""""
" => Command-T
""""""""""""""""""""""""""""""
let g:CommandTMaxHeight = 15
set wildignore+=*.o,*.obj,.git,*.pyc
noremap <leader>j :CommandT<cr>
noremap <leader>y :CommandTFlush<cr>
""""""""""""""""""""""""""""""
" => Vim grep
""""""""""""""""""""""""""""""
let Grep_Skip_Dirs = 'RCS CVS SCCS .svn generated'
set grepprg=/bin/grep\ -nH
""""""""""""""""""""""""""""""
" => NERDTree
""""""""""""""""""""""""""""""
map <leader>d :execute 'NERDTreeToggle ' . getcwd()<CR>
" Only start nerdtree if no file is given as an arg
function! StartUp()
if 0 == argc()
NERDTree
end
endfunction
autocmd VimEnter * call StartUp()
""""""""""""""""""""""""""""""
" => GUI settings
""""""""""""""""""""""""""""""
:colorscheme desert
set guifont=Monaco:h13
""""""""""""""""""""""""""""""
" => MISC
""""""""""""""""""""""""""""""
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment