" " Derek Wyatt's Vim Configuration " " It's got stuff in it. " "----------------------------------------------------------------------------- " Global Stuff "----------------------------------------------------------------------------- function! RunningInsideGit() let result = system('env | grep ^GIT_') if result == "" return 0 else return 1 endif endfunction " Get Vundle up and running set nocompatible filetype off set runtimepath+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'bling/vim-airline' Plugin 'derekwyatt/ag.vim' Plugin 'bufkill.vim' Plugin 'MarcWeber/vim-addon-completion' Plugin 'kien/ctrlp.vim' Plugin 'DfrankUtil' Plugin 'EasyMotion' Plugin 'derekwyatt/vim-fswitch' Plugin 'tpope/vim-fugitive' Plugin 'endel/vim-github-colorscheme' Plugin 'vim-scripts/gnupg.vim' Plugin 'sjl/gundo.vim' Plugin 'laurentgoudet/vim-howdoi' Plugin 'noahfrederick/vim-hemisu' Plugin 'nanotech/jellybeans.vim' Plugin 'elzr/vim-json' Plugin 'scrooloose/nerdtree' Plugin 'derekwyatt/vim-npl' Plugin 'derekwyatt/vim-protodef' Plugin 'derekwyatt/vim-sbt' Plugin 'derekwyatt/vim-scala' Plugin 'altercation/vim-colors-solarized' Plugin 'tpope/vim-surround' Plugin 'godlygeek/tabular' Plugin 'vim-scripts/TwitVim' Plugin 'tpope/vim-unimpaired' Plugin 'vimprj' Plugin 'VisIncr' Plugin 'drmingdrmer/xptemplate' Plugin 'GEverding/vim-hocon' if !RunningInsideGit() Plugin 'indexer.tar.gz' endif call vundle#end() filetype plugin indent on " Add xptemplate global personal directory value if has("unix") set runtimepath+=~/.vim/xpt-personal endif " Set filetype stuff to on filetype on filetype plugin on filetype indent on " Tabstops are 4 spaces set tabstop=2 set shiftwidth=2 set softtabstop=2 set expandtab set autoindent " Printing options set printoptions=header:0,duplex:long,paper:letter " set the search scan to wrap lines set wrapscan " I'm happy to type the case of things. I tried the ignorecase, smartcase " thing but it just wasn't working out for me set noignorecase " set the forward slash to be the slash of note. Backslashes suck set shellslash if has("unix") set shell=bash else set shell=ksh.exe endif " Make command line two lines high set ch=2 " set visual bell -- i hate that damned beeping set vb " Allow backspacing over indent, eol, and the start of an insert set backspace=2 " Make sure that unsaved buffers that are to be put in the background are " allowed to go in there (ie. the "must save first" error doesn't come up) set hidden " Make the 'cw' and like commands put a $ at the end instead of just deleting " the text and replacing it set cpoptions=ces$ function! DerekFugitiveStatusLine() let status = fugitive#statusline() let trimmed = substitute(status, '\[Git(\(.*\))\]', '\1', '') let trimmed = substitute(trimmed, '\(\w\)\w\+\ze/', '\1', '') let trimmed = substitute(trimmed, '/[^_]*\zs_.*', '', '') if len(trimmed) == 0 return "" else return '(' . trimmed[0:10] . ')' endif endfunction " Set the status line the way i like it set stl=%f\ %m\ %r%{DerekFugitiveStatusLine()}\ Line:%l/%L[%p%%]\ Col:%v\ Buf:#%n\ [%b][0x%B] " tell VIM to always put a status line in, even if there is only one window set laststatus=2 " Don't update the display while executing macros set lazyredraw " Don't show the current command in the lower right corner. In OSX, if this is " set and lazyredraw is set then it's slow as molasses, so we unset this set showcmd " Show the current mode set showmode " Switch on syntax highlighting. syntax on " Hide the mouse pointer while typing set mousehide " Set up the gui cursor to look nice set guicursor=n-v-c:block-Cursor-blinkon0,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor,r-cr:hor20-Cursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175 " set the gui options the way I like set guioptions=acg " Setting this below makes it sow that error messages don't disappear after one second on startup. "set debug=msg " This is the timeout used while waiting for user input on a multi-keyed macro " or while just sitting and waiting for another key to be pressed measured " in milliseconds. " " i.e. for the ",d" command, there is a "timeoutlen" wait period between the " "," key and the "d" key. If the "d" key isn't pressed before the " timeout expires, one of two things happens: The "," command is executed " if there is one (which there isn't) or the command aborts. set timeoutlen=500 " Keep some stuff in the history set history=100 " These commands open folds set foldopen=block,insert,jump,mark,percent,quickfix,search,tag,undo " When the page starts to scroll, keep the cursor 8 lines from the top and 8 " lines from the bottom set scrolloff=8 " Allow the cursor to go in to "invalid" places set virtualedit=all " Disable encryption (:X) set key= " Make the command-line completion better set wildmenu " Same as default except that I remove the 'u' option set complete=.,w,b,t " When completing by tag, show the whole tag, not just the function name set showfulltag " Set the textwidth to be 80 chars set textwidth=80 " get rid of the silly characters in separators set fillchars = "" " Add ignorance of whitespace to diff set diffopt+=iwhite " Enable search highlighting set hlsearch " Incrementally match the search set incsearch " Add the unnamed register to the clipboard set clipboard+=unnamed " Automatically read a file that has changed on disk set autoread set grepprg=grep\ -nH\ $* " Trying out the line numbering thing... never liked it, but that doesn't mean " I shouldn't give it another go :) set relativenumber " Types of files to ignore when autocompleting things set wildignore+=*.o,*.class,*.git,*.svn " Various characters are "wider" than normal fixed width characters, but the " default setting of ambiwidth (single) squeezes them into "normal" width, which " sucks. Setting it to double makes it awesome. set ambiwidth=double " OK, so I'm gonna remove the VIM safety net for a while and see if kicks my ass set nobackup set nowritebackup set noswapfile " dictionary for english words " I don't actually use this much at all and it makes my life difficult in general "set dictionary=$VIM/words.txt " Let the syntax highlighting for Java files allow cpp keywords let java_allow_cpp_keywords = 1 " I don't want to have the default keymappings for my scala plugin evaluated let g:scala_use_default_keymappings = 0 " System default for mappings is now the "," character let mapleader = "," " Wipe out all buffers nmap ,wa :1,9000bwipeout " Toggle paste mode nmap ,p :set invpaste:set paste? " cd to the directory containing the file in the buffer nmap ,cd :lcd %:h nmap ,cr :lcd =FindGitDirOrRoot() nmap ,md :!mkdir -p %:p:h " Turn off that stupid highlight search nmap ,n :nohls " put the vim directives for my file editing settings in nmap ,vi ovim:set ts=2 sts=2 sw=2:vim600:fdm=marker fdl=1 fdc=0: " The following beast is something i didn't write... it will return the " syntax highlighting group that the current "thing" under the cursor " belongs to -- very useful for figuring out what to change as far as " syntax highlighting goes. nmap ,qq :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" " Make shift-insert work like in Xterm map map! " set text wrapping toggles nmap ,ww :set invwrap nmap ,wW :windo set invwrap " allow command line editing like emacs cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap b cnoremap cnoremap f cnoremap cnoremap " Maps to make handling windows a bit easier "noremap ,h :wincmd h "noremap ,j :wincmd j "noremap ,k :wincmd k "noremap ,l :wincmd l "noremap ,sb :wincmd p noremap :vertical resize -10 noremap :resize +10 noremap :resize -10 noremap :vertical resize +10 noremap ,s8 :vertical resize 83 noremap ,cj :wincmd j:close noremap ,ck :wincmd k:close noremap ,ch :wincmd h:close noremap ,cl :wincmd l:close noremap ,cc :close noremap ,cw :cclose noremap ,ml L noremap ,mk K noremap ,mh H noremap ,mj J noremap > noremap + noremap + noremap > " Edit the vimrc file nmap ,ev :e $MYVIMRC nmap ,sv :so $MYVIMRC " Make horizontal scrolling easier nmap 10zl nmap 10zh " Add a GUID to the current line imap d =substitute(system("uuidgen"), '.$', '', 'g') " Toggle fullscreen mode nmap :call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0) " Underline the current line with '=' nmap ,u= :t.\|s/./=/g\|:nohls nmap ,u- :t.\|s/./-/g\|:nohls nmap ,u~ :t.\|s/./\\~/g\|:nohls " Shrink the current window to fit the number of lines in the buffer. Useful " for those buffers that are only a few lines nmap ,sw :execute ":resize " . line('$') " Use the bufkill plugin to eliminate a buffer but keep the window layout nmap ,bd :BD " Use CTRL-E to replace the original ',' mapping nnoremap , " Alright... let's try this out imap jj cmap jj " I like jj - Let's try something else fun imap ,fn =expand('%:t:r') " Clear the text using a motion / text object and then move the character to the " next word nmap ,C :set opfunc=ClearTextg@ vmap ,C :call ClearText(visual(), 1) " Make the current file executable nmap ,x :w:!chmod 755 %:e " Digraphs " Alpha imap a* " Beta imap b* " Gamma imap g* " Delta imap d* " Epslion imap e* " Lambda imap l* " Eta imap y* " Theta imap h* " Mu imap m* " Rho imap r* " Pi imap p* " Phi imap f* function! ClearText(type, ...) let sel_save = &selection let &selection = "inclusive" let reg_save = @@ if a:0 " Invoked from Visual mode, use '< and '> marks silent exe "normal! '<" . a:type . "'>r w" elseif a:type == 'line' silent exe "normal! '[V']r w" elseif a:type == 'line' silent exe "normal! '[V']r w" elseif a:type == 'block' silent exe "normal! `[\`]r w" else silent exe "normal! `[v`]r w" endif let &selection = sel_save let @@ = reg_save endfunction " Syntax coloring lines that are too long just slows down the world set synmaxcol=2048 " I don't like it when the matching parens are automatically highlighted let loaded_matchparen = 1 " Highlight the current line and column " Don't do this - It makes window redraws painfully slow set nocursorline set nocursorcolumn if has("mac") let g:main_font = "Anonymous\\ Pro:h11" let g:small_font = "Anonymous\\ Pro:h2" else let g:main_font = "DejaVu\\ Sans\\ Mono\\ 9" let g:small_font = "DejaVu\\ Sans\\ Mono\\ 2" endif "----------------------------------------------------------------------------- " Fugitive "----------------------------------------------------------------------------- " Thanks to Drew Neil autocmd User fugitive \ if fugitive#buffer().type() =~# '^\%(tree\|blob\)$' | \ noremap .. :edit %:h | \ endif autocmd BufReadPost fugitive://* set bufhidden=delete nmap ,gs :Gstatus nmap ,ge :Gedit nmap ,gw :Gwrite nmap ,gr :Gread "----------------------------------------------------------------------------- " NERD Tree Plugin Settings "----------------------------------------------------------------------------- " Toggle the NERD Tree on an off with F7 nmap :NERDTreeToggle " Close the NERD Tree with Shift-F7 nmap :NERDTreeClose " Show the bookmarks table on startup let NERDTreeShowBookmarks=1 " Don't display these kinds of files let NERDTreeIgnore=[ '\.ncb$', '\.suo$', '\.vcproj\.RIMNET', '\.obj$', \ '\.ilk$', '^BuildLog.htm$', '\.pdb$', '\.idb$', \ '\.embed\.manifest$', '\.embed\.manifest.res$', \ '\.intermediate\.manifest$', '^mt.dep$' ] "----------------------------------------------------------------------------- " GPG Stuff "----------------------------------------------------------------------------- if has("mac") let g:GPGExecutable = "gpg2" let g:GPGUseAgent = 0 endif "----------------------------------------------------------------------------- " AG (SilverSearcher) Settings "----------------------------------------------------------------------------- nmap ,sf :AgForCurrentFileDir nmap ,sr :AgForProjectRoot nmap ,se :AgForExtension let g:ag_results_mapping_replacements = { \ 'open_and_close': '', \ 'open': 'o', \ } "----------------------------------------------------------------------------- " FSwitch mappings "----------------------------------------------------------------------------- nmap ,of :FSHere nmap ,ol :FSRight nmap ,oL :FSSplitRight nmap ,oh :FSLeft nmap ,oH :FSSplitLeft nmap ,ok :FSAbove nmap ,oK :FSSplitAbove nmap ,oj :FSBelow nmap ,oJ :FSSplitBelow "----------------------------------------------------------------------------- " XPTemplate settings "----------------------------------------------------------------------------- let g:xptemplate_brace_complete = '' "----------------------------------------------------------------------------- " TwitVim settings "----------------------------------------------------------------------------- let twitvim_enable_perl = 1 let twitvim_browser_cmd = 'firefox' nmap ,tw :FriendsTwitter nmap ,tm :UserTwitter nmap ,tM :MentionsTwitter function! TwitVimMappings() nmap U :exe ":UnfollowTwitter " . expand("") nmap F :exe ":FollowTwitter " . expand("") nmap 7 :BackTwitter nmap 8 :ForwardTwitter nmap 1 :PreviousTwitter nmap 2 :NextTwitter endfunction augroup derek_twitvim au! au FileType twitvim call TwitVimMappings() augroup END "----------------------------------------------------------------------------- " VimSokoban settings "----------------------------------------------------------------------------- " Sokoban stuff let g:SokobanLevelDirectory = "/home/dwyatt/.vim/bundle/vim-sokoban/VimSokoban/" "----------------------------------------------------------------------------- " FuzzyFinder Settings "----------------------------------------------------------------------------- let g:fuf_splitPathMatching = 1 let g:fuf_maxMenuWidth = 110 let g:fuf_timeFormat = '' nmap ,fv :FufFile ~/.vim/ nmap ,fc :FufMruCmd nmap ,fm :FufMruFile let g:CommandTMatchWindowAtTop = 1 let g:make_scala_fuf_mappings = 0 "----------------------------------------------------------------------------- " CtrlP Settings "----------------------------------------------------------------------------- let g:ctrlp_switch_buffer = 'E' let g:ctrlp_tabpage_position = 'c' let g:ctrlp_working_path_mode = 'rc' let g:ctrlp_root_markers = ['.project.root'] let g:ctrlp_custom_ignore = '\v%(/\.%(git|hg|svn)|\.%(class|o|png|jpg|jpeg|bmp|tar|jar|tgz|deb|zip)$|/target/%(quickfix|resolution-cache|streams)|/target/scala-2.10/%(classes|test-classes|sbt-0.13|cache)|/project/target|/project/project)' let g:ctrlp_open_new_file = 'r' let g:ctrlp_open_multiple_files = '1ri' let g:ctrlp_match_window = 'max:40' let g:ctrlp_prompt_mappings = { \ 'PrtSelectMove("j")': [''], \ 'PrtSelectMove("k")': [''], \ 'PrtHistory(-1)': ['', ''], \ 'PrtHistory(1)': ['', ''] \ } nmap ,fb :CtrlPBuffer nmap ,ff :CtrlP . nmap ,fF :execute ":CtrlP " . expand('%:p:h') nmap ,fr :CtrlP nmap ,fm :CtrlPMixed "----------------------------------------------------------------------------- " Gundo Settings "----------------------------------------------------------------------------- nmap :GundoToggle "----------------------------------------------------------------------------- " Conque Settings "----------------------------------------------------------------------------- let g:ConqueTerm_FastMode = 1 let g:ConqueTerm_ReadUnfocused = 1 let g:ConqueTerm_InsertOnEnter = 1 let g:ConqueTerm_PromptRegex = '^-->' let g:ConqueTerm_TERM = 'xterm' "----------------------------------------------------------------------------- " Functions "----------------------------------------------------------------------------- if !exists('g:bufferJumpList') let g:bufferJumpList = {} endif function! MarkBufferInJumpList(bufstr, letter) let g:bufferJumpList[a:letter] = a:bufstr endfunction function! JumpToBufferInJumpList(letter) if has_key(g:bufferJumpList, a:letter) exe ":buffer " . g:bufferJumpList[a:letter] else echoerr a:letter . " isn't mapped to any existing buffer" endif endfunction function! ListJumpToBuffers() for key in keys(g:bufferJumpList) echo key . " = " . g:bufferJumpList[key] endfor endfunction function! IndentToNextBraceInLineAbove() :normal 0wk :normal "vyf( let @v = substitute(@v, '.', ' ', 'g') :normal j"vPl endfunction function! FindGitDirOrRoot() let curdir = expand('%:p:h') let gitdir = finddir('.git', curdir . ';') if gitdir != '' return substitute(gitdir, '\/\.git$', '', '') else return '/' endif endfunction nmap ,ii :call IndentToNextBraceInLineAbove() nmap ,mba :call MarkBufferInJumpList(expand('%:p'), 'a') nmap ,mbb :call MarkBufferInJumpList(expand('%:p'), 'b') nmap ,mbc :call MarkBufferInJumpList(expand('%:p'), 'c') nmap ,mbd :call MarkBufferInJumpList(expand('%:p'), 'd') nmap ,mbe :call MarkBufferInJumpList(expand('%:p'), 'e') nmap ,mbf :call MarkBufferInJumpList(expand('%:p'), 'f') nmap ,mbg :call MarkBufferInJumpList(expand('%:p'), 'g') nmap ,jba :call JumpToBufferInJumpList('a') nmap ,jbb :call JumpToBufferInJumpList('b') nmap ,jbc :call JumpToBufferInJumpList('c') nmap ,jbd :call JumpToBufferInJumpList('d') nmap ,jbe :call JumpToBufferInJumpList('e') nmap ,jbf :call JumpToBufferInJumpList('f') nmap ,jbg :call JumpToBufferInJumpList('g') nmap ,ljb :call ListJumpToBuffers() function! DiffCurrentFileAgainstAnother(snipoff, replacewith) let currentFile = expand('%:p') let otherfile = substitute(currentFile, "^" . a:snipoff, a:replacewith, '') only execute "vertical diffsplit " . otherfile endfunction command! -nargs=+ DiffCurrent call DiffCurrentFileAgainstAnother() function! RunSystemCall(systemcall) let output = system(a:systemcall) let output = substitute(output, "\n", '', 'g') return output endfunction function! HighlightAllOfWord(onoff) if a:onoff == 1 :augroup highlight_all :au! :au CursorMoved * silent! exe printf('match Search /\<%s\>/', expand('')) :augroup END else :au! highlight_all match none /\<%s\>/ endif endfunction :nmap ,ha :call HighlightAllOfWord(1) :nmap ,hA :call HighlightAllOfWord(0) function! LengthenCWD() let cwd = getcwd() if cwd == '/' return endif let lengthend = substitute(cwd, '/[^/]*$', '', '') if lengthend == '' let lengthend = '/' endif if cwd != lengthend exec ":lcd " . lengthend endif endfunction :nmap ,ld :call LengthenCWD() function! ShortenCWD() let cwd = split(getcwd(), '/') let filedir = split(expand("%:p:h"), '/') let i = 0 let newdir = "" while i < len(filedir) let newdir = newdir . "/" . filedir[i] if len(cwd) == i || filedir[i] != cwd[i] break endif let i = i + 1 endwhile exec ":lcd /" . newdir endfunction :nmap ,sd :call ShortenCWD() function! RedirToYankRegisterF(cmd, ...) let cmd = a:cmd . " " . join(a:000, " ") redir @*> exe cmd redir END endfunction command! -complete=command -nargs=+ RedirToYankRegister \ silent! call RedirToYankRegisterF() function! ToggleMinimap() if exists("s:isMini") && s:isMini == 0 let s:isMini = 1 else let s:isMini = 0 end if (s:isMini == 0) " save current visible lines let s:firstLine = line("w0") let s:lastLine = line("w$") " make font small exe "set guifont=" . g:small_font " highlight lines which were visible let s:lines = "" for i in range(s:firstLine, s:lastLine) let s:lines = s:lines . "\\%" . i . "l" if i < s:lastLine let s:lines = s:lines . "\\|" endif endfor exe 'match Visible /' . s:lines . '/' hi Visible guibg=lightblue guifg=black term=bold nmap 10j nmap 10k else exe "set guifont=" . g:main_font hi clear Visible nunmap nunmap endif endfunction command! ToggleMinimap call ToggleMinimap() " I /literally/ never use this and it's pissing me off " nnoremap :ToggleMinimap "----------------------------------------------------------------------------- " Auto commands "----------------------------------------------------------------------------- augroup derek_xsd au! au BufEnter *.xsd,*.wsdl,*.xml setl tabstop=4 shiftwidth=4 augroup END augroup Binary au! au BufReadPre *.bin let &bin=1 au BufReadPost *.bin if &bin | %!xxd au BufReadPost *.bin set filetype=xxd | endif au BufWritePre *.bin if &bin | %!xxd -r au BufWritePre *.bin endif au BufWritePost *.bin if &bin | %!xxd au BufWritePost *.bin set nomod | endif augroup END "----------------------------------------------------------------------------- " Fix constant spelling mistakes "----------------------------------------------------------------------------- iab Acheive Achieve iab acheive achieve iab Alos Also iab alos also iab Aslo Also iab aslo also iab Becuase Because iab becuase because iab Bianries Binaries iab bianries binaries iab Bianry Binary iab bianry binary iab Charcter Character iab charcter character iab Charcters Characters iab charcters characters iab Exmaple Example iab exmaple example iab Exmaples Examples iab exmaples examples iab Fone Phone iab fone phone iab Lifecycle Life-cycle iab lifecycle life-cycle iab Lifecycles Life-cycles iab lifecycles life-cycles iab Seperate Separate iab seperate separate iab Seureth Suereth iab seureth suereth iab Shoudl Should iab shoudl should iab Taht That iab taht that iab Teh The iab teh the "----------------------------------------------------------------------------- " Set up the window colors and size "----------------------------------------------------------------------------- if has("gui_running") exe "set guifont=" . g:main_font colorscheme jellybeans if !exists("g:vimrcloaded") winpos 0 0 if !&diff winsize 130 120 else winsize 227 120 endif let g:vimrcloaded = 1 endif endif :nohls