Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 361 lines (319 sloc) 12 KB
"Pathogen for plugins.
filetype off
call pathogen#infect()
set nocompatible " Use smarter defaults than Vi's.
set nobackup " Don't write out backup files.
set noswapfile
set nowritebackup
set undodir=~/.vim/tmp/undo/ " store persistent undo files here.
filetype plugin on
" Chrome
set encoding=utf-8
set showmode
set showcmd
set hidden " hide buffers when opening new files, without having to save.
set wildmenu
set wildmode=list:longest
set visualbell
set cursorline
set ttyfast
set ruler
set backspace=indent,eol,start " Allow backspacing over everything in insert mode.
set laststatus=2 " Always show the status line
set number
set undofile
set scrolloff=4 " Keep 4 lines of context when scrolling
set shortmess+=I " Remove the default splash screen when a new file is created.
set autoread " When a file is changed outside of Vim, just reload it rather than asking what to do.
set nofoldenable " I hate going into a file with parts folded.
" Line wrapping
set textwidth=110
" Set wrap
set nolist " List disables linebreak.
set linebreak
set colorcolumn=110 " Show a margin indicator.
set formatoptions=croql " Now it shouldn't hard-wrap long lines as you're typing (annoying), but you can gq
" as expected.
" Indent lines after pasting them. Important for when you paste a line inside an if block and it's not
" indented properly inside the if. If this has bad edge cases, try
nnoremap p p`[v`]=
" Tabs
set tabstop=2 "the width hard tab characters are rendered.
set shiftwidth=2 "indent selections the same as softtabstop.
set softtabstop=2
set expandtab "Use spaces instead of tabs.
highlight Cursor guibg=LightGoldenRod guifg=LightGoldenRod
set bg=dark
syntax on
set synmaxcol=200 " Don't syntax highlight super long lines. It makes Vim scrolling very sluggish.
" Searching
set hlsearch
set ignorecase " ignore case when searching.
set smartcase " if you include an uppercase while searching, become case sensitive.
set incsearch " show search matches as you type.
set gdefault " Apply substitutions globally on a line.
" Spellcheck
set spell " My custom spellfile is in ~/.vim/spell/en.utf-8.add
" This function ignores URLs and file paths when spellchecking. Note that some file types set `syntax spell
" toplevel` and must be treated differently than other groups.
" -
fun! SetupSpellCheckIgnoreRules()
if (&filetype=='markdown')
syn case match
syn match spellcheckURL /\<http[^ ]\+/
syn match spellcheckFilepath / \/.*\>/
syn match spellcheckCamelCase /\<[A-Z][a-z]\+[A-Z].\{-}\>/
syn case ignore
syn match spellcheckURL /\<http[^ ]\+/ contains=@NoSpell transparent
syn match spellcheckFilepath / \/.*\>/ contains=@NoSpell transparent
syn match spellcheckCamelCase /\<[A-Z][a-z]\+[A-Z].\{-}\>/ contains=@NoSpell transparent
syn cluster Spell add=spellcheckURL
syn cluster Spell add=spellcheckFilepath
syn cluster Spell add=spellcheckCamelCase
let mapleader=";"
" Make it easy to clear searches
noremap <leader><space> :nohlsearch<cr>
call SetupSpellCheckIgnoreRules()
" Basic editing
autocmd FocusLost * silent! wa " Save file when focus is lost
set shiftround " use multiples of shiftwidth when indenting with <
set autoindent
set copyindent
filetype plugin indent on
set nojoinspaces " When joining lines, Vim inserts two spaces if a line ends with a period. Turn that off.
" These are later remapped to move between tabs.
noremap <Leader>j J
noremap <Leader>k K
set clipboard=unnamed " Use the OSX clipboard, not vim's own
" Emacs-style bindings in insert mode. tpope has wrapped this into the "rsi" vim plugin.
imap <C-d> <Del>
imap <silent> <C-e> <ESC>A
imap <silent> <C-a> <ESC>I
" Insert newlines without entering insert mode. From the Vim wiki.
map <S-Enter> O<Esc>
map <CR> o<Esc>
" Reformat paragraph. I do this very often, so this is a shortcut.
noremap <Leader>q gqap
" Remove hard line breaks so we can paste into emails or other soft-wrap formats. w for "wrap".
" Since we're using a script as our text formatter, pass the line length via an env var. `` restores cursor.
" We not using a substitution as in so that we can preserve list formatting in md.
noremap <leader>wap :let $LINE_LENGTH=10000<CR>gqap``<CR>:let $LINE_LENGTH=&textwidth<CR>
noremap <leader>wG :let $LINE_LENGTH=10000<CR>Ggqgg``<CR>:let $LINE_LENGTH=&textwidth<CR>
" Indentation in insert mode
" These keys are alt+< and alt+> on OSX. They indent the line while preserving the cursor position.
" q{motion} begins a macro. I often hit q to exit Fireplace's outputs, and accidentally start recording
" a macro. Disable macro recording for now.
noremap q <esc>
" Edit and reload vim rc
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC \| :call RainbowParenthesesReset()<CR>
" nmap <silent> <leader>sv :so $MYVIMRC<CR>
" Make it easier to move around through multiline blocks of text:
noremap j gj
noremap k gk
noremap <C-u> 10k
noremap <C-d> 10j
noremap <C-J> 40j
noremap <C-K> 40k
" Tab is easier than % for selecting matched pairs. TODO(philc): vet
nnoremap <tab> %
vnoremap <tab> %
" leader-v to reselect pasted text, for indentation purposes etc.
nnoremap <leader>v V`
" Macvim Tabs
" Meta-# to select a tab.
noremap <D-1> 1gt
noremap <D-2> 2gt
noremap <D-3> 3gt
noremap <D-4> 4gt
noremap <D-5> 5gt
noremap <D-6> 6gt
noremap <D-7> 7gt
imap <D-1> <esc><D-1>
imap <D-2> <esc><D-2>
imap <D-3> <esc><D-3>
imap <D-4> <esc><D-4>
imap <D-5> <esc><D-5>
imap <D-6> <esc><D-6>
imap <D-7> <esc><D-7>
" These are mapped to CMD+J and CMD+K by KeyRemap4Macbook, which I use for tab switching.
noremap <A-D-Left> gT
noremap <A-D-Right> gt
imap <A-D-Left> <esc>gT
imap <A-D-Right> <esc>gt
" Window splits
noremap <D-d> <C-w>s
noremap <D-D> <C-w>v
noremap <D-j> <C-w>j
noremap <D-k> <C-w>k
noremap <D-h> <C-w>h
noremap <D-l> <C-w>l
imap <D-d> <esc><D-d>
imap <D-D> <esc><D-D>
imap <D-j> <esc><D-j>
imap <D-k> <esc><D-k>
imap <D-h> <esc><D-h>
imap <D-l> <esc><D-l>
" Resizing windows
noremap <leader>= 6<C-W>+
noremap <leader>- 6<C-W>-
" Markdown
" Treat .txt files as markdown. All of my .txt notes are in markdown.
let $LINE_LENGTH=&textwidth
augroup markdown_philc
autocmd BufRead,BufNewFile *.txt set filetype=markdown
" By default Vim treats .md as modula2.
autocmd BufRead,BufNewFile *.md set filetype=markdown
" Disable the annoying display of italics which is triggered by underscores_in_words.
autocmd FileType markdown :syn clear markdownItalic
autocmd FileType markdown exec 'set formatprg=~/scripts/code/markdown_formatter.rb'
augroup end
" Shortcut for writing a markdown header line.
nmap <leader>h1 V"zy"zpVr=
nmap <leader>h2 V"zy"zpVr-
" Render a markdown preview in a browser.
nnoremap <LEADER>M :%w ! markdown_doctor \| bcat<CR><CR>
" commenting (provided by NERDCommenter
let NERDSpaceDelims=1 " Insert one space after comment characters.
map <D-/> <plug>NERDCommenterToggle
imap <D-/> <esc><D-/>i
map <leader>/ <plug>NERDCommenterToggle
" Ctrl-P (cmd-t)
nnoremap <leader>t :CtrlP .<CR>
" Follow symlinks but ignore looped internal symlinks to avoid dupes.
let g:ctrlp_follow_symlinks = 1
let g:ctrlp_custom_ignore = {
\ 'dir': '/public/assets/*,/beancounter_logs/*'
\ }
" Omit class files from the listings
set wildignore+=*.class
set wildignore+=*.log
set wildignore+=*.gz
" Nerd Tree
nmap <leader>n :NERDTreeTabsToggle<CR>
" Focuses the current file in nerd tree.
nmap <leader>f :NERDTreeFind<CR>
" These two are mapped to J and K by default. Unbind them so we can use J and K to switch tabs.
let NERDTreeMapJumpFirstChild='_'
let NERDTreeMapJumpLastChild='_'
let g:nerdtree_tabs_open_on_new_tab=0
let g:nerdtree_tabs_open_on_gui_startup=0
" Fireplace
" Remap shift-k to leader k. I use shift-k for tab switching.
augroup fireplace_philc
autocmd BufEnter *.clj nmap <buffer> K gt
autocmd BufEnter *.clj nmap <buffer> <leader>k <Plug>FireplaceK
augroup end
" Powerline
let g:Powerline_symbols = 'unicode'
" Using a customized powerline theme to remove segments, as suggested by
let g:Powerline_theme='my_powerline_theme'
" Rainbow parentheses
let g:rbpt_max = 10
let g:rbpt_colorpairs = [
\ ['gray', 'HotPink1'],
\ ['darkred', 'cyan1'],
\ ['darkcyan', 'RoyalBlue1'],
\ ['darkgreen', 'yellow1'],
\ ['darkblue', 'MediumOrchid'],
\ ['gray', 'DeepSkyBlue1'],
\ ['darkred', 'DarkOrange1'],
\ ['darkcyan', 'LimeGreen'],
\ ['darkgreen', 'goldenrod1'],
\ ['darkblue', 'brown1'],
\ ]
function! RainbowParenthesesReset()
" Rainbow parentheses breaks the syntax highlighting of vim-less.
if &ft =~ 'less'
augroup rainbow_parentheses_philc
autocmd Filetype clojure,ruby RainbowParenthesesActivate
autocmd Filetype clojure,ruby RainbowParenthesesLoadRound
autocmd Filetype clojure,ruby RainbowParenthesesLoadBraces
augroup end
" vim-clojure-static indentation
let g:clojure_align_multiline_strings = 0
let g:clojure_fuzzy_indent = 1
" let g:clojure_fuzzy_indent_patterns = ['with', 'def', 'let']
let g:clojure_fuzzy_indent_patterns = "with.*,def.*,let.*,send.*"
let g:clojure_fuzzy_indent_patterns .= ",cli.*" " Clojure core
let g:clojure_fuzzy_indent_patterns .= ",GET,POST,PUT,PATCH,DELETE,context" " Compojure
let g:clojure_fuzzy_indent_patterns .= ",clone-for" " Enlive
let g:clojure_fuzzy_indent_patterns .= ",select.*,insert.*,update.*,delete.*,with.*" " Korma
let g:clojure_fuzzy_indent_patterns .= ",fact,facts" " Midje
let g:clojure_fuzzy_indent_patterns .= ",up,down,table" " Lobos
let g:clojure_fuzzy_indent_patterns .= ",when-eiligible,with-eligible-values,url-of-form"
" Misc File types.
augroup misc_filetypes
autocmd BufNewFile,BufRead Guardfile,.Guardfile,Vagrantfile set filetype=ruby
" Treat .erb as html
autocmd BufRead,BufNewFile *.erb set filetype=html
augroup end
" Colorscheme
set background=dark
if &t_Co >= 256 || has("gui_running")
" colorscheme Tomorrow-Night-Bright
colorscheme mustang
" Some customizations to the Mustang theme.
hi Todo guifg=#808080 guibg=#000000 gui=italic ctermfg=244 " Don't make todos so loud.
" So gitgutter looks nicer.
hi SignColumn guibg=black
hi Comment gui=none " turn off italics for comments and strings.
hi String gui=none
hi Function gui=none " The function identification for clojure is sketchy so don't bold some and not others
" Make the margin indicator more subtle than the default red.
hi ColorColumn ctermbg=darkgray guibg=#444444
" Show extra whitespace
hi ExtraWhitespace guibg=#664444
hi ExtraWhitespace ctermbg=7
" Strip trailing whitespace on save
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
call cursor(l, c)
match ExtraWhitespace /\s\+$/
augroup trailing_whitespace
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
augroup end
augroup spelling_group
" Don't highlight URLs and file paths in spellcheck.
autocmd BufRead,BufNewFile * :call SetupSpellCheckIgnoreRules()
augroup end
" Set line wrapping to 72 chars when writing gitcommit messages, which is conventional
augroup gitcommit
autocmd FileType gitcommit :set textwidth=72
autocmd FileType gitcommit :set colorcolumn=72
augroup end
" Hide the macvim toolbar
if has("gui_running")
set guioptions=egmrt
" misc hacks
nnoremap <F2> :autocmd BufEnter handler.clj edit \| set filetype=clojure
Jump to Line
Something went wrong with that request. Please try again.