dotfiles/.vimrc
2013-08-24 15:14:48 -04:00

445 lines
14 KiB
VimL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

" ___ _ _ _
" | _ ) __ _ _ _ __ _| |_( )___ __ _(_)_ __ _ _ __
" | _ \/ _` | '_/ _` | / //(_-< \ V / | ' \| '_/ _|
" |___/\__,_|_| \__,_|_\_\ /__/ (_)_/|_|_|_|_|_| \__|
"
"
" ** BASIC EDITOR SETTINGS **
"
" First, we are vim, not vi, so start as many others do with
set nocompatible
" Allow background buffers. Super important for various tab modes.
set hidden
" Set default spacing.
" Hard tabs should show as 8.
set ts=8
" Soft tabs should be 2 wide, and we should use spaces.
" (This is the Googler in me. I've converted to spaces over
" the years because it really is more consistent.)
set softtabstop=2
set shiftwidth=2
set expandtab
" I like comma instead of slash, but that probably comes from playing
" Nethack and Angband
let mapleader = ","
" Set 'smart' things in Vim
" Search case insensitive, unless it contains Uppercase letters
set smartcase
" Use all the indent features
set autoindent
set smartindent
set cindent
" Make backspace remove indents and line breaks, like a normal editor
set backspace=indent,eol,start
" Keep a bigger history
set history=1000
" Allow tab completion for files in command mode.
set wildmenu
set wildmode=list:longest
" Show where you are in the file in the statusbar.
set ruler
" I hate split above, so make it split below. Likewise, to the right.
set splitbelow
" For autocomplete, show a menu, show it when there's only one option,
" and only complete the longest common bit instead of the whole thing (like
" bash).
set completeopt=menu,menuone,longest
" Some stuff for 256-Color consoles that I've forgotten.
set t_Co=256
set t_Sf=ESC[3%dm
set t_Sb=ESC[4%dm
"set t_kb=
" This is like HiglightTooLongLines below, but for modern vim. The problem is
" that it highlights the column, even if your short. Good for measuring, bad for
" my eyes.
"if v:version >= 703
"set relativenumber
"set colorcolumn=81
"endif
" ** FILETYPE SETTINGS **
filetype off
"call pathogen#runtime_append_all_bundles()
execute pathogen#infect()
let g:ft_ignore_pat = '.org'
filetype plugin indent on
" If you prefer the Omni-Completion tip window to close when a selection is
" made, these lines close it on movement in insert mode or when leaving
" insert mode
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" Sources
"source ~/.vim/supertab.vim
"source ~/.vim/charm.vim
"source ~/.vim/plugin/AppleT.vim
runtime macros/matchit.vim
" Completion features (TODO: Add to filetype.vim)
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType python set tags+=$HOME/.vim/tags/python.ctags
"autocmd FileType python set omnifunc=pythoncomplete#Complete
"autocmd FileType python call SuperTabSetCompletionType("<C-X><C-O>")
" Set filetype for VimOrganizer
"au! BufRead,BufWrite,BufWritePost,BufNewFile *.org
"au BufEnter *.org call org#SetOrgFileType()
au! BufRead,BufWrite,BufWritePost,BufNewFile *.org
au BufEnter *.org call org#SetOrgFileType()
command! OrgCapture :call org#CaptureBuffer()
command! OrgCaptureFile :call org#OpenCaptureFile()
" Cull trailing whitespace for all files.
autocmd BufWritePre * :call AutoTrimWhitespace()
" Set syntax and highlighting
syntax on
" baraknew is my own colorscheme. I used to use slate or dante.
colorscheme baraknew
"colorscheme slate
"colorscheme dante
" Turn on the cursorline (highlight on line under cursor) but only for the
" window and buffer you're currently in. A handy trick, I'm trying out as of
" 2013-04-12 but the jury is still out.
autocmd BufEnter * setlocal cursorline
autocmd WinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
setlocal cursorline
" ** PLUGIN CONFIGURATION **
" * Vim general/Unknown
let python_highlight_all = 1
let g:Tb_MaxSize=0
let g:Tb_MapCTabSwitchBufs = 1
let g:UseGooglePythonSettings = 0
" * Configure browser for haskell_doc.vim
let g:haddock_browser = "open"
let g:haddock_browser_callformat = "%s %s"
" * Lusty plugins
let g:LustyExplorerSuppressRubyWarning = 1
let g:LustyJugglerSuppressRubyWarning = 1
let g:LustyJugglerShowKeys = 'a'
" * Buftabs
let g:buftabs_only_basename = 1
"let g:buftabs_in_statusline=1
"
" * NERDTree
let g:NERDChristmasTree = 1
let g:NERDChristmasTree = 1
let g:NERDTreeQuitOnOpen = 1
let g:NERDTreeWinPos = "right"
let g:NERDTreeWinSize = 40
let g:NERDTreeDirArrows=0
" * Tagbar plugin settings
let g:tagbar_width = 40
let g:tagbar_autofocus = 1
" * Taglist plugin settings (deprecated)
let Tlist_GainFocus_On_ToggleOpen = 1
let Tlist_Use_Right_Window = 1
let Tlist_Inc_Winwidth = 0
let Tlist_File_Fold_Auto_Close = 1
let Tlist_WinWidth = 40
let Tlist_Show_One_File = 0
" * ConqueTerm
let g:ConqueTerm_CWInsert = 1
let g:ConqueTerm_InsertOnEnter = 0
let g:ConqueTerm_SendVisKey = '<Leader>ss'
" * YouCompleteMe
let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
let g:ycm_confirm_extra_conf = 0
"let g:ycm_add_preview_to_completeopt = 1
" * MinBufExplorer
"let g:miniBufExplMapWindowNavVim = 1
"let g:miniBufExplMapWindowNavArrows = 1
"let g:miniBufExplMapCTabSwitchBufs = 1
"let g:miniBufExplModSelTarget = 1
"let g:miniBufExplForceSyntaxEnable = 1
" * CommandT
let g:CommandTMaxFiles = 1000
let g:CommandTMaxDepth = 7
" * VimOrganizer
" default Tag list. Will be changed in near future so
" that these are defined by config lines in each .org
" file itself, but now these are where you can change things:
" let g:org_todo_setup='TODO | DONE'
" while g:org_tag_setup is itself a string
"let g:org_tag_setup='{@home(h) @work(w) @tennisclub(t)} \n {easy(e) hard(d)} \n {computer(c) phone(p)}'
au! BufRead,BufWrite,BufWritePost,BufNewFile *.org
au BufEnter *.org call org#SetOrgFileType()
" * Airline
set noshowmode
let g:airline_enable_branch = 1
let g:airline_enable_syntastic = 1
let g:airline_enable_tagbar = 1
let g:airline_theme="ubaryd"
" ** STATUSLINE **
"
set laststatus=2
set statusline=%t "tail of the filename
"set statusline+=[%{&ff}] "file format
"set statusline+=%h "help file flag
set statusline+=\ %w "help file flag
set statusline+=%r "read only flag
set statusline+=%y "filetype
set statusline+=\ %m "modified flag
set statusline+=%= "left/right separator
set statusline+=%{fugitive#statusline()}\ \
set statusline+=%c, "cursor column
set statusline+=%l/%L "cursor line/total lines
set statusline+=\ %P "percent through file
" ** SMALL FUNCTIONS THAT DON'T FIT AS PLUGINS ***
" Add capital W so I can be lazy about my shift key
if !exists(":W")
command W :w
endif
" CD to the path of the file I'm editing.
command Cdf :cd %:p:h
" Save a vim session! Useful if you want to save buffer states and so on
command SaveSession :mksession! ~/.vim_last_session
command LoadSession :source ~/.vim_last_session
" This is a quick way to edit a persistent scratch buffer for me...
command ScratchOpen :e scp://barak@barakmich.com//home/barak/notes/scratch
" Sudo-make-me-a-sandwich write. For when I forget to be root.
command Wdammit :w !sudo tee > /dev/null %
" I can never remember markdown fully. Open me a cheatsheet
command MarkdownCheatsheet :rightb vsplit ~/.vim/markdown_cheatsheet.md
" Doesn't quite work right but can be a real savior if needed.
" Oh-shit-what-was-this-like-before-I-changed-it?
function! s:DiffWithSaved()
let filetype=&ft
diffthis
vnew | r # | normal! 1Gdd
diffthis
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSaved call s:DiffWithSaved()
" Highlight lines that are longer than textwidth for the filetype, commonly 80
" characters.
function! HighlightTooLongLines()
highlight def link RightMargin Error
if &textwidth != 0
exec 'match RightMargin /\%<' . (&textwidth + 3) . 'v.\%>' . (&textwidth + 1) . 'v/'
endif
endfunction
" Toggles the quickfix window split.
command -bang -nargs=? QFix call QFixToggle(<bang>0)
function! QFixToggle(forced)
if exists("g:qfix_win") && a:forced == 0
cclose
else
execute "copen " . 15
endif
endfunction
" Make the Quickfix window respond well to commands (for instance, q to close,
" Enter to select, etc). In tandem with the above.
augroup QFixToggle
autocmd!
autocmd BufWinEnter quickfix let g:qfix_win = bufnr("$")
autocmd BufWinEnter quickfix exec "nnoremap <silent> <buffer> q :QFix<CR>"
autocmd BufWinLeave * if exists("g:qfix_win") && expand("<abuf>") == g:qfix_win | unlet! g:qfix_win | endif
augroup END
" Execute a command that pipes output to window. Captures output into a new,
" appropriately titled, buffer.
function! s:ExecuteInShellOutput(command)
let command = join(map(split(a:command), 'expand(v:val)'))
let winnr = bufwinnr('^' . command . '$')
silent! execute winnr < 0 ? 'botright new ' . fnameescape(command) : winnr . 'wincmd w'
setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile wrap number
echo 'Executing ' . command . '...'
silent! execute 'silent %!'. command
" uncomment this if you want the new buffer to try to grow to accommodate the output
"silent! execute 'resize ' . line('$')
silent! redraw
silent! execute 'au BufUnload <buffer> execute bufwinnr(' . bufnr('#') . ') . ''wincmd w'''
silent! execute 'nnoremap <silent> <buffer> <LocalLeader>r :call <SID>ExecuteInShell(''' . command . ''')<CR>'
echo 'Execution of ' . command . ' complete.'
endfunction
" Same as above, doesn't capture output
function! s:ExecuteInShell(command)
let command = join(map(split(a:command), 'expand(v:val)'))
silent! execute 'silent !'. command
redraw!
echo 'Execution of ' . command . ' complete.'
endfunction
command! -complete=shellcmd -nargs=+ Shell call s:ExecuteInShellOutput(<q-args>)
command! -complete=shellcmd -nargs=+ Exec call s:ExecuteInShell(<q-args>)
command! -nargs=* Make call s:ExecuteInShellOutput('make '.<q-args>)
command! -nargs=* PTW call s:ExecuteInShell('ptw post --client=vim "'.<q-args>.'"')
" Highlight all instances of word under cursor, when idle.
" Useful when studying strange source code.
" Type z/ to toggle highlighting on/off.
nnoremap z/ :if AutoHighlightToggle()<Bar>set hls<Bar>else<Bar>set nohls<Bar>endif<CR>
function! AutoHighlightToggle()
let @/ = ''
if exists('#auto_highlight')
au! auto_highlight
augroup! auto_highlight
setl updatetime=4000
echo 'Highlight current word: off'
return 0
else
augroup auto_highlight
au!
au CursorHold * let @/ = '\V\<'.escape(expand('<cword>'), '\').'\>'
augroup end
setl updatetime=500
echo 'Highlight current word: ON'
return 1
endif
endfunction
" Removes trailing spaces
function AutoTrimWhitespace()
if exists("b:auto_trim_whitespace")
if b:auto_trim_whitespace == 1
let l:winview = winsaveview()
silent! %s/\s\+$//
call winrestview(l:winview)
endif
endif
endfunction
" ** KEY REMAPPINGS **
"
" I used to use tabs, but then I took an arrow to the knee.
" Tabs in vim suck because they aren't what you want. Use tabbar.
"nnoremap gc :tabnew<CR>
"nnoremap gK :tabclose<CR>
"nnoremap gn gt
"nnoremap gp gT
" I don't know how I came up with gt for opening the tree, but it stuck.
nmap gt :NERDTreeToggle<CR>
" The same for the TagList, useful for large C files.
nmap gb :TlistToggle<CR>
"nnoremap gx :Kwbd<CR>
" :Kwbd (defined below) really kills a buffer dead, and closes the window.
" gK is similar.
nnoremap gc :Kwbd<CR>
"nnoremap gc :bdelete<CR>
nnoremap gK :bdelete!<CR>
" I use gn/gp to cycle through open tabs/buffers
nnoremap gn :bn<CR>
nnoremap gp :bp<CR>
nnoremap gz :pclose<CR>
" The single most handy way to get around a file. Cursor over a word, and then
" type g* -- you'll go to the next instance of that word in the file. Make it
" easier to reach by calling it gw (go-word) instead of hidden away.
nnoremap gw g*
" Make shift-p like p except, put the line above instead of below.
nmap P o<Esc>p
" Line-based movement is cute, but it's tricky for files with lines that wrap.
" Attune more to what you see on the screen instead of where the lines actually
" are.
nnoremap j gj
nnoremap k gk
xnoremap j gj
xnoremap k gk
nnoremap <Down> gj
nnoremap <Up> gk
xnoremap <Down> gj
xnoremap <Up> gk
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
"nnoremap <C-i> <C-a>
" Years of using bash and zsh have caused my fingers to expect these Emacs-like
" mappings to exist. Make them exist in vim as well. But eye them with
" suspicion, as they come from Emacs.
nnoremap <C-a> ^
nnoremap <C-e> $
xnoremap <C-a> ^
xnoremap <C-e> $
inoremap <C-a> <C-O>^
inoremap <C-e> <C-O>$
" Dealing with split windows is a pain. Make it less of a pain, by making
" Ctrl-direction appropriate.
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
nnoremap <C-h> <C-w>h
inoremap <C-j> <C-w>j
inoremap <C-k> <C-w>k
inoremap <C-l> <C-w>l
inoremap <C-h> <C-w>h
" Better fold mappings
nnoremap <silent> <Space> @=(foldlevel('.')?'za':'l')<CR>
vnoremap <Space> zf
" Just to be handy, Ctrl-C acts like escape. So does jj, which never really
" comes up in practice. If you really need to type jj do so slowly.
imap <C-c> <Esc>
inoremap jj <Esc>
" Leader key functions
" See quickfix.
nnoremap <Leader>ff :QFix<CR>
" Next quickfix.
nnoremap <Leader>fn :cnext<CR>
" Prev quickfix.
nnoremap <Leader>fp :cprev<CR>
" Ack (grep) for the word under the cursor.
nnoremap <Leader>aw :exe 'Ack ' . expand('<cword>')<CR>
" Ack prompt.
nnoremap <Leader>ac :Ack
" For C++ -- A is a great plugin which allows you to jump from the c file to the
" header and vice-versa. Mneumonic here is headerheader.
nnoremap <Leader>hh :A<CR>
" CommandT is useful, but if I'm juggling lots of buffers, limit it to another
" one I have open (instead of standard <Leader>t).
nnoremap <silent> <Leader>o :CommandTBuffer<CR>
nnoremap <Leader>j <C-^>
nnoremap <Leader>p :PTW
" ** EXTRA INCLUDES **
"
let s:extrarc = expand($HOME . '/.vimrc_google')
if filereadable(s:extrarc)
exec ':so ' . s:extrarc
endif
" ** SEE ALSO **
" filetype.vim