From a50d01abd658d4268c6c72419a9894cdc76972d5 Mon Sep 17 00:00:00 2001 From: Barak Michener Date: Fri, 12 Apr 2013 15:11:32 -0400 Subject: [PATCH] .vimrc --- .vimrc | 232 +++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 118 insertions(+), 114 deletions(-) diff --git a/.vimrc b/.vimrc index 53c34f9..4d57375 100644 --- a/.vimrc +++ b/.vimrc @@ -1,55 +1,86 @@ +" ___ _ _ _ +" | _ ) __ _ _ _ __ _| |_( )___ __ _(_)_ __ _ _ __ +" | _ \/ _` | '_/ _` | / //(_-< \ V / | ' \| '_/ _| +" |___/\__,_|_| \__,_|_\_\ /__/ (_)_/|_|_|_|_|_| \__| +" +" Let's have a look. +" First, we are vim, not vi, so start as many others do with +" +" ** BASIC EDITOR SETTINGS ** set nocompatible " Set syntax and highlighting syntax on +" baraknew is my own colorscheme. I used to use slate or dante. +colorscheme baraknew "colorscheme slate "colorscheme dante -colorscheme baraknew -" Set default spacing -"set gfn=Monaco:h12:a +" 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 +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() filetype plugin indent on -" Set 'smart' things in Vim -set smartcase -set autoindent -set smartindent -set cindent -set hidden -set backspace=indent,eol,start - -set history=1000 -set wildmenu -set wildmode=list:longest -set ruler - -set splitbelow -set completeopt=menu,menuone,longest " 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 -" Some stuff for console 256 Colors -set t_Co=256 -set t_Sf=ESC[3%dm -set t_Sb=ESC[4%dm -"set t_kb= -" -"if v:version >= 703 - "set relativenumber - "set colorcolumn=81 -"endif - " Sources "source ~/.vim/supertab.vim @@ -62,14 +93,35 @@ 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("") +" +au! BufRead,BufWrite,BufWritePost,BufNewFile *.org +au BufEnter *.org call org#SetOrgFileType() + +" 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/Unknown let python_highlight_all = 1 let g:Tb_MaxSize=0 let g:Tb_MapCTabSwitchBufs = 1 + +" 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 @@ -77,7 +129,6 @@ 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 @@ -90,12 +141,11 @@ 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 = 'ss' -au! BufRead,BufWrite,BufWritePost,BufNewFile *.org -au BufEnter *.org call org#SetOrgFileType() "MiniBufExplore Options "let g:miniBufExplMapWindowNavVim = 1 "let g:miniBufExplMapWindowNavArrows = 1 @@ -103,24 +153,41 @@ au BufEnter *.org call org#SetOrgFileType() "let g:miniBufExplModSelTarget = 1 "let g:miniBufExplForceSyntaxEnable = 1 +" CommandT +let g:CommandTMaxFiles = 1000 +let g:CommandTMaxDepth = 7 -"Remappings -"Open in tabs... + +" ** 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 "nnoremap gK :tabclose "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 nmap gb :TlistToggle "nnoremap gx :Kwbd +" :Kwbd (defined below) really kills a buffer dead, and closes the window. +" gK is similar. nnoremap gc :Kwbd "nnoremap gc :bdelete nnoremap gK :bdelete! +" I use gn/gp to cycle through open tabs nnoremap gn :bn nnoremap gp :bp nnoremap gz :pclose +" 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 op +" 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 @@ -132,22 +199,27 @@ xnoremap gk inoremap gj inoremap gk "nnoremap +" 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 ^ nnoremap $ xnoremap ^ xnoremap $ inoremap ^ inoremap $ + +" Better fold mappings +nnoremap @=(foldlevel('.')?'za':'l') +vnoremap 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 +inoremap jj -"nmap :FocusNextWindow -"nmap :FocusPrevWindow -"nmap :FocusMasterWindow -"nmap :SwapWithMasterWindow -"nmap :SwapWithNextWindow -"nmap :SwapWithPrevWindow - +" ** STATUSLINE ** +" set laststatus=2 set statusline=%t "tail of the filename "set statusline+=[%{&ff}] "file format @@ -162,28 +234,20 @@ set statusline+=%c, "cursor column set statusline+=%l/%L "cursor line/total lines set statusline+=\ %P "percent through file - -autocmd BufEnter * setlocal cursorline -autocmd WinEnter * setlocal cursorline -autocmd WinLeave * setlocal nocursorline -setlocal cursorline - -" Useful functions +" ** SMALL FUNCTIONS THAT DON'T FIT AS PLUGINS *** " Add capital W so I can be lazy about my shift jey 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 -let g:CommandTMaxFiles = 1000 -let g:CommandTMaxDepth = 7 - " 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 @@ -199,39 +263,6 @@ function! s:DiffWithSaved() endfunction com! DiffSaved call s:DiffWithSaved() -" Forget where I found this... -function! Find(name) - let l:_name = substitute(a:name, "\\s", "*", "g") - "let l:list=system("find . -iname '*".l:_name."*' -not -name \"*.class\" -and -not -name \"*.swp\" | perl -ne 'print \"$.\\t$_\"'") - let l:list=system("find . -path \"*/.svn\" -prune -o -iname '*".l:_name."*' -not -name \"*.class\" -and -not -name \"*.swp\" -print | perl -ne 'print \"$.\\t$_\"'") - let l:num=strlen(substitute(l:list, "[^\n]", "", "g")) - if l:num < 1 - echo "'".a:name."' not found" - return - endif - if l:num != 1 - echo l:list - let l:input=input("Which ? (=nothing)\n") - if strlen(l:input)==0 - return - endif - if strlen(substitute(l:input, "[0-9]", "", "g"))>0 - echo "Not a number" - return - endif - if l:input<1 || l:input>l:num - echo "Out of range" - return - endif - let l:line=matchstr("\n".l:list, "\n".l:input."\t[^\n]*") - else - let l:line=l:list - endif - let l:line=substitute(l:line, "^[^\t]*\t./", "", "") - execute ":e ".l:line -endfunction -command! -nargs=1 Find :call Find("") - " toggles the quickfix window. command -bang -nargs=? QFix call QFixToggle(0) function! QFixToggle(forced) @@ -260,8 +291,6 @@ nnoremap o :CommandTBuffer nnoremap j nnoremap p :PTW -" Googley things.... - function! HighlightTooLongLines() highlight def link RightMargin Error if &textwidth != 0 @@ -269,28 +298,9 @@ function! HighlightTooLongLines() endif endfunction -let g:google_enable = 0 -let g:disable_google_optional_settings = 1 -if filereadable("/usr/share/vim/google/google.vim") - source /usr/share/vim/google/google.vim - let g:google_enable = 1 -endif - -if g:google_enable != 0 - augroup filetypedetect - au WinEnter,BufNewFile,BufRead * call HighlightTooLongLines() - augroup END - " Load Blaze errors into quickfix mode - nmap bl :call LoadBlazeErrors():cc - " Run the most appropriate blaze command on the target for the current file. - nmap bb :call BlazeDwim() - " Run update_deps on the target for the current file. - nmap bu :call UpdateDepsDwim() - " Configure a 'Comments' command to import CL code review comments into the - " quickfix buffer. - command! Comments cexpr system('git5 comments -q -u') - command! Lint cexpr system('git5 lint -q') - nmap bs :!google-chrome https://cs.corp.google.com/'' +let s:extrarc = expand($HOME . '/.vimrc_google') +if filereadable(s:extrarc) + exec ':so ' . s:extrarc endif " Configure browser for haskell_doc.vim @@ -322,7 +332,6 @@ endfunction command! -complete=shellcmd -nargs=+ Shell call s:ExecuteInShellOutput() command! -complete=shellcmd -nargs=+ Exec call s:ExecuteInShell() command! -nargs=* Make call s:ExecuteInShellOutput('make '.) -command! -nargs=* Git call s:ExecuteInShellOutput('git '.) command! -nargs=* PTW call s:ExecuteInShell('ptw post --client=vim "'..'"') " Highlight all instances of word under cursor, when idle. @@ -362,11 +371,6 @@ endfunction autocmd BufWritePre * :call AutoTrimWhitespace() -" Test fold mappings -nnoremap @=(foldlevel('.')?'za':'l') -vnoremap zf -inoremap jj - " 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: