Mercurial > dotfiles
changeset 193:ae53d68033d9
Enable fugitive and some CtrlP extensions, include a new one of my own.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 23 Jul 2014 16:57:59 -0700 |
parents | 89e9c0c0b839 |
children | 12d610e73ee6 |
files | .ctrlpignore vim/autoload/ctrlpext/autoignore.vim vim/vimrc |
diffstat | 3 files changed, 126 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.ctrlpignore Wed Jul 23 16:57:59 2014 -0700 @@ -0,0 +1,10 @@ +# Unix/Mac +dir:\vvim/backup$ +dir:\vvim/cache$ +dir:\vvim/temp$ + +# Windows +dir:\vvim\\backup$ +dir:\vvim\\cache$ +dir:\vvim\\temp$ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vim/autoload/ctrlpext/autoignore.vim Wed Jul 23 16:57:59 2014 -0700 @@ -0,0 +1,106 @@ +" ============================================================================= +" File: autoload/ctrlpext/autoignore.vim +" Description: Auto-ignore Extension +" Author: Ludovic Chabant <github.com/ludovicchabant> +" ============================================================================= + + +" Global Settings {{{ + +if !exists('g:ctrlp_autoignore_debug') + let g:ctrlp_autoignore_debug = 0 +endif + +if !exists('g:ctrlp_autoignore_trace') + let g:ctrlp_autoignore_trace = 0 +endif + +if exists('g:ctrlp_autoignore_loaded') && g:ctrlp_autoignore_loaded + \ && !g:ctrlp_autoignore_debug + finish +endif +let g:ctrlp_autoignore_loaded = 1 + +" }}} + +" Autoload functions {{{ + +" Call this in your `vimrc` to enable auto-ignore. +function! ctrlpext#autoignore#init() abort + if !exists('g:ctrlp_custom_ignore') + let g:ctrlp_custom_ignore = {} + endif + let g:ctrlp_custom_ignore['func'] = 'ctrlpext#autoignore#ignore' +endfunction + +" List patterns for a given project's root. +function! ctrlpext#autoignore#get_patterns(root_dir) abort + let l:patterns = s:get_project_patterns(a:root_dir) + for pat in l:patterns + let l:prefix = pat['type'] == '' ? '(all)' : pat['type'] + echom l:prefix . ':' . pat['pat'] + endfor +endfunction + +" }}} + +" Internals {{{ + +function! s:trace(message) abort + if g:ctrlp_autoignore_trace + echom "ctrlp_autoignore: " . a:message + endif +endfunction + +let s:proj_cache = {} + +function! s:load_project_patterns(root_dir) abort + let l:ign_path = a:root_dir . '/.ctrlpignore' + if !filereadable(l:ign_path) + call s:trace("No pattern file at: " . l:ign_path) + return [] + endif + let l:patterns = [] + let l:lines = readfile(l:ign_path) + for line in l:lines + if match(line, '\v^\s*$') >= 0 || match(line, '\v^\s*#') >= 0 + continue + endif + let l:matches = matchlist(line, '\v^((dir|file|link)\:)?(.*)') + let l:mtype = l:matches[2] + let l:mpat = l:matches[3] + call add(l:patterns, {'type': l:mtype, 'pat': l:mpat}) + endfor + call s:trace("Loaded " . len(l:patterns) . " patterns from: " . l:ign_path) + return l:patterns +endfunction + +function! s:get_project_patterns(root_dir) abort + let l:patterns = get(s:proj_cache, a:root_dir) + if type(l:patterns) == type([]) + return l:patterns + endif + + call s:trace("Loading patterns for project: " . a:root_dir) + let l:loaded = s:load_project_patterns(a:root_dir) + let s:proj_cache[a:root_dir] = l:loaded + return l:loaded +endfunction + +" The custom ignore function that CtrlP will be using in addition to +" normal pattern-based matching. +function! ctrlpext#autoignore#ignore(item, type) abort + let l:root = getcwd() + let l:patterns = s:get_project_patterns(l:root) + for pat in l:patterns + if pat['type'] == '' || pat['type'] == a:type + if match(a:item, pat['pat']) >= 0 + return 1 + endif + endif + endfor + return 0 +endfunction + +" }}} +
--- a/vim/vimrc Wed Jul 23 16:57:10 2014 -0700 +++ b/vim/vimrc Wed Jul 23 16:57:59 2014 -0700 @@ -38,7 +38,6 @@ call add(g:pathogen_disabled, 'vimroom') call add(g:pathogen_disabled, 'minibufexpl') call add(g:pathogen_disabled, 'ragtag') -call add(g:pathogen_disabled, 'fugitive') " Load pathogen. call pathogen#infect() @@ -126,7 +125,7 @@ " 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,*.pyc,*.pyo +set wildignore+=.DS_Store,Thumbs.db,*.so,*.dll,*.exe,*.lib,*.pdb,*.pyc,*.pyo " Always display the tab-page line. set showtabline=2 @@ -229,6 +228,12 @@ " Make Ctrl-P cache stuff in our temp directory. let g:ctrlp_cache_dir = s:vim_home.'/cache' +" Enable some cool extensions. +let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'mixed'] + +" Initialize other custom extensions. +call ctrlpext#autoignore#init() + " }}} " Syntastic {{{ @@ -371,7 +376,9 @@ " Ctrl-P mappings. nnoremap <silent> <C-p> :CtrlP<cr> nnoremap <silent> <C-o> :CtrlPBuffer<cr> -nnoremap <silent> <C-i> :CtrlPTag<cr> +nnoremap <silent> <C-i> :CtrlPBufTag<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.