Skip to content

Instantly share code, notes, and snippets.

@tcrayford
Created March 17, 2011 22:58
Show Gist options
  • Save tcrayford/875318 to your computer and use it in GitHub Desktop.
Save tcrayford/875318 to your computer and use it in GitHub Desktop.
vimrc
set nocompatible
filetype off
silent! call pathogen#runtime_append_all_bundles()
filetype plugin indent on
runtime macros/matchit.vim
set hidden
set autoread
set nobackup
set noswapfile
set nowritebackup
set number
set ignorecase
set smartcase
set cmdheight=2
set t_Co=256
let mapleader = " "
map <leader>e :e <C-R>=expand("%:h")<cr>/
map <leader>r :r <C-R>=expand("%:h")<cr>/
" Go to previous file
nnoremap <leader><leader> <c-^>
" Open a new vsplit window and switch to it
nnoremap <leader>w <C-w>v<C-w>l
map <leader>f <Plug>PeepOpen
nmap <silent> <leader>v :tabe $MYVIMRC<CR>
nmap <silent> <leader>sv :source ~/.vimrc<CR>
" Copy current visual selection to osx clipboard
map <silent> <leader>y :<C-u>silent '<,'>w !pbcopy<CR>
map <leader>n :cn <CR>
map <leader>p :cp <CR>
function! RunTests()
make %
endfunction
function! JumpToError()
silent ccl
:redraw
if getqflist() != []
for error in getqflist()
if error['valid']
break
endif
endfor
let error_message = substitute(error['text'], '^ *', '', 'g')
silent cc!
call RedBar()
echo error_message
else
call GreenBar()
echo "All tests passed"
endif
endfunction
function! RedBar()
hi RedBar ctermfg=white ctermbg=red guibg=red
echohl RedBar
echon repeat(" ",&columns - 1)
echohl
endfunction
function! GreenBar()
hi GreenBar ctermfg=white ctermbg=green guibg=green
echohl GreenBar
echon repeat(" ",&columns - 1)
echohl
endfunction
" Testing shortcuts
"map <leader>th :!runhaskell "%" <cr>
"map <leader>lh :!hlint "%"<cr>
"map <leader>ti :!/Users/tcrayford/.bin/ioke-files/bin/ispec "%" <cr>
"map <leader>tj :!node specs.js --noColor<cr>
map <leader>s :call RunTests()<cr>:call JumpToError()<cr>
"map <leader>tr :!ruby "%" <cr>
" map <leader>tp :!python "%" <cr>
"map <leader>tc :!cake test <cr>
"map <leader>ml :w <cr> :! latex "%" && open writeup.dvi <cr>
"map <leader>tl :call RunTests()<cr>:call JumpToError()<cr>
"map <leader>tp :!script/lua_spec<cr>
" Seriously, who ever actually uses '
nnoremap ' `
nnoremap ` '
nnoremap j gj
nnoremap k gk
"Seriously, guys. It's not like :W is bound to anything anyway.
command! W :w
command! Q :q
command! Wall :wall
" Tab in visual mode bounces between being at the start and at the end
vnoremap <tab> o
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set history=1000 " keep 1000 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
colorscheme grb4
" Make tab completion for files/buffers act like bash
set wildmenu
set completeopt=longest,menu
" Softtabs, 2 spaces
set tabstop=2
set shiftwidth=2
set expandtab
set softtabstop=2
set smarttab
if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on")
syntax enable
set hlsearch
set cursorline
hi CursorLine cterm=NONE ctermbg=black
endif
set numberwidth=5
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif
" Remap the tab key to do autocompletion or indentation depending on the
" context (from http://www.vim.org/tips/tip.php?tip_id=102)
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
autocmd BufNewFile,BufRead *.lua compiler lua_assert
autocmd BufNewFile,BufRead *.less set filetype=css
function! SetGRBRailsCompiler()
compiler rspec
hi GreenBar term=reverse ctermfg=black ctermbg=green guifg=white guibg=green
endfunction
autocmd BufNewFile,BufRead *.rb call SetGRBRailsCompiler()
set statusline=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
set laststatus=2
" Map keys to go to specific files
map <leader>gr :topleft :split config/routes.rb<cr>
function! ShowRoutes()
" Requires 'scratch' plugin
:topleft 100 :split __Routes__
" Make sure Vim doesn't write __Routes__ as a file
:set buftype=nofile
" Delete everything
:normal 1GdG
" Put routes output in buffer
:0r! rake -s routes
" Size window to number of lines (1 plus rake output length)
:exec ":normal " . line("$") . _ "
" Move cursor to bottom
:normal 1GG
" Delete empty trailing line
:normal dd
endfunction
map <leader>gR :call ShowRoutes()<cr>
map <c-k> <c-w>k
map <c-j> <c-w>j
map <c-h> <c-w>h
map <c-l> <c-w>l
map <leader>w :let &wh = (&wh == 999 ? 10 : 999)<CR><C-W>=
let minwinheight=5
let winheight=999
map <leader>gd :topleft 100 :split spec/todo_spec.rb<cr>
function! PressedEnter()
:nohlsearch
endfunction
:nnoremap <CR> :nohlsearch\|:call PressedEnter()<cr>
for prefix in ['i', 'n', 'v']
for key in ['<Up>', '<Down>', '<Left>', '<Right>']
exe prefix . "noremap " . key . " <Nop>"
endfor
endfor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment