Mercurial > dotfiles
view vim/vimrc @ 207:d482e6144d52
Update Autotags, put tags files in a cache dir.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 01 Sep 2014 08:22:38 -0700 |
parents | dae926f52b9a |
children | 477efa0013fd |
line wrap: on
line source
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " " Ludovic Chabant's ~/.vimrc " " http://ludovic.chabant.com " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Global Setup {{{ " Use Vim settings, rather then Vi settings (much better!). " This must be first, because it changes other options as a side effect. set nocompatible " Set a variable that says we already sourced this file, for those few " settings we don't want to re-apply. if exists('g:sourced_vimrc') let g:resourcing_vimrc = 1 endif let g:sourced_vimrc = 1 " Get the platform we're running on. if has("win32") || has("win64") || has("dos32") let s:vim_platform = "windows" else let s:vim_platform = "unix" endif " Get our vim directory. let s:vim_home = expand("<sfile>:h") " Make sure `filetype` stuff is turned off before loading Pathogen. syntax off filetype off " Disable some plugins. let g:pathogen_disabled = [] call add(g:pathogen_disabled, 'vimroom') call add(g:pathogen_disabled, 'minibufexpl') call add(g:pathogen_disabled, 'ragtag') " Load pathogen. call pathogen#infect() " Hide the toolbar in MacVim/gVIM, and set a nice window size. if has("gui_running") && !exists('g:resourcing_vimrc') set guioptions=-t set lines=50 set columns=135 endif " }}} " General Settings {{{ " Restrict modelines. set modelines=1 " Don't unload abandoned buffers. set hidden " Show line numbers. set number " Show what mode we're in, and what command we're typing. set showmode set showcmd " Keep the cursor off the top/bottom edges. set scrolloff=3 " Smart auto-indenting. set autoindent set smartindent " Use confirmation dialog. set confirm " Don't use annoying sounds. set visualbell " Remember lots of commands. set history=1000 " Try to reduce flickering. set lazyredraw " Show matching braces but not for too long. set showmatch set matchtime=2 " Show soft-broken/wrapped lines with a prefix. set showbreak=→ " Use incremental search, with highlighting, " case-insensitive unless we actually type some " mixed-case stuff. set incsearch set hlsearch set ignorecase set smartcase " Always show window status lines. set laststatus=2 " Enable using the mouse like some everyday guy. set mouse=a " Show interesting stuff at the bottom of the window. set showcmd set ruler " Make sure splitting windows is done in a way that makes sense. set splitbelow set splitright " Don't pollute the hard-drive with *~ files. Only " create them in hidden backup/temp directories while " we edit the file, and then get rid of it. set nobackup set writebackup execute('set backupdir='.s:vim_home.'/backup') execute('set directory='.s:vim_home.'/temp') " Better command-line completion, but don't show some " stuff we don't care about. set wildmenu set wildignore+=.DS_Store,Thumbs.db,*.so,*.dll,*.exe,*.lib,*.pdb,*.pyc,*.pyo " Always display the tab-page line. set showtabline=2 " Set the file-formats. set ffs=unix,mac,dos " Tabs and indenting are 4 characters, and tabs behave like " spaces during editing. They're smart, too, and when you " press <TAB> it actually inserts a soft-tab so everything's " indented the same. set tabstop=4 set shiftwidth=4 set softtabstop=4 set smarttab set expandtab " Default encoding set encoding=utf-8 " Clipboard buffer. set clipboard=unnamed " Smoot terminal experience. set ttyfast " Allow backspacing over anything. set backspace=indent,eol,start " Going left and right let you go to other lines. set whichwrap+=<,>,h,l " How to show invisible characters set listchars=eol:$,tab:>-,trail:-,extends:>,precedes:<,nbsp:%,conceal:. " Folds are defined by markers in the text. set foldmethod=marker " Nice auto-complete menu. set completeopt=longest,menuone,preview " Column indicators. set colorcolumn=72,79 " And now, for some system-dependent settings: " - font to use if s:vim_platform == "windows" set guifont=Consolas:h12 else set guifont=Monaco:h12 endif " Syntax highlighting. syntax on " Change the current directory to the home directory. if !exists('g:resourcing_vimrc') cd ~/ endif " Default color scheme. if has('gui_running') set background=light else set background=dark endif colorscheme badwolf " Enable file type detection. filetype indent plugin on " }}} " Auto-Commands {{{ " Only show the highlighted cursor line in the current window. augroup CursorLine au! au WinLeave * set nocursorline au WinEnter * set cursorline augroup END " }}} " Plugin Settings {{{ " Ctrl-P {{{ " We'll set our own mappings. let g:ctrlp_map = '' " Ctrl-P should manage the working directory. let g:ctrlp_working_path_mode = 'ra' " Ctrl-P should however ignore some stuff. let g:ctrlp_custom_ignore = { \ 'dir': '\v[\/](\.git|\.hg|\.svn|venv|build|static|node_modules)$' \ } " Make Ctrl-P cache stuff in our temp directory. let g:ctrlp_cache_dir = s:vim_home.'/cache' " Remember things. let g:ctrlp_clear_cache_on_ext = 0 " Enable some cool extensions. let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'mixed'] " Initialize other custom extensions. call ctrlpext#autoignore#init() " }}} " Autotags {{{ let g:autotags_exclude = ['venv', 'build', 'static', 'node_modules'] let g:autotags_cache_dir = s:vim_home.'/tags' " }}} " Syntastic {{{ " Use `pyflakes` with `syntastic`. "let g:syntastic_python_checkers = ['pyflakes'] "let g:syntastic_mode_map = { " \'mode': 'active', " \'passive_filetypes': []} " }}} " Lawrencium {{{ " Custom Mercurial commands highlighting in Lawrencium. let g:lawrencium_hg_commands_file_types = { \'clog': 'hggraphlog' \} " Make the annotate window better in Lawrencium. let g:lawrencium_annotate_width_offset = 1 " }}} " Gundo {{{ let g:gundo_map_move_older = '<Down>' let g:gundo_map_move_newer = '<Up>' " }}} " YankRing {{{ let g:yankring_replace_n_pkey = '<C-K>' let g:yankring_replace_p_pkey = '<C-J>' " }}} " Python-Mode {{{ let g:pymode = 0 " }}} " }}} " File-Specific Settings {{{ if has("autocmd") augroup VimRCAutoCWD au! autocmd BufEnter * call s:SetProjectRootCwd() augroup END augroup VimRCFileTypeSettings au! " Nice text width for text files. autocmd FileType text,markdown setlocal textwidth=80 " Who the hell changes my matchpairs? autocmd FileType php setlocal matchpairs-=<:> " File I know are markdown: personal notes & PieCrust pages. autocmd BufRead,BufNewfile */Dropbox/Personal/SimpleNote/* set ft=markdown autocmd BufRead,BufNewFile */_content/**/*.html set ft=piecrustmarkdown augroup END augroup VimRCTrailingWhitespaces au! autocmd FileType c,cpp,java,php,ruby,python,js,css,less autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces() augroup END endif " }}} " Mappings {{{ let mapleader="," " Visual line navigation noremap <up> g<up> noremap <down> g<down> noremap <home> g<home> noremap <end> g<end> " Tab navigation noremap <C-Tab> :tabnext<cr> noremap <C-S-Tab> :tabprevious<cr> " Window navigation nnoremap <C-up> :wincmd k<cr> nnoremap <C-down> :wincmd j<cr> nnoremap <C-left> :wincmd h<cr> nnoremap <C-right> :wincmd l<cr> " Switch buffers. nnoremap <F2> :execute ("buffer " . bufname("#"))<cr> " NERDTree. nnoremap <F3> :call <SID>ToggleNERDTree()<cr> nnoremap <F4> :call <SID>FindInNERDTree()<cr> " Tagbar. nnoremap <F5> :TagbarToggle<cr> nnoremap <F6> :TagbarOpenAutoClose<cr> " Gundo. nnoremap <F7> :GundoToggle<cr> " Common typos. nnoremap ; : " Split windows nnoremap <leader>s :split<cr> nnoremap <leader>v :vsplit<cr> " Easier things to type nnoremap <leader>w :w<cr> nnoremap <leader>q :q<cr> nnoremap <leader>hh :Hg nnoremap <leader>hg :Hg! nnoremap <leader>hs :Hgstatus<cr> nnoremap <leader>hv :Hgvdiff<cr> " Make the hash-key not suck. inoremap # X<BS># " Toggle invisible characters nnoremap <leader>i :set list!<cr> " Clear search matches nnoremap <leader><space> :noh<cr>:call clearmatches()<cr> " Ctrl-P mappings. nnoremap <silent> <C-p> :CtrlP<cr> nnoremap <silent> <C-o> :CtrlPBuffer<cr> nnoremap <silent> <C-u> :CtrlPTag<cr> nnoremap <silent> <C-y> :CtrlPQuickfix<cr> nnoremap <silent> <Tab> :CtrlPMRUFiles<cr> " Switch between FR and US keyboard layouts. nnoremap <C-l>f :setlocal keymap=french<cr> nnoremap <C-l>u :setlocal keymap=<cr> " Toggle spell check according to current keyboard layout. nnoremap <C-l>s :call <SID>ToggleSpellCheck()<cr> " Simple way to close a buffer without closing the window. nnoremap <leader>bd :bprevious<cr>:bdelete #<cr> " Toggle folds with <space>. nnoremap <space> za " Create folds with <space> (in visual mode). vnoremap <space> zf " File-type switching. nnoremap <leader>ftmd :set ft=markdown<cr> " Use sane regexes. nnoremap / /\v vnoremap / /\v " Quick search and replace. function! s:VSetSearch() let temp = @@ norm! gvy let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g') let @@ = temp endfunction vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR><c-o> vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR><c-o> " Jump to tags by keeping things better in view. Option for jumping to a tag " in a split window where everything is folded except what you need to see. function! JumpToTag() execute "normal! \<c-]>zz" endfunction function! JumpToTagInSplit() execute "normal! \<c-w>v\<c-]>zMzvzz" endfunction nnoremap <c-]> :silent! call JumpToTag()<cr> nnoremap <c-\> :silent! call JumpToTagInSplit()<cr> " Keep search matches in the middle of the window. nnoremap n nzzzv nnoremap N Nzzzv " Same when jumping around nnoremap g; g;zz nnoremap g, g,zz " }}} " Abbreviations {{{ iabbrev @@ ludovic@chabant.com iabbrev ccopy Copyright ©2011 Ludovic Chabant, all rights reserved. iabbrev ssig --<cr>l u d o .<cr>. 8 0 17 80 " }}} " Status Line {{{ set statusline=%f " Path. set statusline+=%m " Modified flag. set statusline+=%r " Readonly flag. set statusline+=%w " Preview window flag. set statusline+=\ " Space. set statusline+=%#redbar# " Highlight the following as a warning. set statusline+=%{SyntasticStatuslineFlag()} " Syntastic errors. set statusline+=%* " Reset highlighting. set statusline+=%= " Right align. " Tag file generation indicator. set statusline+=%{autotags#statusline('[TAGS]')} set statusline+=\ " Space. " Mercurial information. set statusline+=%{lawrencium#statusline('[',']')} set statusline+=\ " Space. " File format, encoding and type. Ex: "(unix/utf-8/python)" set statusline+=( set statusline+=%{&ff} " Format (unix/DOS). set statusline+=/ set statusline+=%{strlen(&fenc)?&fenc:&enc} " Encoding (utf-8). set statusline+=/ set statusline+=%{&ft} " Type (python). set statusline+=) " Line and column position and counts. set statusline+=\ (line\ %l\/%L,\ col\ %03c) " }}} " Functions {{{ function! s:ToggleSpellCheck() abort if &spell ==? 'nospell' if &keymap ==? 'french' setlocal spell spelllang=fr_fr else setlocal spell spelllang=en_us,en_ca endif else setlocal spell nospell endif endfunction function! s:StripTrailingWhitespaces() abort let l = line(".") let c = col(".") %s/\s\+$//e let @/='' call cursor(l, c) endfunction function! s:FindProjectRoot(cur, marker) abort let l:cur = a:cur let l:previous_cur = '' let l:slash = '/' if has('win32') let l:slash = '\\' endif while l:cur != l:previous_cur let l:marker_path = l:cur . l:slash . a:marker if glob(l:marker_path) != '' return fnamemodify(l:cur, ':p') endif let l:previous_cur = l:cur let l:cur = fnamemodify(l:cur, ':h') endwhile return '' endfunction function! s:SetProjectRootCwd() abort let l:cur_file_dir = expand('%:p:h', 1) if l:cur_file_dir =~ '\v^.+:(//|\\\\)' return endif let l:root = l:cur_file_dir let l:markers = [] if exists('g:ctrlp_root_markers') let l:markers += g:ctrlp_root_markers endif let l:markers += ['.git', '.hg', '.svn', '.bzr', '_darcs'] for marker in l:markers let l:proj_root = s:FindProjectRoot(l:cur_file_dir, marker) if l:proj_root != '' let l:root = l:proj_root break endif endfor execute 'lcd!' fnameescape(l:root) endfunction function! s:ToggleNERDTree() abort let l:was_open = nerdtree#isTreeOpen() NERDTreeToggle if !l:was_open wincmd p NERDTreeCWD wincmd p NERDTreeFind endif endfunction function! s:FindInNERDTree() abort if !nerdtree#isTreeOpen() call s:ToggleNERDTree() else if getbufvar('%', 'NERDTreeType') != '' wincmd p else NERDTreeFind endif endif endfunction " }}} " Temporary stuff {{{ " Enable debugging Lawrencium let g:lawrencium_debug = 1 let g:lawrencium_trace = 0 command! LawrenciumEnableTrace :call lawrencium#debugtrace(1) command! LawrenciumDisableTrace :call lawrencium#debugtrace(0) let g:autotags_debug = 1 " Enable debugging PieCrust let g:piecrust_debug = 1 let g:piecrust_trace = 0 " }}} " Local override {{{ let s:local_vimrc = s:vim_home.'/vimrc-local' if filereadable(s:local_vimrc) execute 'source' s:local_vimrc endif " }}}