Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
603 lines (478 sloc) 17.9 KB
" Root for most key bindings
let mapleader = ","
" Vundle setup
set rtp+=~/.vim/bundle/vundle/
source ~/.vim/bundle/vundle/autoload/vundle.vim
call vundle#rc()
" Allow comments after Bundle commands
command! -nargs=+ Load Bundle split(<q-args>)[0]
" Colorscheme plugins
Bundle 'altercation/vim-colors-solarized.git'
Load 'vim-scripts/molokai.git'
Load 'vim-scripts/desert256.vim.git'
Load 'tpope/vim-vividchalk.git'
Load 'vim-scripts/Wombat.git'
Load 'vim-scripts/wombat256.vim.git'
Load 'vim-scripts/Lucius.git'
" Other plugins
" Mappings for commenting
Bundle 'scrooloose/nerdcommenter.git'
" awesome syntax validation
Bundle 'scrooloose/syntastic.git'
" Undo tree
Bundle 'vim-scripts/Gundo.git'
" Expands CSS-like selectors into HTML
Bundle 'kogakure/vim-sparkup'
" Replace without losing register contents
Bundle 'vim-scripts/ReplaceWithRegister.git'
" Language syntax/highlighting/indentation
Bundle 'vim-scripts/vim-indent-object.git'
Bundle 'pangloss/vim-javascript'
Bundle 'mxw/vim-jsx'
Bundle 'vim-scripts/OOP-javascript-indentation.git'
Bundle 'vim-scripts/less.vim.git'
Bundle 'vim-scripts/Jinja.git'
Bundle 'vim-scripts/Markdown.git'
"Bundle 'elixir-lang/vim-elixir.git'
Bundle 'vim-scripts/JSON.vim.git'
Bundle 'plasticboy/vim-markdown.git'
Bundle 'ekalinin/Dockerfile.vim'
Bundle 'pearofducks/ansible-vim'
Bundle 'FooSoft/vim-argwrap'
" Repeats complex actions
Bundle 'tpope/vim-repeat.git'
" Mappings for surrounding text with stuff
Bundle 'tpope/vim-surround.git'
" Smart case subsitute with :Subvert/Pattern/Repl/
Bundle 'tpope/vim-abolish.git'
" Git wrapper
Bundle 'tpope/vim-fugitive.git'
"Load 'kana/vim-smartinput' " Auto close pairs
Load 'Raimondi/delimitMate' " Auto close pairs
let delimitMate_expand_cr=1
" Tag list plugin that uses ctags to show variables, classes, methods, etc.
"Bundle 'majutsushi/tagbar'
" Fuzzy file finder
Bundle 'kien/ctrlp.vim'
" :Narrow and :Widen commands for narrowing buffer to selection
"Bundle 'jkramer/vim-narrow'
" Rails
"Bundle 'tpope/vim-rails'
" Powerline statusline improvements
Bundle "Lokaltog/vim-powerline"
" Show Git changes in sidebar
Bundle "airblade/vim-gitgutter"
" Better completion with Tab
Bundle 'ervandew/supertab'
" Go support
Bundle 'fatih/vim-go'
" Auto-generate table-driven test structure
Bundle 'buoto/gotests-vim'
" Go Debugger (neovim-only)
if has('nvim')
let g:go_term_enabled=1
let g:godebug_breakpoints_file='/tmp/.gobreakpoints'
Bundle 'jodosha/vim-godebug'
endif
let g:go_auto_type_info = 0
let g:go_highlight_structs = 1
let g:go_autodetect_gopath = 1
let g:go_fmt_autosave = 1
let g:go_fmt_command = "goimports"
let g:go_def_reuse_buffer = 0
let g:go_def_mapping_enabled = 0
let g:go_autodetect_gopath = 0
" run current file
au FileType go nmap <leader>r <Plug>(go-run-split)
au FileType go nmap <leader>t <Plug>(go-test-func)
au FileType go nmap <silent> <leader>g :GoDecls<cr>
au FileType go nmap <silent> <leader>G :GoDeclsDir<cr>
au FileType go nmap gd <Plug>(go-def)
au FileType go nmap gD <Plug>(go-def-split)
au FileType go nmap gb <Plug>(go-def-pop)
au FileType go nmap <C-t> <Plug>(go-def-pop)
au FileType go nmap gi <Plug>(go-info)
au FileType go nmap ga <Plug>(go-alternate-edit)
au FileType go nmap gc <Plug>(go-coverage-toggle)
" Very full-featured python / rope integration
"let g:pymode_lint=0 " Disable lint since we're already using syntastic
"Bundle 'klen/python-mode'
" Quickly get out of insert mode without your fingers having to leave the
" home row (either use 'jj' or 'jk')
inoremap jj <Esc>
" Edit .vimrc in a new tab
map <Leader>V :tabe $MYVIMRC<CR>
map <Leader>v :tabe $MYVIMRC<CR>
" Use Space to open command mode
nmap <space> :
" Swap default ':', '/' and '?' with cmdline-window equivalent.
nnoremap q: q:1<c-w>_i
xnoremap q: q:1<c-w>_i
nnoremap q/ q/1<c-w>_i
xnoremap q/ q/1<c-w>_i
nnoremap q? q?1<c-w>_i
xnoremap q? q?1<c-w>_i
" Have <esc> leave cmdline-window
autocmd CmdwinEnter * nnoremap <buffer> <esc> :q<cr>
" Powerline fancy statusline
let g:Powerline_symbols = 'unicode'
set laststatus=2
let g:Powerline_cache_enabled = 0
let g:Powerline_symbols_override = { 'BRANCH': [0x2213], 'LINE': 'L' }
" Argwrap plugin activates with ,r
nnoremap <silent> <leader>r :ArgWrap<CR>
" Eye candy
if has('gui_running')
"colorscheme molokai
"colorscheme wombat
"colorscheme lucius
colorscheme fruity
set background=dark
" Customize startup size.
if !exists('g:sized_window')
"set lines=50
set columns=90
let g:sized_window=1
endif
set guifont=Inconsolata:h16
"set guifont=Droid\ Sans\ Mono:h14
set selectmode=mouse,key
" Scrollbars are for the weak-willed, use Ctrl-g instead
set guioptions=egmt
" Always show tab line to prevent resizing of window on close
set showtabline=2
" Enable scrolling, highlighting, etc. with mouse
set mouse=a
else
set t_Co=256
set background=dark
colorscheme solarized
set mouse=
endif
" Shortcuts for other color schemes
command! Light call LightColorScheme()
function! LightColorScheme()
colorscheme solarized
set background=light
endfunction
command! HighlightUnicode match Error "[^ -~]"
" Better completion in command-line
"set wildmode=longest:full " only complete longest match
set wildchar=<Tab> wildmenu wildmode=full
" [Shift]-Tab cycles tabs
map <Tab> :tabn<CR>
map <S-Tab> :tabp<CR>
map <D-Right> :tabn<CR>
map <D-Left> :tabp<CR>
" Toggle line wrap
map <Leader>W :set wrap!<CR>
" Toggle paste mode
map <Leader>pp :set paste!<CR>
" Show errors
map <Leader>e :Errors<CR>
" Toggle highlight search
map <Leader>hh :set hls!<CR>
" Toggle whitespace symbols
nmap <leader>l :set list!<CR>
" Easier way of starting substitute
map <Leader>s :s/
map <Leader>S :%s/
" Substitute word
map <Leader>ws :s/\<<C-r><C-w>\>//gc<Left><Left><Left>
map <Leader>wS :%s/\<<C-r><C-w>\>//gc<Left><Left><Left>
" Add blank line under this one
nmap <Leader><Leader> o<Esc>
" Center search results
map n nzz
map N Nzz
set noincsearch
" Tame the quickfix window (open/close using ,q)
nmap <silent> <leader>q :QFix<CR>
command! -bang -nargs=? QFix call QFixToggle(<bang>0)
function! QFixToggle(forced)
if exists("g:qfix_win") && a:forced == 0
cclose
unlet g:qfix_win
else
copen 10
let g:qfix_win = bufnr("$")
endif
endfunction
" Who needs Shift, anyway?
nnoremap ; :
" Make indenting easier since I never use < and > as operators
nmap > V><Esc>
nmap < V<<Esc>
" Run scripts with Cmd-R
map <D-r> :!./%<CR>
" Tag list
map <Leader>T :TagbarOpenAutoClose<CR>
let g:tagbar_foldlevel=0
" Syntastic options
let g:syntastic_check_on_open=0
let g:syntastic_auto_jump=0
let g:syntastic_always_populate_loc_list=1
let g:syntastic_python_checker_args='--ignore=E121,E122,E124,E201,E202,E123,E126,E127,E128,E222,E226,E231,E241,E261,E265,E266,E301,E302,E303,E401,E402,E501,E502,E701,E702,E704,E711,E712,E731,W291,W292,W293,W391,W404,W503 --max-complexity=10'
let g:syntastic_python_flake8_args='--ignore=E121,E122,E124,E201,E202,E123,E126,E127,E128,E222,E226,E231,E241,E261,E265,E266,E301,E302,E303,E401,E402,E501,E502,E701,E702,E704,E711,E712,E731,W291,W292,W293,W391,W404,W503 --max-complexity=10'
let g:syntastic_mode_map={ 'mode': 'active', 'passive_filetypes': ['html', 'django'] }
let g:syntastic_phpcs_conf="--config-set default_standard PSR2"
let g:syntastic_javascript_checkers = ['jsxhint']
let g:syntastic_elixir_checkers = ['elixir']
let g:syntastic_go_checkers = ['gofmt', 'go'] " Run gotype instead of go build to avoid lag
let g:syntastic_enable_elixir_checker = 1
"autocmd CursorHold *.go SyntasticCheck
" Disable auto-folding in markdown plugin
let g:vim_markdown_folding_disabled=1
" Avoid bug in supertab with long lines by disabling <CR> mappings
let g:SuperTabCrMapping=0
" Make Supertab adjust completion type based on preceding context
" Don't change this, it's bad ass
let g:SuperTabDefaultCompletionType = "context"
let g:SuperTabContextDefaultCompletionType = "<C-p>"
" double percentage sign in command mode is expanded
" to directory of current file - http://vimcasts.org/e/14
cnoremap %% <C-R>=expand('%:h').'/'<cr>
" Fuzzy file search in current directory
map <leader>f :<C-U>CtrlP<CR>
" Fuzzy file search in current file's directory
map <leader>F :<C-U>CtrlPCurFile<CR>
" Fuzzy file search with open buffers (excludes current open buffer)
map <Leader>b :<C-U>CtrlPBuffer<CR>
" Fuzzy file search with most recently used buffers
map <Leader>m :<C-U>CtrlPMRUFiles<CR>
" Switch to previous buffer
map <leader><Space> :b#<CR>
" Open error window
map <Leader>m :<C-U>CtrlPMRUFiles<CR>
" Ctrlp settings
let g:ctrlp_jump_to_buffer = 1
let g:ctrlp_use_caching = 1
let g:ctrlp_clear_cache_on_exit = 0
" Only look for files in git version control (overrides any custom ignore patterns)
let g:ctrlp_user_command = ['.git/', 'cd %s && git ls-files --exclude-standard -co']
set wildignore+=*/.venv/*
" Gundo
let g:gundo_help=0
let g:gundo_close_on_revert=1
" Surround mappings for Django templates
let g:surround_{char2nr("b")} = "{% block\1 \r..*\r &\1%}\r{% endblock %}"
let g:surround_{char2nr("i")} = "{% if\1 \r..*\r &\1%}\r{% endif %}"
let g:surround_{char2nr("w")} = "{% with\1 \r..*\r &\1%}\r{% endwith %}"
let g:surround_{char2nr("c")} = "{% comment %}\r{% endcomment %}"
let g:surround_{char2nr("F")} = "{% for\1 \r..*\r &\1%}\r{% endfor %}"
let g:surround_{char2nr("v")} = "{{ \r }}"
" Make command-line mimic bash-style shortcuts
cmap <C-a> <C-b>
" Stop annoying auto-indenting of comment/includes
inoremap # X<BS>#
" Crontab hijinks (prevents error when using "crontab -e")
au BufEnter /private/tmp/crontab.* setl backupcopy=yes
set backupskip=/tmp/*,/private/tmp/*
" How to keep your sanity when editing long text sentences in Vim
map j gj
map k gk
" Reselect visual block after indent/outdent
vnoremap < <gv
vnoremap > >gv
""""""""""""" Python Code """"""""""""""""""""
if has('python')
fun! s:LoadPythonShortcuts()
if exists("g:python_shortcuts_loaded")
return
endif
let g:python_shortcuts_loaded=1
python << EOF
import vim,os
# Evaluate Python code under cursor
def ExecCurrentRange():
eval(compile('\n'.join(vim.current.range),'','exec'),globals())
def EvaluateCurrentRange():
result = eval(compile('\n'.join(vim.current.range),'','eval'),globals())
vim.current.line = str(result)
# Add the virtualenv's site-packages to vim path
import vim
if os.environ.get('VIRTUAL_ENV'):
project_base_dir = os.environ['VIRTUAL_ENV']
sys.path.insert(0, project_base_dir)
activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
# Open the file referenced by an import statement
def LoadImportedFile():
source, imports = vim.current.line.split('import')
if source:
# from x.y import z
source = source.split('from ')[1].replace(' ', '')
module = __import__(source, fromlist=[''])
else:
# import x.y
module = __import__(imports.replace(' ', ''))
path = module.__file__.replace('.pyc', '.py')
# Edit file
vim.command('e %s' % path.replace(' ', '\\ '))
EOF
" Evaluate current range as python
map <C-h> :py ExecCurrentRange()<CR>
map <C-e> :py EvaluateCurrentRange()<CR>
" Load the python import on this line
command! LoadImportedFile py LoadImportedFile()
endfun
autocmd FileType python call s:LoadPythonShortcuts()
endif
""""""""""""" /Python Code """""""""""""""""""
" Really handy if you often end up doing :W by accident
command! -nargs=* W write <args>
command! -nargs=0 Q quit
" Autocommands and filetype detection
"au BufReadPost *.project bd | Project <afile>:p
au BufReadPost *.json set ft=json
au BufReadPost *.less set ft=less
au BufReadPost buildfile set ft=ruby
au BufNewFile,BufRead *.god setf ruby
au BufNewFile,BufRead *.pde setf processing
au BufNewFile,BufRead *.ino setf arduino
au BufNewFile,BufRead *.wsgi setf python
au BufNewFile,BufRead *.info,*.conf setf ini
au BufReadPost *.mu set ft=mustache
au BufReadPost Guardfile set ft=ruby
autocmd BufRead Vagrantfile set filetype=ruby
" Fix ^M signs left by shitty Windows editors
command! FixLineEndings %substitute/\r$//g
" Completion functions (set to default with Ctrl-x Ctrl-o)
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType javascript let g:SuperTabDefaultCompletionType = "<c-p>"
autocmd FileType css,less set omnifunc=csscomplete#CompleteCSS
autocmd Filetype java setlocal omnifunc=javacomplete#Complete
"autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
" Setup different indentations for filetypes
autocmd FileType ruby set shiftwidth=2 softtabstop=2 tabstop=2
autocmd FileType yaml set shiftwidth=2 softtabstop=2 tabstop=2
autocmd FileType python set shiftwidth=4 softtabstop=4 tabstop=4 textwidth=0 | match Error /\(^\|[^,]\) \+$/
autocmd FileType php set shiftwidth=4 softtabstop=4 tabstop=4 | set isk-=-
autocmd FileType javascript set shiftwidth=2 softtabstop=2 tabstop=2
autocmd FileType json set shiftwidth=2 softtabstop=2 tabstop=2
autocmd FileType perl set shiftwidth=4 softtabstop=4 tabstop=4
autocmd FileType java set shiftwidth=4 softtabstop=4 tabstop=4
autocmd FileType lua set shiftwidth=4 softtabstop=4 tabstop=4
autocmd FileType tex set shiftwidth=4 softtabstop=4 tabstop=4
autocmd FileType c,cpp set shiftwidth=4 softtabstop=4 tabstop=4
autocmd FileType sh set shiftwidth=2 softtabstop=2 tabstop=2
autocmd FileType rst,txt,markdown set textwidth=0 foldcolumn=1 wrap
autocmd FileType gitcommit set textwidth=0
autocmd FileType logstash set shiftwidth=2 softtabstop=2 tabstop=2 autoindent smartindent
autocmd FileType ini,nginx set shiftwidth=4 softtabstop=4 tabstop=4 autoindent smartindent
autocmd FileType arduino,php,html,xhtml,css,less,xml set shiftwidth=2 softtabstop=2 tabstop=2
" Jump to the last position when reopening a file
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
if exists('&autochdir')
set noautochdir
endif
" HTML re-formatting
hi! link htmlLink Normal
" Simplify saving and loading sessions
set sessionoptions=curdir,resize,tabpages,winpos,winsize,folds " No variables, screws up scripts
command! Pause mks! ~/session.vim
command! Resume so ~/session.vim
" Load indentation rules and plugins according to the detected filetype.
filetype plugin indent on
syntax on
set synmaxcol=320 " Only highlight syntax up until column 80 to avoid lag
if exists('&colorcolumn')
" Great for keeping code wrapped neatly
set colorcolumn=80
endif
" Prompt for reload after external change
set noautoread
" Assume UTF-8
if !has('nvim')
set encoding=utf8
endif
" Use tilde (alternates case) as an operator
set tildeop
" Show relative line numbers
set number
if exists('&relativenumber')
"set relativenumber
endif
" When list mode is enabled, set the replacement characters for EOL, tab, etc
set listchars=eol:$,tab:\|_,trail:_
" This allows block selection to span outside of lines
set virtualedit=block
if exists('&conceallevel')
set conceallevel=2 " Allow hiding and replacing of syntax items
set concealcursor=nc " Turn off conceal when in insert or visual mode
endif
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
set smartcase " Do smart case matching
set hidden " Hide buffers when they are abandoned
set textwidth=0
set visualbell
" These options interact together in some mysterious way to give four tab spacing
set softtabstop=4
set expandtab
set shiftwidth=4
set tabstop=4
set nosmartindent
set nocindent
set autoindent
set nobackup
set showcmd
set noswapfile
set viminfo+=h
set nocp
set switchbuf=useopen,usetab
" Folding - Do it by one indent level, but off by default
set foldmethod=manual
set nofoldenable
set foldnestmax=1
" Do not automatically insert a comment leader after an enter
au FileType * setlocal formatoptions-=r
" Auto syntax folding for javascript by braces
au FileType javascript setlocal foldmethod=marker
au FileType javascript setlocal foldmarker={,}
" Disable wrapping by default
set nowrap
set linebreak
set display=lastline " show partial lines when wrapping
" Way better than Vim's crazy default backspace setting
set bs=indent,eol,start
set laststatus=2
set history=500
set completeopt=menu,menuone
set dictionary+=/usr/share/dict/words " Enable completion of dictionary words
set fillchars=vert:.,fold:~
" Split windows open above and to the right
set splitright
set nosplitbelow
" No backups for temp files
set backupskip=/tmp/*,/private/tmp/*"
" Make - and _ part of a word for text objects
set iskeyword+=-
set iskeyword+=_
" :Loremipsum plugin is more effective, but doing this is just hilarious
iab lorem Lorem ipsum dolor sit amet, consectetur adipiscing elit
iab llorem Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam lacus ligula, accumsan id imperdiet rhoncus, dapibus vitae arcu. Nulla non quam erat, luctus consequat nisi
iab lllorem Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam lacus ligula, accumsan id imperdiet rhoncus, dapibus vitae arcu. Nulla non quam erat, luctus consequat nisi. Integer hendrerit lacus sagittis erat fermentum tincidunt. Cras vel dui neque. In sagittis commodo luctus. Mauris non metus dolor, ut suscipit dui. Aliquam mauris lacus, laoreet et consequat quis, bibendum id ipsum. Donec gravida, diam id imperdiet cursus, nunc nisl bibendum sapien, eget tempor neque elit in tortor
" Simple re-format for minified Javascript
command! UnMinify call UnMinify()
function! UnMinify()
%s/{\ze[^\r\n]/{\r/g
%s/){/) {/g
%s/};\?\ze[^\r\n]/\0\r/g
%s/;\ze[^\r\n]/;\r/g
%s/[^\s]\zs[=&|]\+\ze[^\s]/ \0 /g
normal ggVG=
endfunction
" auto-chmod for scripts
au FileChangedShell * let v:fcs_choice = (v:fcs_reason == "mode") ? "" : "ask"
autocmd BufWritePost * call NoExtNewFile()
function! NoExtNewFile()
if getline(1) =~ "^#!.*/bin/" && match(getfperm(bufname('%')), 'x') == -1
if &filetype == ""
filetype detect
endif
silent !chmod a+x <afile>
endif
endfunction