" Author: Josh Davis " Description: This is the personal .vimrc file of Josh Davis. I've tried to " document every option and item. Feel free to use it to learn " more about configuring Vim. " " Also, I encourage you to pick out the parts that you use and " understand rather than blindly using it. " " You can find me on Github: http://github.com/jdavis Or my " personal site: http://joshldavis.com " As the help says 'Make vim behave in a more useful way' " **Must be first uncommented line** set nocompatible " " Determine what we have " let s:OS = 'linux' let os = substitute(system('uname'), '\n', '', '') if os == 'Darwin' || os == 'Mac' let s:OS = 'osx' endif let s:plugins=isdirectory(expand('~/.vim/bundle/vundle', 1)) " " Setup folder structure " if !isdirectory(expand('~/.vim/undo/', 1)) silent call mkdir(expand('~/.vim/undo', 1), 'p') endif if !isdirectory(expand('~/.vim/backup/', 1)) silent call mkdir(expand('~/.vim/backup', 1), 'p') endif if !isdirectory(expand('~/.vim/swap/', 1)) silent call mkdir(expand('~/.vim/swap', 1), 'p') endif " " Custom Functions " " Remove trailing whitespace " http://vim.wikia.com/wiki/Remove_unwanted_spaces function! StripTrailingWhitespace() if !&binary && &filetype != 'diff' normal mz normal Hmy %s/\s\+$//e normal 'yz normal `z retab endif endfunction " Function to hide all the text except for the text selected in visual mode. " This is great for highlighting parts of the code. Just call the function " again to deselect everything. function! ToggleSelected(visual) range highlight HideSelected ctermfg=bg ctermbg=bg \ guifg=bg guibg=bg gui=none term=none cterm=none if exists('g:toggle_selected_hide') call matchdelete(g:toggle_selected_hide) unlet g:toggle_selected_hide redraw if !a:visual return endif endif let [lnum1, col1] = getpos(''<')[1:2] let [lnum2, col2] = getpos(''>')[1:2] let pattern = '\%^\|\%<'.lnum1.'l\|\%<'.col1.'v\|\%>'.lnum2.'l\|\%>'.col2.'v' let g:toggle_selected_hide = matchadd('HideSelected', pattern, 1000) redraw endfunction " Check if a colorscheme exists " http://stackoverflow.com/a/5703164 function! HasColorScheme(scheme) let basepath = '~/.vim/bundle/' for plug in g:color_schemes let path = basepath . '/' . plug . '/colors/' . a:scheme . '.vim' if filereadable(expand(path)) return 1 endif endfor return 0 endfunction " " Global Settings " " The default 20 isn't nearly enough set history=9999 " Show the numbers on the left of the screen set number " Show the column/row set ruler " Highlight only the lines that go past 80 characters highlight ColorColumn ctermbg=green guibg=green call matchadd('ColorColumn', '\%82v', 100) " Pretty colors are fun, yayyy syntax on " Show the matching when doing a search set showmatch " Allows the backspace to delete indenting, end of lines, and over the start " of insert set backspace=indent,eol,start " Ignore case when doing a search as well as highlight it as it is typed set ignorecase smartcase set hlsearch set incsearch " Don't show the startup message set shortmess=I " Show the current command at the bottom set showcmd " Disable beeping and flashing. set noerrorbells visualbell t_vb= autocmd GUIEnter * set visualbell t_vb= " Use smarter defaults set smartindent set smarttab " Use autoindenting set autoindent " The tabstop look best at 4 spacing set tabstop=4 set softtabstop=4 set shiftwidth=4 " I have been converted to the dark side, I will use spaces to indent code " from here on out set expandtab " Buffer Settings set hidden " Turn on persistent undo " Thanks, Mr Wadsten: github.com/mikewadsten/dotfiles/ if has('persistent_undo') set undodir=~/.vim/undo// set undofile set undolevels=1000 set undoreload=10000 endif " Use backups " Source: " http://stackoverflow.com/a/15317146 set backup set writebackup set backupdir=~/.vim/backup// " Use a specified swap folder " Source: " http://stackoverflow.com/a/15317146 set directory=~/.vim/swap// " The comma makes a great leader of men, heh heh let mapleader = ',' let maplocalleader = '\' " Show two lines for the status line set laststatus=2 " Always show the last line set display+=lastline " UTF-8 THIS SHITTTTTT set encoding=utf-8 " Enhanced mode for command-line completion set wildmenu " Automatically re-read the file if it has changed set autoread " Fold Settings " Off on start set nofoldenable " Indent seems to work the best set foldmethod=indent set foldlevel=20 " " Global Bindings " " Disable ex mode, ick, remap it to Q instead. " " Tip: " Use command-line-window with q: " Use search history with q/ " " More info: " http://blog.sanctum.geek.nz/vim-command-window/ nmap Q q " Show only selected in Visual Mode nmap th :cal ToggleSelected(0) vmap th :cal ToggleSelected(1) " Split the window using some nice shortcuts nmap s :vsplit nmap s- :split " Unhighlight the last search pattern on Enter nn :nohlsearch " Remove trailing whitespace nmap tW :cal StripTrailingWhitespace() " Control enhancements in insert mode imap imap imap vBc imap imap " When pushing j/k on a line that is wrapped, it navigates to the same line, " just to the expected location rather than to the next line nnoremap j gj nnoremap k gk " Arrow key users won't survive in this environment map map map map " Map Ctrl+V to paste in Insert mode imap * " Map Ctrl+C to copy in Visual mode vmap "+y " Add paste shortcut nmap P "+p " GVim Settings if has('gui_running') " Who uses a GUI in GVim anyways? Let's be serious. set guioptions=egirLt " Ensure that clipboard isn't clobbered when yanking set guioptions-=a " Let's make the fonts look nice if s:OS == 'osx' set guifont=Droid\ Sans\ Mono\ for\ Powerline:h11 elseif s:OS == 'linux' set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ 9 endif endif " Ignore some defaults set wildignore=*.o,*.obj,*~,*.pyc set wildignore+=.env set wildignore+=.env[0-9]+ set wildignore+=.git,.gitkeep set wildignore+=.tmp set wildignore+=.coverage set wildignore+=*DS_Store* set wildignore+=.sass-cache/ set wildignore+=__pycache__/ set wildignore+=vendor/rails/** set wildignore+=vendor/cache/** set wildignore+=*.gem set wildignore+=log/** set wildignore+=tmp/** set wildignore+=.tox/** set wildignore+=.idea/** set wildignore+=*.egg,*.egg-info set wildignore+=*.png,*.jpg,*.gif set wildignore+=*.so,*.swp,*.zip,*/.Trash/**,*.pdf,*.dmg,*/Library/**,*/.rbenv/** set wildignore+=*/.nx/**,*.app " Fold Keybindings "nnoremap za " " Custom Settings " " Set on textwidth when in markdown files autocmd FileType markdown set textwidth=80 " Smarter completion in C autocmd FileType c set omnifunc=ccomplete#Complete " My own special flavoring to running programs autocmd FileType asm,c,objc,scheme,sh,python,perl,javascript nn R :!~/Scripts/deepThought.sh '%:p' " Use 2 spaces when in Lua & Ruby autocmd FileType lua,ruby set tabstop=2 autocmd FileType lua,ruby set shiftwidth=2 if !s:plugins " Bootstrap Vundle on new systems " Borrowed from @justinmk's vimrc fun! InstallVundle() silent call mkdir(expand('~/.vim/bundle', 1), 'p') silent !git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle endfun " Instead of install packages, install Vundle nmap vi :call InstallVundle() else " Required by Vundle filetype off " Vundle is the new god among plugins set rtp+=~/.vim/bundle/vundle/ call vundle#rc() " " Vundle Bundles + Settings " Plugin 'gmarik/vundle' Plugin 'tpope/vim-git' Plugin 'airblade/vim-gitgutter' Plugin 'tpope/vim-fugitive' Plugin 'scrooloose/syntastic' Plugin 'Shougo/unite.vim' Plugin 'Shougo/vimfiler.vim' Plugin 'kien/ctrlp.vim' Plugin 'tpope/vim-surround' Plugin 'bling/vim-airline' Plugin 'pangloss/vim-javascript' Plugin 'kchmck/vim-coffee-script' Plugin 'groenewege/vim-less' Plugin 'tpope/vim-markdown' Plugin 'wting/rust.vim' Plugin 'wavded/vim-stylus' Plugin 'bitc/vim-bad-whitespace' Plugin 'mattn/webapi-vim' Plugin 'mattn/gist-vim' Plugin 'Lokaltog/vim-easymotion' Plugin 'takac/vim-commandcaps' Plugin 'majutsushi/tagbar' Plugin 'mileszs/ack.vim' Plugin 'mbbill/undotree' Plugin 'wlangstroth/vim-racket' Plugin 'terryma/vim-multiple-cursors' Plugin 'benmills/vimux' Plugin 'vim-scripts/SyntaxRange' Plugin 'jalvesaq/VimCom' Plugin 'jcfaria/Vim-R-plugin' Plugin 'derekwyatt/vim-scala' Plugin 'LaTeX-Box-Team/LaTeX-Box' Plugin 'SirVer/ultisnips' Plugin 'honza/vim-snippets' Plugin 'leafo/moonscript-vim' Plugin 'jeetsukumaran/vim-buffergator' "Plugin 'Valloric/YouCompleteMe' Plugin 'tpope/vim-speeddating' Plugin 'tpope/vim-repeat' Plugin 'tpope/vim-endwise' Plugin 'ryanss/vim-hackernews' " Themes Plugin 'freeo/vim-kalisi' Plugin 'flazz/vim-colorschemes' let g:color_schemes = ['vim-kalisi', 'vim-colorschemes'] " Vundle mapping nmap vl :BundleList nmap vi :BundleInstall nmap vI :BundleInstall! nmap vc :BundleClean nmap vC :BundleClean! " Fugitive mapping nmap gb :Gblame nmap gc :Gcommit nmap gd :Gdiff nmap gg :Ggrep nmap gl :Glog nmap gp :Git pull nmap gP :Git push nmap gs :Gstatus nmap gw :Gbrowse " VimFiler options let g:vimfiler_as_default_explorer = 1 let g:vimfiler_ignore_pattern = '^\%(\.git\|\.DS_Store\|\.class\|\.aux\|\.sw[po]\|\.py[co]\)$' autocmd BufEnter * if (winnr('$') == 1 && &filetype ==# 'vimfiler') | q | endif call vimfiler#custom#profile('default', 'context', { \ 'explorer' : 1, \ 'safe' : 0, \ }) " VimFiler keybindings nmap tb :VimFilerExplorer nmap tB :VimFiler " Automatically open VimFiler whenever opened with GUI, but not terminal if has('gui_running') autocmd VimEnter * VimFilerExplorer "autocmd VimEnter * wincmd p endif " Syntastic Settings let g:syntastic_always_populate_loc_list=1 let g:syntastic_error_symbol = '✗' let g:syntastic_warning_symbol = '⚠' let g:syntastic_auto_loc_list = 2 let g:syntastic_enable_signs = 1 let g:syntastic_java_checkers = ['checkstyle', 'javac'] let g:syntastic_java_javac_delete_output = 1 let g:syntastic_java_checkstyle_conf_file = '~/bin/jars/sun_checks.xml' let g:syntastic_java_checkstyle_classpath = '~/bin/jars/checkstyle-5.5-all.jar' let g:syntastic_filetype_map = { 'rnoweb': 'tex'} " CtrlP Settings let g:ctrlp_user_command = { \ 'types': { \ 1: ['.git', 'cd %s && git ls-files --exclude-standard --others --cached'], \ 2: ['.hg', 'hg --cwd %s locate -I .'], \ }, \ 'fallback': 'find %s -type f' \ } " Use nearest .git dir let g:ctrlp_working_path_mode = 'r' nmap p :CtrlP " Buffer controls to go with Buffergator nmap bb :CtrlPBuffer nmap bm :CtrlPMixed nmap bs :CtrlPMRU " Airline options let g:airline_enable_branch = 1 let g:airline_enable_syntastic = 1 let g:airline_powerline_fonts = 1 let g:airline_theme = 'kalisi' " Whitespace settings " Show trailing whitespace and tabs obnoxiously set list listchars=tab:▸\ ,trail:. set list fun! ToggleWhitespace() ToggleBadWhitespace if &list set nolist else set list listchars=tab:▸\ ,trail:. set list endif endfun nmap tw :cal ToggleWhitespace() " Easymotion map (easymotion-prefix) let g:EasyMotion_smartcase = 1 map h (easymotion-lineforward) map j (easymotion-j) map k (easymotion-k) map l (easymotion-linebackward) let g:EasyMotion_startofline = 0 " Tagbar Options " Toggle Tagbar nmap tt :TagbarToggle let g:tagbar_left = 0 let g:tagbar_width = 30 let g:ackpreview = 2 "let g:ack_autoclose = 1 let g:ackhighlight = 1 nmap / :Ack! " Undotree settings nmap tu :UndotreeToggle let g:undotree_SplitWidth = 30 let g:undotree_WindowLayout = 3 " Multiple Cursors Settings let g:multi_cursor_use_default_mapping = 0 let g:multi_cursor_next_key = '' let g:multi_cursor_prev_key = '' let g:multi_cursor_skip_key = '' let g:multi_cursor_quit_key = '' " Worthless mapping let g:vimrplugin_assign = 0 " Disable ridiculous mappings let g:vimrplugin_insert_mode_cmds = 0 " The powers of Gitignore + wildignore combine! " Originally written by @zdwolfe, updated by @mikewadsten "Bundle 'mikewadsten/vim-gitwildignore' " LaTex-Box Settings let g:LatexBox_latexmk_async = 1 let g:LatexBox_latexmk_preview_continuously = 1 let g:LatexBox_viewer = 'open -a Skim.app' let g:LatexBox_viewer = 'mate-open' nmap U :call UltiSnips#ListSnippets() " Complete UltiSnip snippets with function! g:UltiSnips_Complete() call UltiSnips#ExpandSnippet() if g:ulti_expand_res == 0 if pumvisible() return "\" else call UltiSnips#JumpForwards() if g:ulti_jump_forwards_res == 0 return "\" endif endif endif return '' endfunction au InsertEnter * exec 'inoremap ' . g:UltiSnipsExpandTrigger . ' =g:UltiSnips_Complete()' let g:UltiSnipsExpandTrigger = '' let g:UltiSnipsJumpForwardTrigger = '' let g:UltiSnipsJumpBackwardTrigger = '' " " Buffergator Options " " I want my own keymappings... let g:buffergator_suppress_keymaps = 1 " Looper! "let g:buffergator_mru_cycle_loop = 1 nmap T :enew nmap jj :BuffergatorMruCyclePrev nmap kk :BuffergatorMruCycleNext nmap bq :bp bd # " Use extra conf file let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py' " Ignore certain filetypes let g:ycm_filetype_blacklist = { \ 'tagbar': 1, \ 'qf': 1, \ 'notes': 1, \ 'markdown': 1, \ 'unite': 1, \ 'text': 1, \ 'vimwiki': 1, \ 'pandoc': 1, \ 'infolog': 1, \ 'mail': 1, \ 'gitcommit': 1, \} " " CScope bindings " " Cheat Sheet: " " 's' symbol: find all references to the token under cursor " 'g' global: find global definition(s) of the token under cursor " 'c' calls: find all calls to the function name under cursor " 't' text: find all instances of the text under cursor " 'e' egrep: egrep search for the word under cursor " 'f' file: open the filename under cursor " 'i' includes: find files that include the filename under cursor " 'd' called: find functions that function under cursor calls if has("cscope") " use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t' set cscopetag " check cscope for definition of a symbol before checking ctags: set to 1 " if you want the reverse search order. set csto=0 " add any cscope database in current directory if filereadable("cscope.out") cs add cscope.out " else add the database pointed to by environment variable elseif $CSCOPE_DB != "" cs add $CSCOPE_DB endif " show msg when any other cscope db added set cscopeverbose nmap s :cs find s =expand("") nmap g :cs find g =expand("") nmap c :cs find c =expand("") nmap t :cs find t =expand("") nmap e :cs find e =expand("") nmap f :cs find f =expand("") nmap i :cs find i ^=expand("")$ nmap d :cs find d =expand("") endif " " Vimux Settings " if has('gui_running') let g:VimuxUseNearest = 1 let g:VimuxRunnerType = 'window' else let g:VimuxUseNearest = 0 let g:VimuxRunnerType = 'pane' endif let g:VimuxPromptString = 'tmux > ' function! VimuxSetupRacket() call VimuxRunCommand('racket -il readline') call VimuxClearRunnerHistory() endfunction function! VimuxQuitRacket() call VimuxInterruptRunner() call VimuxCloseRunner() endfunction function! VimuxRunSelection() range let [lnum1, col1] = getpos(''<')[1:2] let [lnum2, col2] = getpos(''>')[1:2] let lines = getline(lnum1, lnum2) let lines[-1] = lines[-1][: col2 - 1] let lines[0] = lines[0][col1 - 1:] call VimuxRunCommand(join(lines, "\n")) endfunction function! VimuxRunLine() call VimuxRunCommand(getline('.')) endfunction function! VimuxRunParagraph() let [lnum1] = getpos("'{")[1:1] let [lnum2] = getpos("'}")[1:1] let lines = getline(lnum1, lnum2) let filtered = filter(lines, 'v:val !~ "^\s*;"') call VimuxRunCommand(join(filtered, '')) endfunction " Setup autocmd if Racket filetype autocmd FileType racket call SetupVimuxRacket() function! SetupVimuxRacket() set shiftwidth=2 " Start interpretter nmap ri :call VimuxSetupRacket() nmap rq :call VimuxQuitRacket() nmap rl :call VimuxRunLine() nmap R :call VimuxRunParagraph() nmap rp :call VimuxRunParagraph() vmap R :call VimuxRunSelection() endfunction " End the conditional for plugins endif " Load plugins and indent for the filtype " **Must be last for Vundle** filetype plugin indent on " " Misc/Non Plugin Settings " " Paste toggle to something easy set pastetoggle=tP " Bind :sort to something easy, don't press enter, allow for options (eg -u, " n, sorting in reverse [sort!]) vnoremap s :sort " Let's make it pretty set background=dark set t_Co=256 set t_AB=[48;5;%dm set t_AF=[38;5;%dm " Must be loaded after all color scheme plugins if HasColorScheme('kalisi') && s:plugins colorscheme kalisi endif