Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
513 lines (479 sloc) 17.5 KB
" vim:fdm=marker
set nocompatible " We're running VIM, not vi
scriptencoding utf-8
filetype off " Turn off _before_ loading all Plugins
let mapleader = " "
inoremap § <ESC>
nnoremap <F1> <NOP>
inoremap <F1> <ESC>
noremap <F10> :set spell! spell?<CR>
nnoremap <F9> :Dispatch<CR>
" set synmaxcol=256
" set updatetime=1000
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'vim-scripts/Align'
" Plug 'chrisbra/csv.vim'
Plug 'junegunn/vim-slash'
Plug 'junegunn/goyo.vim' " {{{
let g:goyo_width = 119
let g:goyo_margin_top = 2
let g:goyo_margin_bottom = 2
nnoremap <Leader>V :Goyo<CR>
autocmd! User GoyoEnter Limelight
autocmd! User GoyoLeave Limelight!
" }}}
Plug 'junegunn/limelight.vim' " {{{ Hide other blocks of code
let g:limelight_conceal_ctermfg = 'gray'
let g:limelight_conceal_ctermfg = 244
let g:limelight_paragraph_span = 1
" nmap <Leader>l <Plug>(Limelight)
" xmap <Leader>l <Plug>(Limelight)
" }}}
Plug 'sheerun/vim-polyglot' " Highlighter
Plug 'dearrrfish/vim-applescript' " Highlighter
Plug 'lambdatoast/elm.vim' " elm -> javascript
Plug 'moll/vim-node'
Plug 'AndrewRadev/vim-eco' " Highlighter
Plug 'maksimr/vim-jsbeautify' " Formatter
Plug 'wsdjeg/vim-fetch' " Process line and column jump specifications
Plug 'christoomey/vim-tmux-navigator'
Plug 'tmux-plugins/vim-tmux'
Plug 'nathanaelkane/vim-indent-guides' " Highlighter, Indentation {{{
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_auto_colors = 0
let g:indent_guides_indent_levels = 8
" }}}
" Color-Schemes {{{
Plug 'nanotech/jellybeans.vim' " {{{
let g:jellybeans_overrides = {
\ 'background': {'ctermbg': 'none', '256ctermbg': 'none'},
\ 'TabLine': {'guibg': '000000', 'guifg': '585858', '256ctermbg': '16', 'attr': 'underline'},
\ 'TabLineSel': {'guibg': '343434', 'guifg': 'FFFFFF', '256ctermbg': 'none' },
\ 'TabLineFill': {'guibg': '000000', 'guifg': '343434', 'attr': 'underline'},
\ 'StatusLine': {'guibg': '444444', 'guifg': 'FFFFFF'},
\ 'StatusLineNC': {'guibg': '121212', 'guifg': '808080'},
\ 'CursorLine': {'guibg': '343434'},
\ 'ColorColumn': {'guibg': '1C1C1C'},
\ 'IndentGuidesOdd': {'guibg': '000000'},
\ 'IndentGuidesEven': {'guibg': '1C1C1C'},
\ 'SpecialKey': {'guibg': '000000'},
\ }
" }}}
" Plug 'altercation/solarized', {'rtp': 'vim-colors-solarized'} " {{{
" let g:solarized_termcolors=256
" }}}
Plug 'junegunn/seoul256.vim'
Plug 'morhetz/gruvbox'
Plug 'chriskempson/base16-vim'
let base16colorspace=256
" }}}
Plug 'tpope/vim-fugitive' " Git: command Integration {{{
" Util: Determine what happened and why
nnoremap <LEADER>gb :Gblame<CR>
Plug 'int3/vim-extradite'
nnoremap <LEADER>ge :Extradite<CR>
nnoremap <LEADER>gd :Gdiff<CR>
nnoremap <LEADER>gm :Gdiff develop<CR>
nnoremap <LEADER>dd :windo diffthis<CR>
" Util: Make things happen
nnoremap <LEADER>gs :Gstatus<CR>
nnoremap <LEADER>gc :Gcommit --verbose<CR>
Plug 'airblade/vim-gitgutter'
set signcolumn=yes
" }}}
Plug 'vim-ruby/vim-ruby' " {{{
let g:ruby_indent_access_modifier_style = 'outdent'
let g:ruby_indent_block_style = 'do'
let g:ruby_indent_assignment_style = 'variable'
" }}}
Plug 'tpope/vim-rails', " {{{
let g:rails_projections = {
\ "spec/factories/*.rb": {
\ "command": "factory",
\ "affinity": "collection",
\ "alternate": "app/models/%i.rb",
\ "related": "db/schema.rb#%s",
\ "test": ["unit/models/%i_test.rb", "spec/models/%i_spec.rb"],
\ "template": "FactoryGirl.define do\n factory :%i do\n end\nend",
\ "keywords": "factory sequence"
\ },
\ "app/mailers/*.rb": {
\ "command": "mailer",
\ "affinity": "collection",
\ "alternate": "spec/mailers/previews/%i_preview.rb",
\ "related": "app/views/mailers/%i.html.erb",
\ "test": ["unit/mailers/%i_test.rb", "spec/mailers/%i_spec.rb"],
\ "template": "",
\ "keywords": "mailers"
\ }}
" }}}
Plug 'tpope/vim-bundler' " Ruby Util Plugin: Gem Ctags
Plug 'tpope/vim-rake'
Plug 'danchoi/ri.vim', {'for': 'ruby'} " documentation access {{{
let g:ri_no_mappings=1
nnoremap <LEADER>rd :call ri#OpenSearchPrompt(1)<cr> " vertical split
nnoremap <LEADER>rc :call ri#LookupNameUnderCursor()<cr> " keyword lookup
" }}}
Plug 'GutenYe/gem.vim'
Plug 'thoughtbot/vim-rspec', {'for': 'ruby'} " {{{
let $RUBYOPT="-W0"
let g:rspec_command='Dispatch ./bin/rspec {spec}'
map <LEADER>sf :call RunCurrentSpecFile()<CR>
map <LEADER>sn :call RunNearestSpec()<CR>
map <LEADER>sl :call RunLastSpec()<CR>
map <LEADER>sa :Dispatch bin/parallel_rspec spec/<CR>
" }}}
Plug 'AndrewRadev/switch.vim' " Util: Switch between predefined replacements (true <-> false) {{{
nnoremap - :Switch<cr>
" }}}
" Plug '/usr/local/opt/flow/' | Plug 'flowtype/vim-flow', {'for': 'javascript'} " Util: JavaScript type checker
Plug '/usr/local/opt/fzf/' | Plug 'junegunn/fzf.vim' " ag & fzf {{{
if executable("ag")
set grepprg=ag\ --vimgrep\ --hidden
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
let g:fzf_buffers_jump = 1
let g:fzf_commits_log_options = '--color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
let g:fzf_history_dir = '~/.vim/fzf/'
" autocmd BufWinEnter
" \ if isdirectory('.git/')
" \ if !isdirectory('.git/fzf/')
" \ call mkdir('.git/fzf/')
" \ endif
" \ let g:fzf_history_dir = '.git/fzf/'
" \ else
" \ let g:fzf_history_dir = '~/.vim/fzf/'
" \ endif
autocmd VimEnter * command! Colors
\ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'})
nnoremap <C-G>c :Commits<CR>
nnoremap <C-G>b :BCommits<CR>
inoremap <expr> <c-x><c-k> fzf#complete('git commit-words')
function! s:branch_touched_sink(line)
let [status, file] = split(a:line, '\s\+')
execute 'e' file
endfunction
nnoremap <C-G>f :call fzf#run({
\
\ 'source': 'git branch-touched',
\ 'options': '--ansi',
\ 'sink': function('<sid>branch_touched_sink'),
\ })<CR>
nnoremap <C-F>c :Colors<CR>
" nnoremap <C-F>h :Helptags<CR> " TODO
nnoremap <C-F>t :Tags<CR>
nnoremap <C-P> :Files<CR>
nmap <leader><tab> <plug>(fzf-maps-n)
xmap <leader><tab> <plug>(fzf-maps-x)
omap <leader><tab> <plug>(fzf-maps-o)
imap <c-x><c-k> <plug>(fzf-complete-word)
imap <c-x><c-f> <plug>(fzf-complete-path)
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
imap <c-x><c-l> <plug>(fzf-complete-line)
imap <c-x><c-b> <plug>(fzf-complete-buffer-line)
" }}}
Plug 'tpope/vim-vinegar' " Util: netrw {{{
nmap _ <plug>VinegarUp
" }}}
Plug 'w0rp/ale' " Util: Code lint {{{
let g:ale_lint_on_enter = 0
let g:ale_set_highlights = 0
let g:ale_sign_column_always = 1
let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok']
let g:ale_echo_msg_format = '%linter%: %s'
let g:ale_linters = {
\ 'javascript': ['eslint', 'flow'],
\}
" }}}
Plug 'tpope/vim-abolish' " Util: Pluralize (:crl), SnakeCase <-> camel_case (:crt), Replace (Subvert), made easy
Plug 'tpope/vim-commentary' " Util: (Un)Comment made easy
Plug 'tpope/vim-dispatch' " Util: Allow asynchronous tasks to be dispatched
Plug 'tpope/vim-endwise' " Util: 'wisely' add `end` after `if` `do` etc.
Plug 'vim-scripts/bufkill.vim' " Util: Kill buffers without closing splits
Plug 'tpope/vim-afterimage' " Util: Edit (small) images
Plug 'vim-scripts/vimwiki' " Util: Nice way to take and organise notes {{{
let g:vimwiki_global_ext = 0
let g:vimwiki_list = [
\ {
\ 'syntax': 'markdown',
\ 'ext': '.md',
\ 'path': '~/vimwiki/work/'
\ },
\ {
\ 'syntax': 'markdown',
\ 'ext': '.md',
\ 'path': '~/vimwiki/play/'
\ },
\ {
\ 'syntax': 'markdown',
\ 'ext': '.md',
\ 'path': '~/vimwiki/dnd5/'
\ }
\ ]
" }}}
Plug 'tpope/vim-rbenv' " Util: rbenv.vim
Plug 'tpope/vim-surround' " Util: quoting/parenthesizing Enhancements
" Plug 'tpope/vim-ragtag' " Util: ghetto HTML/XML mappings
Plug 'tpope/vim-unimpaired' " Util: brakety Things
Plug 'tpope/vim-repeat' " Util: make things repeatable with '.'
Plug 'tpope/vim-speeddating' " Util: CTRL-A/CTRL-X to increment dates/times & more
Plug 'godlygeek/tabular' " Util: vertically aligning things (not for code)
Plug 'kana/vim-textobj-user' | Plug 'nelstrom/vim-textobj-rubyblock' " Motion: Ruby text objects
Plug 'ecomba/vim-ruby-refactoring', { 'for': 'ruby'}
Plug 'AndrewRadev/splitjoin.vim' " Util: Toggle inline/multiline {{{
let g:splitjoin_split_mapping = '<LEADER>ss'
let g:splitjoin_join_mapping = '<LEADER>sj'
" }}}
Plug 'jgdavey/vim-blockle' " Ruby: toggle {} <-> do ; end {{{
let g:blockle_mapping = '<LEADER>bl'
" }}}
Plug 'lmeijvogel/vim-yaml-helper', {'for': 'yml'}
Plug 'embear/vim-localvimrc' " Util: Allow for project specific vim settings
Plug 'kana/vim-vspec'
Plug 'ConradIrwin/vim-bracketed-paste'
Plug 'wavded/vim-stylus'
Plug 'guns/xterm-color-table.vim'
Plug 'vim-scripts/Improved-AnsiEsc'
" }}}
call plug#end()
filetype plugin indent on " Turn on _after_ loading all Plugins
runtime macros/matchit.vim
runtime! ftplugin/man.vim
if &t_Co > 2 || has('gui_running')
syntax on
endif
if &t_Co == 256 || has('gui_running')
set background=dark
colorscheme jellybeans
endif
" Cursor on a command word and let vim help you: `:help <C-R><C-W>`
set viminfo='10,f1,<100,:20,@20,/20,h,n~/.vim/.viminfo "-- Files & Directories {{{
" | | | | | | | +-> Where to save the viminfo files
" | | | | | | +-> Disable 'hlsearch' highlights on start
" | | | | | +-> # lines to save from the search history
" | | | | +-> # lines to save from the input line history
" | | | +-> # lines of command-line history
" | | +-> Save up to # lines for each register
" | +-> Global marks
" +-> marks for up to # previously edited files
" Remember things when we exit
" }}}
set directory=~/.vim/tmp " Don't clutter up dirs with swp files
set backupdir=~/.vim/tmp " nor tmp files
set history=500 " keep 500 lines of command line history
set autoread " reload files only changed outside vim from disk
set autowrite " write before :next/:cnext
set ttyfast " you got a fast terminal
set ttymouse=xterm2 " Allows colleagues to use my mouse
set mouse=a " Allows colleagues to use my mouse
set ruler " show the cursor position all the time
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set showcmd " display incomplete commands
set wmh=0 " minimum unfocussed window height
set hlsearch " highlight matches
set incsearch " incremental searching
set lazyredraw " prevent redraws while executing
set tabstop=4
set shiftwidth=2 " indent using 2 spaces
set expandtab " use spaces only
set smarttab " deindent with <BS>, start at indent level
set colorcolumn=80,119
set smartcase " ... unless they contain at least one capital letter
set scrolloff=5 " don't show search results as the first line
set laststatus=2 " Always show status line.
set smartindent
set autoindent " always set autoindenting on
set shiftround " When at 3 spaces and I hit >>, go to 4, not 5.
set gdefault " assume the /g flag on :s
set wildmenu " Better? completion on command line
set wildmode=list:longest,full " Completion settings
set tags+=.git/tags-includes " Search for ctag file in .git/
set wildignore+=tags " Don't complete from project code ctag file
set wildignore+=tags-includes " Don't complete from includes code ctag file
set winaltkeys=no " Let vim handle alt keys
set list " Create a list & make invisible chars visible
set statusline=
set statusline+=%<%.99f\ %h%m%r%y " absolute filename (max 99) & used syntax properties
set statusline+=%=\ %{SL('fugitive#statusline')} " Git branchname
set statusline+=%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"]\ \"} " encoding
set statusline+=%k\ %-12.(%l,%c%V%) " cursor position & line count
set statusline+=\ %P
if has("eval")
function! SL(function)
if exists('*'.a:function)
return call(a:function,[])
else
return ''
endif
endfunction
endif
let &fillchars = "vert: "
if (&termencoding ==# 'utf-8' || &encoding ==# 'utf-8') && version >= 700
let &listchars = "tab:\u21e5\u00b7,trail:\u2423,extends:\u21c9,precedes:\u21c7,nbsp:\u26ad"
" let &fillchars = "vert:\u259a,fold:\u00b7"
else
set listchars=tab:>\ ,trail:-,extends:>,precedes:<
endif
" set cursorline
augroup myfiletypes
" Clear old autocmds in group
autocmd!
" Ruby {{{
autocmd FileType css,sass
\ set iskeyword+=-
autocmd FileType ruby,sass,css,coffee
\ let b:switch_custom_definitions = [
\ {
\ 'have_no_\(\w\+\)': 'have_\1',
\ 'have_\(\w\+\)': 'have_no_\1',
\ },
\ ['includes', 'eager_load', 'preload'],
\ ['allow', 'expect'],
\ ['integration', 'DEBUG_integration'],
\ ['dark', 'light'],
\ ['high', 'low'],
\ ['foo', 'bar', 'baz'],
\ ['left', 'right'],
\ ['rock', 'paper', 'scissors', 'lizard', 'Spock'],
\ ]
" }}}
" autocmd FileType clojure,c,cpp,objc,objcpp call rainbow#load()
" highlights all not yet matched repeating blocks of whitespace
" autocmd FileType * highlight ExcessiveWhitespace ctermbg=red guibg=red
" autocmd FileType * 2match ExcessiveWhitespace /\S\s\s\+\S/
" Some file types use real tabs
autocmd FileType make set noexpandtab sw=4
augroup END
" Format xml files
" autocmd FileType xml exe ":silent 1,$!xmllint --format --recover - 2>/dev/null"
" Don't add the comment prefix when I hit enter or o/O on a comment line.
" autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
autocmd BufNewFile,BufRead *.txt setlocal wrap lbr
autocmd BufNewFile,BufRead *.handlebars,*.hbs set ft=html syntax=handlebars
autocmd filetype crontab setlocal nobackup nowritebackup
autocmd BufWinLeave * call clearmatches() " Fix some performance issues
" {{{ quick open some default locations
nnoremap <LEADER>bx :tabe ~/Dropbox<CR>
nnoremap <LEADER>vi :tabe ~/.dotfiles/lib/vimrc<CR>
nnoremap <LEADER>tm :tabe ~/.dotfiles/lib/tmux.conf<CR>
nnoremap <LEADER>lcd :lcd %:p:h<CR>
nnoremap <LEADER>cd :cd %:p:h<CR>
" }}}
" Use Q as alias for @j (execute 'j' recording) {{{
" This is great because you can just do something like QnQnnQ to quickly
" repeat your recording where needed. You never have to press `@` again.
nnoremap Q @j
xnoremap Q @j
" }}}
" nnoremap <LEADER>q :q<CR>
" nnoremap <LEADER>Q :qal<CR>
nnoremap <LEADER>bn :bn<CR>
nnoremap <LEADER>n :bn<CR>
" New tab/vsplit buffer {{{
nnoremap <LEADER>tn <ESC>:tabnew<CR>
" Edit another file in the same directory as the current file
" uses expression to extract path from current file's path
nmap <LEADER>te :vnew <C-R>=expand("%:p:h") . '/'<CR>
" }}}
nnoremap <LEADER>o :set paste!<CR>
nnoremap <LEADER>w :setlocal wrap!<CR>:setlocal wrap?<CR>
inoremap <C-L> :<SPACE>
noremap <C-S> <ESC>:w<CR>
inoremap <C-S> <ESC>:w<CR>
noremap <LEADER><LEADER> :w<CR>
" Emacs-like beginning and end of line. {{{
inoremap <C-E> <C-O>$
inoremap <C-A> <C-O>^
noremap H ^
noremap L $
" }}}
noremap K <NOP>
nnoremap <LEADER>F :grep! "\b<cword>\b"<CR>:cw<CR>
nnoremap <LEADER>f :set operatorfunc=<SID>GrepOperator<CR>g@
vnoremap <LEADER>f :<C-U>call <SID>GrepOperator(visualmode())<CR>
function! s:GrepOperator(type)
let saved_unnamed_register = @@
if a:type ==# 'v'
normal! `<v`>y
elseif a:type ==# 'char'
normal! `[v`]y
else
return
endif
silent execute "grep! -R " . shellescape(@@) . " ."
redraw!
copen
let @@ = saved_unnamed_register
endfunction
" Center search matches when jumping {{{
noremap N Nzz
noremap n nzz
" }}}
" Ignore 'sticky-shift' typing {{{
command! Q q " Bind :Q to :q
command! Qall qall
" }}}
" w!! - write a file using sudo _after_ starting vim {{{
cmap w!! w !sudo tee % >/dev/null
" }}}
" Merge a tab into a vsplit in the previous window {{{
function! MergeTabIntoVSplit()
if tabpagenr() == 1
return
endif
let bufferName = bufname("%")
if tabpagenr("$") == tabpagenr()
close!
else
close!
tabprev
endif
vsplit
execute "buffer " . bufferName
endfunction
nmap <C-W>u :call MergeTabIntoVSplit()<CR>
" }}}
" function! RestoreCursorPosition() " {{{
" if line("'\"") <= line("$")
" normal! g`"
" return 1
" endif
" endfunction
" augroup restoreCursorPosition
" autocmd!
" autocmd BufWinEnter * call RestoreCursorPosition()
" augroup END
" }}}
" {{{ open URL under cursor in browser
command! -nargs=1 OpenURL :call OpenURL(<q-args>)
nnoremap gb :OpenURL <cfile><CR>
nnoremap gA :OpenURL http://www.answers.com/<cword><CR>
nnoremap gG :OpenURL http://www.google.com/search?q=<cword><CR>
nnoremap gW :OpenURL http://en.wikipedia.org/wiki/Special:Search?search=<cword><CR>
function! OpenURL(url)
exec "!open \"".a:url."\""
redraw!
endfunction
" }}}
function! <SID>StripTrailingWhitespace() " {{{
" Don't strip any spaces when the filetype is markdown
if &ft =~ 'markdown'
return
endif
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
autocmd BufWritePre * :call <SID>StripTrailingWhitespace()
" }}}