Find file
c7dcefc Jan 13, 2017
@r00k @andyw8
379 lines (312 sloc) 11 KB
" ========================================================================
" Vundle stuff
" ========================================================================
set nocompatible " Required by vundle
filetype off " Required by vundle
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
" My bundles
Plugin 'ervandew/supertab'
Plugin 'kchmck/vim-coffee-script'
Plugin 'skwp/greplace.vim'
Plugin 'tomtom/tcomment_vim'
Plugin 'thoughtbot/vim-rspec'
Plugin 'tpope/vim-bundler'
Plugin 'tpope/vim-dispatch'
Plugin 'tpope/vim-endwise'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-unimpaired'
Plugin 'vim-ruby/vim-ruby'
Plugin 'ctrlpvim/ctrlp.vim'
" Clojure
Plugin 'tpope/vim-fireplace'
" Elm
Plugin 'ElmCast/elm-vim'
let g:elm_setup_keybindings = 0 " Get out of my bindings
" Want this, but not showing errors:
let g:elm_format_autosave = 1
" Colors
Plugin 'nanotech/jellybeans.vim'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" ========================================================================
" Ruby stuff
" ========================================================================
syntax on " Enable syntax highlighting
augroup myfiletypes
" Clear old autocmds in group
" autoindent with two spaces, always expand tabs
autocmd FileType ruby,eruby,yaml setlocal ai sw=2 sts=2 et
autocmd FileType ruby,eruby,yaml setlocal path+=lib
autocmd FileType ruby,eruby,yaml setlocal colorcolumn=80
" Make ?s part of words
autocmd FileType ruby,eruby,yaml setlocal iskeyword+=?
" Clojure
autocmd FileType clojure setlocal colorcolumn=80
autocmd FileType clojure map <Leader>t :!lein test<cr>
augroup END
" Enable built-in matchit plugin
runtime macros/matchit.vim
" ================
let mapleader = ","
imap jj <esc>
map <Leader>ac :sp app/controllers/application_controller.rb<cr>
vmap <Leader>b :<C-U>!git blame <C-R>=expand("%:p") <CR> \| sed -n <C-R>=line("'<") <CR>,<C-R>=line("'>") <CR>p <CR>
map <Leader>bb :!bundle install<cr>
nmap <Leader>bi :source ~/.vimrc<cr>:PluginInstall<cr>
vmap <Leader>bed "td?describe<cr>obed<tab><esc>"tpkdd/end<cr>o<esc>:nohl<cr>
map <Leader>cc :!cucumber --drb %<CR>
map <Leader>cu :Tabularize /\|<CR>
map <Leader>co mmggVG"*y`m
map <Leader>cc :Rjcollection client/
map <Leader>cj :Rjspec client/
map <Leader>cm :Rjmodel client/
map <Leader>cs :call SearchForCallSitesCursor()<CR>
map <Leader>ct :Rtemplate client/
map <Leader>cv :Rjview client/
map <Leader>cn :e ~/Dropbox/notes/coding-notes.txt<cr>
map <Leader>d orequire 'pry'<cr>binding.pry<esc>:w<cr>
map <Leader>dr :e ~/Dropbox<cr>
map <Leader>dj :e ~/Dropbox/notes/debugging_journal.txt<cr>
map <Leader>ec :e ~/code/
map <Leader>gw :!git add . && git commit -m 'WIP' && git push<cr>
map <Leader>gl :e Gemfile.lock<cr>
map <Leader>f :call OpenFactoryFile()<CR>
map <Leader>fix :cnoremap % %<CR>
map <Leader>fa :sp test/factories.rb<CR>
map <Leader>i mmgg=G`m
map <Leader>l :Eval<cr>
map <Leader>m :Rmodel
map <Leader>mf mmgqap`m:w<cr>
map <Leader>nn :sp ~/Dropbox/notes/programming_notes.txt<cr>
map <Leader>nt :e! ~/Dropbox/docs/trailmix/<cr>
map <Leader>o :w<cr>:call RunNearestSpec()<CR>
map <Leader>p :set paste<CR><esc>"*]p:set nopaste<cr>
map <Leader>pn :sp ~/Dropbox/work/thoughtbot/notes/<cr>
map <Leader>q :copen<cr><cr>
map <Leader>ra :%s/
map <Leader>rd :!bundle exec rspec % --format documentation<CR>
map <Leader>rs :vsp <C-r>#<cr><C-w>w
map <Leader>rt q:?!ruby<cr><cr>
map <Leader>rw :%s/\s\+$//<cr>:w<cr>
map <Leader>sc :sp db/schema.rb<cr>
map <Leader>sg :sp<cr>:grep<space>
map <Leader>sj :call OpenJasmineSpecInBrowser()<cr>
map <Leader>sm :RSmodel
map <Leader>sp yss<p>
map <Leader>sn :e ~/.vim/snippets/ruby.snippets<CR>
map <Leader>so :so %<cr>
map <Leader>sq j<c-v>}klllcs<esc>:wq<cr>
map <Leader>ss ds)i <esc>:w<cr>
map <Leader>st :!ruby -Itest % -n "//"<left><left>
map <Leader>su :RSunittest
map <Leader>sv :RSview
map <Leader>t :w<cr>:call RunCurrentSpecFile()<CR>
map <Leader>y :!rspec --drb %<cr>
map <Leader>u :Runittest<cr>
map <Leader>vc :Vcontroller<cr>
map <Leader>vf :Vfunctional<cr>
map <Leader>vg :vsp<cr>:grep
map <Leader>vi :tabe ~/.vimrc<CR>
map <Leader>vu :AV<CR>
map <Leader>vm :Vmodel<cr>
map <Leader>vv :Vview<cr>
map <Leader>w <C-w>w
map <Leader>x :exec getline(".")<cr>
" Edit another file in the same directory as the current file
" uses expression to extract path from current file's path
map <Leader>e :e <C-R>=escape(expand("%:p:h"),' ') . '/'<CR>
map <Leader>s :split <C-R>=escape(expand("%:p:h"), ' ') . '/'<CR>
map <Leader>v :vnew <C-R>=escape(expand("%:p:h"), ' ') . '/'<CR>
map <C-h> :nohl<cr>
imap <C-l> :<Space>
" Note that remapping C-s requires flow control to be disabled
" (e.g. in .bashrc or .zshrc)
map <C-s> <esc>:w<CR>
imap <C-s> <esc>:w<CR>
map <C-t> <esc>:tabnew<CR>
map <C-x> <C-w>c
" Emacs-like beginning and end of line.
imap <c-e> <c-o>$
imap <c-a> <c-o>^
" Quickfix management
map <Space><Space> :ccl<cr>
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set history=500 " keep 500 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set showmatch
set nowrap
set backupdir=~/.tmp
set directory=~/.tmp " Don't clutter my dirs up with swp and tmp files
set autoread
set wmh=0
set viminfo+=!
set guioptions-=T
set guifont=Triskweline_10:h10
set et
set sw=2
set smarttab
set noincsearch
set ignorecase smartcase
set laststatus=2 " Always show status line.
set relativenumber
set number
set gdefault " assume the /g flag on :s substitutions to replace all matches in a line
set autoindent " always set autoindenting on
set lazyredraw " Don't redraw screen when running macros.
colorscheme jellybeans
" Set the tag file search order
set tags=./tags;
" Use Silver Searcher instead of grep
set grepprg=ag
" Make the omnicomplete text readable
highlight PmenuSel ctermfg=black
" Ignore stuff that can't be opened
set wildignore+=tmp/**
" Highlight the status line
highlight StatusLine ctermfg=blue ctermbg=yellow
" Format xml files
au FileType xml exe ":silent 1,$!xmllint --format --recover - 2>/dev/null"
set shiftround " When at 3 spaces and I hit >>, go to 4, not 5.
set nofoldenable " Say no to code folding...
command! Q q " Bind :Q to :q
command! Qall qall
command! QA qall
command! E e
command! W w
command! Wq wq
" Execute macro in q
map Q @q
" Disable K looking stuff up
map K <Nop>
au BufNewFile,BufRead *.txt setlocal nolist " Don't display whitespace
" Better? completion on command line
set wildmenu
" What to do when I press 'wildchar'. Worth tweaking to see what feels right.
set wildmode=list:full
" (Hopefully) removes the delay when hitting esc in insert mode
set noesckeys
set ttimeout
set ttimeoutlen=1
" Turn on spell-checking in markdown and text.
" au BufRead,BufNewFile *.md,*.txt setlocal spell
" Merge a tab into a split in the previous window
function! MergeTabs()
if tabpagenr() == 1
let bufferName = bufname("%")
if tabpagenr("$") == tabpagenr()
execute "buffer " . bufferName
nmap <C-W>u :call MergeTabs()<CR>
" Squash all commits into the first during rebase
function! SquashAll()
normal ggj}klllcf:w
function! SearchForCallSitesCursor()
let searchTerm = expand("<cword>")
call SearchForCallSites(searchTerm)
" Search for call sites for term (excluding its definition) and
" load into the quickfix list.
function! SearchForCallSites(term)
cexpr system('ag ' . shellescape(a:term) . '\| grep -v def')
" Make CtrlP use ag for listing the files. Way faster and no useless files.
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
let g:ctrlp_use_caching = 0
" Test-running stuff
"Now using thoughtbot/vim-rspec and tpope/dispatch.
let g:rspec_command = "!clear && bin/rspec {spec}"
inoremap <Tab> <C-P>
" Let's be reasonable, shall we?
nmap k gk
nmap j gj
let g:CommandTMaxHeight=50
let g:CommandTMatchWindowAtTop=1
" Don't wait so long for the next keypress (particularly in ambigious Leader
" situations.
set timeoutlen=500
" Remove trailing whitespace on save for ruby files.
au BufWritePre *.rb :%s/\s\+$//e
function! OpenFactoryFile()
if filereadable("test/factories.rb")
execute ":sp test/factories.rb"
execute ":sp spec/factories.rb"
" Set gutter background to black
highlight SignColumn ctermbg=black
" RENAME CURRENT FILE (thanks Gary Bernhardt)
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
map <Leader>n :call RenameFile()<cr>
" Display extra whitespace
set list listchars=tab:»·,trail:·
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
" Make it more obvious which paren I'm on
hi MatchParen cterm=none ctermbg=black ctermfg=yellow
" By default, vim thinks .md is Modula-2.
autocmd BufNewFile,BufReadPost *.md set filetype=markdown
" Without this, vim breaks in the middle of words when wrapping
autocmd FileType markdown setlocal nolist wrap lbr
" Wrap the quickfix window
autocmd FileType qf setlocal wrap linebreak
" Make it more obviouser when lines are too long
highlight ColorColumn ctermbg=235
" ========================================================================
" End of things set by me.
" ========================================================================
" Only do this part when compiled with support for autocommands.
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
" 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
endif " has("autocmd")