Skip to content

Instantly share code, notes, and snippets.

@ezyang
Created April 10, 2017 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezyang/02f30726bd55775d30d4182bf66c5072 to your computer and use it in GitHub Desktop.
Save ezyang/02f30726bd55775d30d4182bf66c5072 to your computer and use it in GitHub Desktop.
My vimrc
" https://github.com/tpope/vim-pathogen
" Pathogen is good because you can keep plugins together in logical
" units, without blasting them throughout your directory structure.
execute pathogen#infect()
" This just turns on per-filetype plugins. Vim ships with file
" indentation/plugin/syntax rules for highlighting. The highlighting
" is nice. Sometimes the indentation is a bit annoying though because
" it REINDENTS my stupid code when I didn't want it to. It's annoying
" to track down why it's doing that...
filetype indent on
filetype on
filetype plugin on
" ...I hade a reason for this one. Maybe.
highlight SpecialKey guifg=#bbbbbb
" Well, I didn't like the default...
highlight comment ctermfg=lightblue
" So, if you see <leader>, this is the key that you press to get it. I
" honestly never use this...
let mapleader="\\"
" Ditto here, but it's for a local leader. I also never use this.
let localmapleader=","
" I like pressing space to tab down
nnoremap <silent> <space> <C-f>
set autoindent " When I type return, I want the same tabbing
set background=dark " Cuz I use a dark terminal. Obviously don't use this if your terminal is light
set backspace=indent,eol,start " Delete past current line
set clipboard=unnamed " This makes vim's clipboard coincide with the system clipboard. I like it but some people might find it annoying. FUTURE: Should make use of vim's registers
set directory=~/.vim-tmp " Where to put swap files.
set backupdir=~/.vim-tmp " Where... to put backup files? I don't know what makes this different from a swapfile.
set expandtab " When you press tab, get spaces. If you're a no-tabs shop, gotta have this on.
set encoding=utf-8 " Uhh... someone gave me these two and I put them in
set fenc=utf-8 " but whatever. UTF-8 is basically what you want.
set formatoptions-=t " autowrap
set formatoptions+=q " gq
set formatoptions+=r " insert comment leader after <ENTER>
set formatoptions+=o " insert comment leader after 'o'/'O'
set formatoptions+=c " autowrap comments
set formatoptions+=b " autowrap only if inserted blank
set history=1000 " If you type colon and then press arrow up, you can get a previous command (actually you can type any prefix and see matching prefixes). Useful.
set hlsearch " Highlight search results as you search. SUPER USEFUL. To clear the highlighting search for a random string.
set incsearch " Automatically search as you are typing query. SUPER USEFUL.
set modeline " Uhhh... not actually that useful. Makes vim interpret modelines. No one uses modelines lol.
set laststatus=2 " I like always having statusline, makes split windows visually clearer.
set list " This setting is great and the next are great
set listchars=tab:>-,trail:· " I can see trailing space and tabs explicitly. Helps kill tabs and trailing space.
set ruler " Tells me where I'm on, on bottom right. Mostly useful for telling if you've gone to far width-wise
" set scrolloff=3 " Not good for quickfix
set shortmess=atI " This helps sometimes. I guess.
set showcmd " Uhhhh... I don't think I actually use this.
set ignorecase " I think this is redundant with the next, actually.
set smartcase " Search is case-insensitive unless you have a capital letter. USEFUL.
set smarttab " I'll be honest, I have no idea what this does
set shiftwidth=4 " This and the next control how many spaces are
set softtabstop=4 " a tab. Can never remember which is which.
" This is the status line you see at the bottom. Maybe not all of it is
" useful but whatever.
set statusline=%F%m%r%h%w\ [%{&ff},\ %{&fenc}]\ [ln:%l\ col:%v]
"\ %{SyntasticStatuslineFlag()} <-- hate this flag, don't put it in menu
set title " Set console title so window shows some useful info
set textwidth=72 " Wrap at 72 cols. Maybe. (This is affected by formatoptions and your syntax file. Ugh. Check out http://blog.ezyang.com/2010/03/vim-textwidth/)
set whichwrap+=<,>,h,l " If I type h at end of line, go to next line
set wildmenu " Show me possible matches
set wildmode=list:longest " This makes completion more like Bash, default is annoying
set visualbell " Don't beep, do a visual bell...
set t_vb="" " BUT disable it (so net effect: no bell)
set undofile " Save your undos even if you close your editor
set undodir=~/.vim-undo " Hate having random undo files, so centralize them
set undolevels=1000 " Maximum number of changes that can be undone
" If your file is bigger than this number of lines, than if you do a
" full-buffer operation like :e!, Vim won't let you undo past this.
set undoreload=10000
syntax on
" Don't check on open, adds latency
let g:syntastic_check_on_open = 0
" I find the other syntax error cues too subtle, but signs are very
" in your face
let g:syntastic_enable_signs = 1
" Experimenting with this, since pulling up :Errors is a pain. I don't
" think it'll interfere too much with :make
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
" Testing for now; NB you can use ctrl-o to jump back
" Results of test: this is pretty nice when you have a lot of errors and
" you're trying to go and fix them one-by-one, but it's utterly unusable
" when you have arbitrary Makefiles, where the error output is not in
" a form parseable by vim. Known offenders: bibtex, ott
" http://vim.wikia.com/wiki/A_better_interfacing_of_(La)TeX_with_the_quickfix_mode
" texwrapper works pretty good for bibtex
"let g:syntastic_auto_jump = 1
" If you mash \\, however, this will jump you to the 'current'
" error. An idiosyncracy of vim means that :lnext does not jump
" to the current if there is only one. See:
" https://github.com/scrooloose/syntastic/issues/32
nmap <silent> <leader>\ :ll<CR>
" Make it behave like :make
let g:syntastic_auto_loc_list = 2
" lacheck is less maintained than chktex, and annoyingly errors when
" commands contain '@' (who thought up of that restriction?!) so use chktex
let g:syntastic_tex_checkers=['chktex']
" One way to work around mismatched parentheses errors that
" chktex emits is to use this pair of macros
"
" \def\lparen{(\strip@prefix)>}
" \def\rparen{\strip@prefix (>)}
"
" This doesn't work for lacheck because it doesn't accept commands with
" @ in it (don't know why)
" Very simplistic ':make' support for Rust: just run rustc
autocmd FileType rust compiler rustc
" XXX disable Racket syntax checking for now
" vim-racket causes syntastic to hang on write, ostensibly because the
" Racket build method configured by vim-racket is extremely slow
" (unsuitable for syntax checking). Anyway, you should be using
" drracket to edit these files anyway.
let g:syntastic_racket_checkers=[]
let g:syntastic_haskell_checkers=[]
let g:syntastic_rst_checkers=[]
" Make, but with a few improvements: write before we try it, suppress
" the output (it's going to show up in the quickfix buffer) and induce
" a redraw, because some output might leak out anyway
map m :w<CR>:silent make<CR>:redraw!<CR>
" Make the quickfix buffer only three lines high, so we conserve screen estate
au FileType qf call AdjustWindowHeight(3, 6)
function! AdjustWindowHeight(minheight, maxheight)
let l = 1
let n_lines = 0
let w_width = winwidth(0)
while l <= line('$')-3
" number to float for division
let l_len = strlen(getline(l)) + 0.0
let line_width = l_len/w_width
let n_lines += float2nr(ceil(line_width))
let l += 1
endw
exe max([min([n_lines, a:maxheight]), a:minheight]) . "wincmd _"
endfunction
" Configure the GHC build trees
function! SetupGhc(name)
" Prefer source directory, in case symlinks are out of date
let orig_includes = '/srv/code/ghc-' . a:name . '/includes'
let orig_rts = '/srv/code/ghc-' . a:name . '/rts'
" You need to have run the build to some (ill-specified) point,
" to make sure includes like ghcplatform.h are created.
let build_includes = '/srv/code/ghc-build-' . a:name .'/includes'
let g:syntastic_c_include_dirs = [orig_includes, orig_rts, build_includes]
endfunction
function! DisableSyn()
let g:syntastic_check_on_open = 0
let g:syntastic_check_on_wq = 0
let g:syntastic_mode_map = { 'mode': 'passive' }
endfunction
function! Tabs()
set noet sts=8 sw=8
endfunction
function! Latency()
call Tabs()
let g:syntastic_cpp_compiler_options = '-std=gnu++11 -Wall'
let g:syntastic_cpp_check_header = 1
let includes = '/home/ezyang/Stanford/latency/lib/libevent/include/'
let g:syntastic_cpp_include_dirs = [includes]
endfunction
" Because I like C++11. And pie.
let g:syntastic_cpp_compiler_options = '-std=gnu++11'
" Basically Syntastic is dumb and thinks that includes always live
" in some directory, which of course, is NEVER where the headers
" actually are. Best to configure it explicitly as mentioned in
" Latency, etc.
let g:syntastic_c_no_default_include_dirs = 1
let g:syntastic_cpp_no_default_include_dirs = 1
" For Xournal settings
"let g:syntastic_c_include_dirs = ['/usr/include/libgnomecanvas-2.0/', '/usr/include/libart-2.0/', 'src', '..', '.']
"let g:syntastic_c_compiler_options = '-DHAVE_CONFIG_H -DPACKAGE_DATA_DIR=\"/usr/local/share\" -DPACKAGE_LOCALE_DIR=\"/usr/local/share/locale\"'
"let g:syntastic_c_no_include_search = 1
" Java checker is DOG slow. Disable it.
let g:loaded_syntastic_java_javac_checker = 1
" Automatically apply some commands when I'm in some folder.
" Though I don't use this as much as I should.
autocmd BufRead,BufNewFile /srv/code/ghc-july/**.c call SetupGhc("july")
autocmd BufRead,BufNewFile /srv/code/ghc-alloc/**.c call SetupGhc("alloc")
autocmd BufRead,BufNewFile /srv/code/serum/**.c call SetupGhc("july")
autocmd BufRead /srv/code/hotspot/** call DisableSyn()
autocmd BufRead,BufNewFile /srv/code/xournal/** call DisableSyn()
autocmd BufRead,BufNewFile /home/ezyang/Research/2writing/ifc.js/** call DisableSyn()
autocmd BufRead,BufNewFile /srv/code/ghc-july/docs/backpack/ubackpack.tex call DisableSyn()
autocmd BufRead,BufNewFile /srv/code/latency/** call Latency()
autocmd BufRead,BufNewFile /home/ezyang/Stanford/latency/** call Latency()
autocmd BufRead,BufNewFile /afs/ir.stanford.edu/users/e/z/ezyang/latency/** call Latency()
autocmd BufRead,BufNewFile /srv/code/granola/** let g:syntastic_cpp_compiler_options = '-std=gnu++11 -Wall'
" Skip QuickFix window when cycling buffers
nnoremap <silent> <C-w><C-w> <C-w><C-w>:if &buftype ==# 'quickfix'<Bar>wincmd w<Bar>endif<CR>
" Look in parent directories for tag files
set tags=tags;
" Gives the me the little chevron on the bottom. Kind of impractical
" but I guess it looks cool.
let g:airline_powerline_fonts = 1
" I don't use tabs, don't want to waste a row displaying tabs.
let g:airline#extensions#tabline#enabled = 0
" https://github.com/vim-scripts/Gundo
" Ever undo undo undo, edit, crap, I lost my redo? Gundo lets you
" get it back. Although, I never seem to have this plugin installed
" when I need undos, so I also use g- g+ :earlier 10 and :later 10
" to navigate chronologically through my undo history.
nnoremap U :GundoToggle<CR>
" From http://vim.wikia.com/wiki/Show_entire_multiline_error_in_quickfix
" Because Vim is dumb and doesn't flush multiline at the top
" I picked the keys based on unimpaired (though I'm not using them.)
map ]q :cwindow<CR>:cn<CR><c-w>bz<CR><CR>
map [q :cwindow<CR>:cp<CR><c-w>bz<CR><CR>
map ]e :lnext<CR><CR>
map [e :lprev<CR><CR>
map ]t :tn<CR>
map [t :tp<CR>
" Automatically open the QuickFix window after make
function! Mycwindow()
cwindow
" Cribbed from http://vim.1045645.n5.nabble.com/detecting-whether-the-quickfix-window-is-open-td1155292.html
for i in range(1, winnr('$'))
let bnum = winbufnr(i)
if getbufvar(bnum, '&buftype') == 'quickfix'
cc
" It would be better to use bnum to jump but
" whatever this works
call feedkeys("\<c-w>bz\<CR>\<CR>")
return
endif
endfor
endfunction
autocmd QuickFixCmdPost [^l]* nested call Mycwindow()
autocmd QuickFixCmdPost l* nested lwindow
set errorformat^=%-G%.%#bound\ at%.%#
" Work around php.vim/html.vim ftplugin ordering bug
" See http://stackoverflow.com/questions/2061321/incorrect-comments-set-for-php-in-vim
au FileType php setlocal comments=s1:/*,mb:*,ex:*/,://,:#
au FileType php setlocal formatoptions+=cro
au BufRead,BufNewFile *.hsig setfiletype haskell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment