diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 4098d6b..e023eff 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -3,7 +3,7 @@ " Description: Full path fuzzy file, buffer and MRU file finder for Vim. " Author: Kien Nguyen " License: MIT -" Version: 1.5 +" Version: 1.5.1 " ============================================================================= if v:version < '700' "{{{ @@ -14,7 +14,6 @@ endif "}}} func! s:opts() let opts = { \ 'g:ctrlp_match_window_reversed' : ['s:mwreverse', 1], - \ 'g:ctrlp_persistent_input' : ['s:pinput', 0], \ 'g:ctrlp_split_window' : ['s:splitwin', 0], \ 'g:ctrlp_working_path_mode' : ['s:pathmode', 1], \ 'g:ctrlp_root_markers' : ['s:rmarkers', []], @@ -25,20 +24,15 @@ func! s:opts() \ 'g:ctrlp_by_filename' : ['s:byfname', 0], \ 'g:ctrlp_prompt_mappings' : ['s:urprtmaps', 0], \ 'g:ctrlp_dotfiles' : ['s:dotfiles', 1], - \ 'g:ctrlp_highlight_match' : ['s:mathi', [1, 'Function']], + \ 'g:ctrlp_highlight_match' : ['s:mathi', [1, 'Identifier']], \ 'g:ctrlp_max_files' : ['s:maxfiles', 20000], \ 'g:ctrlp_max_depth' : ['s:maxdepth', 40], - \ 'g:ctrlp_live_update' : ['s:liup', 1], \ 'g:ctrlp_open_new_file' : ['s:newfop', 3], \ 'g:ctrlp_open_multi' : ['s:opmul', 1], \ } for key in keys(opts) - if call('exists', [key]) - let def = type(eval(key)) != 1 ? string(eval(key)) : eval(key) - exe 'unl' key - else - let def = type(opts[key][1]) != 1 ? string(opts[key][1]) : opts[key][1] - endif + let def = call('exists', [key]) ? string(eval(key)) : string(opts[key][1]) + exe 'unl!' key exe 'let' opts[key][0] '=' def endfor if !exists('g:ctrlp_cache_dir') @@ -253,33 +247,19 @@ func! s:GetMatchedItems(items, pats, limit) let newitems = s:MatchIt(items, each, limit) endif endfor - let s:nomatches = len(newitems) + let s:matches = len(newitems) retu newitems endfunc "}}} -func! s:SetupBlank() "{{{ - setl bt=nofile bh=unload noswf nobl ts=4 sw=4 sts=4 nonu - \ nowrap nolist nospell cul nocuc tw=0 wfh - if v:version >= '703' - setl nornu noudf cc=0 - endif - redr -endfunc "}}} - func! s:BufOpen(...) "{{{ - " a:1 bufname; a:2 delete - let buf = a:1 - " Closing, use s:winnr as a switch to avoid an issue with Vim 7.2 - if exists('s:winnr') + if exists('a:2') + " Closing try bun! catch winc c endtry - unl! s:winnr - endif - if exists('a:2') exe s:currwin.'winc w' " Restore the changed global options let &magic = s:CtrlP_magic @@ -298,19 +278,21 @@ func! s:BufOpen(...) "{{{ cal s:unmarksigns() let g:ctrlp_lines = [] let g:ctrlp_allfiles = [] - if s:pinput != 2 - unl! g:CtrlP_cline - endif + unl! g:CtrlP_cline if exists('s:cwd') exe 'chd!' s:cwd unl s:cwd endif - unl! s:focus s:firstinit s:hisidx s:hstgot s:marked s:bufnr + unl! s:focus s:hisidx s:hstgot s:marked s:winnr s:init + " Record the input string + let prt = g:CtrlP_prompt + cal s:recordhist(prt[0] . prt[1] . prt[2]) ec else let s:currwin = winnr() " Open new buffer - exe 'sil! bo 1new' buf + sil! exe 'bo 1new' a:1 + abc let s:winnr = bufwinnr('%') let s:bufnr = bufnr('%') " Store global options @@ -326,9 +308,7 @@ func! s:BufOpen(...) "{{{ let s:CtrlP_siso = &siso let s:CtrlP_gcr = &gcr let s:CtrlP_mfd = &mfd - if !s:pinput - let g:CtrlP_prompt = ['', '', ''] - endif + let g:CtrlP_prompt = ['', '', ''] if !exists('s:hstry') let hst = filereadable(s:gethistloc()[1]) ? s:gethistdata() : [''] let s:hstry = empty(hst) || !s:maxhst ? [''] : hst @@ -353,10 +333,7 @@ endfunc "}}} func! s:Renderer(lines, pat) "{{{ cal s:unmarksigns() - let nls = [] - for i in range(0, len(a:lines) - 1) - cal add(nls, '> '.a:lines[i]) - endfor + let nls = deepcopy(a:lines) " Determine/set max height let height = s:mxheight let max = len(nls) < height ? len(nls) : height @@ -373,6 +350,8 @@ func! s:Renderer(lines, pat) "{{{ if s:mwreverse cal reverse(nls) endif + let s:matched = deepcopy(nls) + cal map(nls, 'substitute(v:val, "^", "> ", "")') cal setline('1', nls) if s:mwreverse keepj norm! G @@ -380,8 +359,7 @@ func! s:Renderer(lines, pat) "{{{ keepj norm! gg endif keepj norm! 1| - let s:matched = nls - cal s:remarksigns(nls) + cal s:remarksigns(s:matched) else setl nocul cal setline('1', ' == NO MATCHES ==') @@ -406,7 +384,7 @@ func! s:UpdateMatches(pat) "{{{ endif endfunc "}}} -func! s:BuildPrompt(...) "{{{ +func! s:BuildPrompt(upd,...) "{{{ let base1 = s:regexp ? 'r' : '>' let base2 = s:byfname ? 'd' : '>' let base = base1.base2.'> ' @@ -415,16 +393,17 @@ func! s:BuildPrompt(...) "{{{ let prt = deepcopy(g:CtrlP_prompt) cal map(prt, 'escape(v:val, estr)') let str = prt[0] . prt[1] . prt[2] - if s:nomatches && ( s:liup || s:firstinit ) - let s:firstinit = 0 + if ( s:matches || s:regexp || match(str, '[*|]') >= 0 ) && a:upd sil! cal s:UpdateMatches(str) endif sil! cal s:statusline() " Toggling if !exists('a:1') || ( exists('a:1') && a:1 ) let hiactive = 'Normal' + let hicursor = 'Constant' elseif exists('a:1') || ( exists('a:1') && !a:1 ) let hiactive = 'Comment' + let hicursor = 'Comment' let base = substitute(base, '>', '-', 'g') endif let hibase = 'Comment' @@ -432,7 +411,7 @@ func! s:BuildPrompt(...) "{{{ redr exe 'echoh' hibase '| echon "'.base.'" \ | echoh' hiactive '| echon "'.prt[0].'" - \ | echoh' hibase '| echon "'.prt[1].'" + \ | echoh' hicursor '| echon "'.prt[1].'" \ | echoh' hiactive '| echon "'.prt[2].'" \ | echoh None' " Append the cursor _ at the end @@ -441,14 +420,6 @@ func! s:BuildPrompt(...) "{{{ endif endfunc "}}} -func! s:ForceUpdate() "{{{ - let estr = '"\' - let prt = deepcopy(g:CtrlP_prompt) - cal map(prt, 'escape(v:val, estr)') - let str = prt[0] . prt[1] . prt[2] - cal s:UpdateMatches(str) -endfunc "}}} - func! s:CreateNewFile() "{{{ let prt = g:CtrlP_prompt let str = prt[0] . prt[1] . prt[2] @@ -456,7 +427,6 @@ func! s:CreateNewFile() "{{{ let arr = split(str, '[\/]') cal map(arr, 'escape(v:val, "%#")') let fname = remove(arr, -1) - cal s:recordhist(str) winc c if s:newfop == 1 " In new tab tabnew @@ -470,10 +440,10 @@ func! s:CreateNewFile() "{{{ endif if len(arr) if isdirectory(s:createparentdirs(arr)) - exe 'bo '.cmd.' '.str + sil! exe 'bo '.cmd.' '.str endif else - exe 'bo '.cmd.' '.fname + sil! exe 'bo '.cmd.' '.fname endif cal s:insertcache(str) endfunc "}}} @@ -510,12 +480,15 @@ func! s:MarkToOpen() endfunc func! s:OpenMulti() - if !exists('s:marked') || !s:opmul | retu | endif + if !exists('s:marked') || !s:opmul + cal s:AcceptSelection('e') + retu + endif let marked = deepcopy(s:marked) let prt = g:CtrlP_prompt let str = prt[0] . prt[1] . prt[2] - if !empty(str) | cal s:recordhist(str) | endif if !has('autocmd') | cal s:BufOpen('ControlP', 'del') | endif + exe s:currwin.'winc w' " Try not to open in new tab let bufs = [] for winnr in range(1, winnr('$')) @@ -523,7 +496,7 @@ func! s:OpenMulti() endfor let ntab = 1 " Check if the other window only has a blank buffer - if len(bufs) == 2 + if len(bufs) == 1 for each in bufs if getbufvar(each, '&bl') && empty(bufname(each)) \ && empty(getbufvar(each, '&bt')) && empty(getbufvar(each, '&ft')) @@ -537,50 +510,48 @@ func! s:OpenMulti() let ic = 1 for key in keys(marked) let filpath = marked[key] - exe 'bo vne' filpath + sil! exe 'bo vne' filpath if s:opmul > 1 && s:opmul < ic winc c else let ic += 1 endif endfor - if ntab - 1winc w | winc c - endif + 1winc w | winc c ec endfunc "}}} " * Prt Actions {{{ func! s:PrtClear() - let s:nomatches = 1 + let s:matches = 1 unl! s:hstgot let g:CtrlP_prompt = ['','',''] - cal s:BuildPrompt() + cal s:BuildPrompt(1) endfunc func! s:PrtAdd(char) unl! s:hstgot let prt = g:CtrlP_prompt let prt[0] = prt[0] . a:char - cal s:BuildPrompt() + cal s:BuildPrompt(1) endfunc func! s:PrtBS() - let s:nomatches = 1 + let s:matches = 1 unl! s:hstgot let prt = g:CtrlP_prompt let prt[0] = strpart(prt[0], -1, strlen(prt[0])) - cal s:BuildPrompt() + cal s:BuildPrompt(1) endfunc func! s:PrtDelete() - let s:nomatches = 1 + let s:matches = 1 unl! s:hstgot let prt = g:CtrlP_prompt let prt[1] = strpart(prt[2], 0, 1) let prt[2] = strpart(prt[2], 1) - cal s:BuildPrompt() + cal s:BuildPrompt(1) endfunc func! s:PrtCurLeft() @@ -590,13 +561,15 @@ func! s:PrtCurLeft() let prt[1] = strpart(prt[0], strlen(prt[0]) - 1) let prt[0] = strpart(prt[0], -1, strlen(prt[0])) endif - cal s:BuildPrompt() + cal s:BuildPrompt(0) endfunc func! s:PrtCurRight() let prt = g:CtrlP_prompt let prt[0] = prt[0] . prt[1] - cal s:PrtDelete() + let prt[1] = strpart(prt[2], 0, 1) + let prt[2] = strpart(prt[2], 1) + cal s:BuildPrompt(0) endfunc func! s:PrtCurStart() @@ -605,7 +578,7 @@ func! s:PrtCurStart() let prt[2] = strpart(str, 1) let prt[1] = strpart(str, 0, 1) let prt[0] = '' - cal s:BuildPrompt() + cal s:BuildPrompt(0) endfunc func! s:PrtCurEnd() @@ -614,11 +587,11 @@ func! s:PrtCurEnd() let prt[2] = '' let prt[1] = '' let prt[0] = str - cal s:BuildPrompt() + cal s:BuildPrompt(0) endfunc func! s:PrtDeleteWord() - let s:nomatches = 1 + let s:matches = 1 unl! s:hstgot let prt = g:CtrlP_prompt let str = prt[0] @@ -632,7 +605,7 @@ func! s:PrtDeleteWord() let str = '' endif let prt[0] = str - cal s:BuildPrompt() + cal s:BuildPrompt(1) endfunc func! s:PrtSelectMove(dir) @@ -641,7 +614,7 @@ func! s:PrtSelectMove(dir) endfunc func! s:PrtSelectJump(char,...) - let lines = map(s:matched, 'substitute(v:val, "^> ", "", "g")') + let lines = deepcopy(s:matched) if exists('a:1') let lines = map(lines, 'split(v:val, ''[\/]\ze[^\/]\+$'')[-1]') endif @@ -670,11 +643,20 @@ endfunc func! s:PrtClearCache() cal ctrlp#clearcache() cal s:SetLines(s:itemtype) - cal s:BuildPrompt() + cal s:BuildPrompt(1) +endfunc + +func! s:PrtExit() + if has('autocmd') && s:currwin + exe s:currwin.'winc w' + else + cal s:BufOpen('ControlP', 'del') + endif endfunc func! s:PrtHistory(...) if !s:maxhst | retu | endif + let s:matches = 1 let prt = g:CtrlP_prompt let str = prt[0] . prt[1] . prt[2] let hst = s:hstry @@ -687,7 +669,7 @@ func! s:PrtHistory(...) let g:CtrlP_prompt = [hst[idx], '', ''] let s:hisidx = idx let s:hstgot = 1 - cal s:BuildPrompt() + cal s:BuildPrompt(1) endfunc "}}} @@ -697,7 +679,7 @@ func! s:MapKeys(...) let func = !exists('a:1') || ( exists('a:1') && a:1 ) ? 'PrtAdd' : 'PrtSelectJump' let sjbyfname = s:byfname && func == 'PrtSelectJump' ? ', 1' : '' for each in range(32,126) - exe "nn \ \ \ :cal \".func."(\"".escape(nr2char(each), '"|\')."\"".sjbyfname.")\" + exe "nn \ \ \ :cal \".func."(\"".escape(nr2char(each), '"|\')."\"".sjbyfname.")\" endfor if exists('a:2') | retu | endif " Special keystrokes @@ -710,33 +692,32 @@ endfunc func! s:MapSpecs(...) let prtmaps = { - \ 'PrtBS()': [''], - \ 'PrtDelete()': [''], - \ 'PrtDeleteWord()': [''], - \ 'PrtClear()': [''], - \ 'PrtSelectMove("j")': ['', ''], - \ 'PrtSelectMove("k")': ['', ''], - \ 'PrtHistory(-1)': [''], - \ 'PrtHistory(1)': [''], - \ 'AcceptSelection("e")': [''], - \ 'AcceptSelection("h")': ['', '', ''], - \ 'AcceptSelection("t")': [''], - \ 'AcceptSelection("v")': ['', ''], - \ 'ToggleFocus()': [''], - \ 'ToggleRegex()': [''], - \ 'ToggleByFname()': [''], - \ 'ToggleType(1)': ['', '', ''], - \ 'ForceUpdate()': [''], - \ 'PrtCurStart()': [''], - \ 'PrtCurEnd()': [''], - \ 'PrtCurLeft()': ['', ''], - \ 'PrtCurRight()': ['', ''], - \ 'PrtClearCache()': [''], - \ 'CreateNewFile()': [''], - \ 'MarkToOpen()': [''], - \ 'OpenMulti()': [''], - \ 'BufOpen("ControlP", "del")': ['', '', ''], + \ 'PrtBS()': [''], + \ 'PrtDelete()': [''], + \ 'PrtDeleteWord()': [''], + \ 'PrtClear()': [''], + \ 'PrtSelectMove("j")': ['', ''], + \ 'PrtSelectMove("k")': ['', ''], + \ 'PrtHistory(-1)': [''], + \ 'PrtHistory(1)': [''], + \ 'AcceptSelection("e")': [''], + \ 'AcceptSelection("h")': ['', '', ''], + \ 'AcceptSelection("t")': [''], + \ 'AcceptSelection("v")': ['', ''], + \ 'ToggleFocus()': [''], + \ 'ToggleRegex()': [''], + \ 'ToggleByFname()': [''], + \ 'ToggleType(1)': ['', '', ''], + \ 'PrtCurStart()': [''], + \ 'PrtCurEnd()': [''], + \ 'PrtCurLeft()': ['', ''], + \ 'PrtCurRight()': ['', ''], + \ 'PrtClearCache()': [''], + \ 'CreateNewFile()': [''], + \ 'MarkToOpen()': [''], + \ 'OpenMulti()': [''], + \ 'PrtExit()': ['', '', ''], \ } if type(s:urprtmaps) == 4 cal extend(prtmaps, s:urprtmaps) @@ -765,7 +746,7 @@ func! s:MapSpecs(...) endfor | endfor else for each in keys(prtmaps) | for kp in prtmaps[each] - exe lcmap kp ':cal '.each.'' + exe lcmap kp ':cal '.each.'' endfor | endfor endif endfunc @@ -779,8 +760,7 @@ endfunc func! s:ToggleFocus() let s:focus = !exists('s:focus') || s:focus ? 0 : 1 cal s:MapKeys(s:focus) - let s:firstinit = 1 - cal s:BuildPrompt(s:focus) + cal s:BuildPrompt(0,s:focus) endfunc func! s:ToggleRegex() @@ -808,9 +788,8 @@ func! s:Type(type) endfunc func! s:PrtSwitcher() - let s:nomatches = 1 - let s:firstinit = 1 - cal s:BuildPrompt(s:Focus()) + let s:matches = 1 + cal s:BuildPrompt(1,s:Focus()) endfunc "}}} @@ -838,8 +817,10 @@ func! ctrlp#SetWorkingPath(...) \ || !s:pathmode || !l:pathmode retu endif - if exists('+acd') | se noacd | endif - sil! exe 'chd!' exists('*fnameescape') ? fnameescape(expand('%:p:h')) : expand('%:p:h') + if exists('+acd') | let &acd = 0 | endif + let path = expand('%:p:h') + let path = exists('*fnameescape') ? fnameescape(path) : escape(path, '%#') + sil! exe 'chd!' path if s:pathmode == 1 || l:pathmode == 1 | retu | endif let markers = [ \ 'root.dir', @@ -878,23 +859,6 @@ func! s:AcceptSelection(mode,...) "{{{ if exists('a:1') && a:1 | retu filpath | endif " Manually remove the prompt and match window if !has('autocmd') | cal s:BufOpen('ControlP', 'del') | endif - " Record the input string - cal s:recordhist(str) - " Split the mode string if it's longer than 1 char - if len(md) > 1 - let mds = split(md, '\zs') - let md = mds[0] - endif - " Determine the command to use - if md == 't' || s:splitwin == 1 " In new tab - let cmd = 'e' - elseif md == 'h' || s:splitwin == 2 " In new hor split - let cmd = 'new' - elseif md == 'v' || s:splitwin == 3 " In new ver split - let cmd = 'vne' - elseif md == 'e' || !s:splitwin " In current window - let cmd = 'e' - endif let bufnum = bufnr(filpath) let bufwinnr = bufwinnr(bufnum) let norbuf = s:normbuf() @@ -931,8 +895,16 @@ func! s:AcceptSelection(mode,...) "{{{ elseif bufnum > 0 && bufwinnr > 0 " In a window exe bufwinnr.'winc w' else - " If mode is 'e' - if md == 'e' + " Determine the command to use + if md == 't' || s:splitwin == 1 " In new tab + tabnew + let cmd = 'e' + elseif md == 'h' || s:splitwin == 2 " In new hor split + let cmd = 'new' + elseif md == 'v' || s:splitwin == 3 " In new ver split + let cmd = 'vne' + elseif md == 'e' || !s:splitwin " In current window + let cmd = 'e' " If there's at least 1 normal buffer if norbuf " But not the current one @@ -944,8 +916,6 @@ func! s:AcceptSelection(mode,...) "{{{ " No normal buffers let cmd = 'vne' endif - elseif md == 't' - tabnew endif " Open new window/buffer sil! exe 'bo '.cmd.tail.' '.filpath @@ -1042,7 +1012,7 @@ func! s:statusline(...) let item = '%#Character# '.item.' %*' let slider = ' <'.prev.'>={'.item.'}=<'.next.'>' let dir = ' %=%<%#LineNr# '.getcwd().' %*' - let marked = s:opmul ? exists('s:marked') ? ' <+'.len(s:marked).'>' : ' <+>' : '' + let marked = s:opmul ? exists('s:marked') ? ' <'.s:dismarks(s:marked).'>' : ' <+>' : '' let &l:stl = focus.byfname.regex.slider.marked.dir endfunc @@ -1052,6 +1022,21 @@ func! s:progress(len) let &l:stl = cnt.dir redr endfunc + +func! s:dismarks(marked) + let marked = deepcopy(a:marked) + cal map(marked, 'split(v:val, "[\\/]")[-1]') + if has('signs') + let str = '+'.len(marked) + else + let str = '%<' + for each in values(marked) + let str .= ', '.each + endfor + let str = substitute(str, ', ', '', '') + endif + retu str +endfunc "}}} " Paths {{{ @@ -1074,6 +1059,21 @@ func! s:createparentdirs(arr) endfor retu curr endfunc + +func! s:listdirs(path,parent) + let str = '' + for entry in filter(split(globpath(a:path, '*'), '\n'), 'isdirectory(v:val)') + let str .= a:parent.split(entry, '[\/]')[-1] . "\n" + endfor + retu str +endfunc + +func! ctrlp#compl(A,L,P) + let haslash = match(a:A, '[\/]') + let parent = substitute(a:A, '[^\/]*$', '', 'g') + let path = !haslash ? parent : haslash > 0 ? getcwd().s:lash.parent : getcwd() + retu s:listdirs(path,parent) +endfunc "}}} " Highlighting {{{ @@ -1133,7 +1133,6 @@ endfunc func! s:remarksigns(nls) if !s:dosigns() | retu | endif let nls = deepcopy(a:nls) - cal map(nls, 'substitute(v:val, "^> ", "", "g")') let ic = 1 while ic <= len(nls) let filpath = s:itemtype ? nls[ic - 1] : getcwd().s:lash.nls[ic - 1] @@ -1150,6 +1149,62 @@ func! s:dosigns() endfunc "}}} +" Dictionaries {{{ +func! s:dictindex(dict, expr) + for key in keys(a:dict) + let val = a:dict[key] + if val == a:expr + retu key + endif + endfor + retu -1 +endfunc + +func! s:vacantdict(dict) + let vac = [] + for ic in range(1, max(keys(a:dict))) + if !has_key(a:dict, ic) + cal add(vac, ic) + endif + endfor + retu vac +endfunc +"}}} + +" Buffers {{{ +func! s:normbuf() + if &l:bl && empty(&l:bt) && &l:ma | retu winnr() | endif + for each in range(1, winnr('$')) + let bufnr = winbufnr(each) + if getbufvar(bufnr, '&bl') && empty(getbufvar(bufnr, '&bt')) + \ && getbufvar(bufnr, '&ma') + retu each + endif + endfor + retu 0 +endfunc + +func! s:setupblank() + setl noswf nobl nonu nowrap nolist nospell cul nocuc wfh tw=0 bt=nofile bh=unload + if v:version >= '703' + setl nornu noudf cc=0 + endif +endfunc + +func! s:leavepre() + if s:cconex | cal ctrlp#clearallcaches() | endif + cal ctrlp#utils#writecache(s:hstry, s:gethistloc()[0], s:gethistloc()[1]) +endfunc + +func! s:checkbuf() + if exists('s:init') | retu | endif + if exists('s:bufnr') && s:bufnr > 0 + exe s:bufnr.'bw!' + unl! s:bufnr + endif +endfunc +"}}} + " Misc {{{ func! s:walker(max, pos, dir, ...) if a:dir == 1 @@ -1172,40 +1227,6 @@ func! s:maxfiles(len) retu s:maxfiles && a:len > s:maxfiles ? 1 : 0 endfunc -func! s:dictindex(dict, expr) - for key in keys(a:dict) - let val = a:dict[key] - if val == a:expr - retu key - endif - endfor - retu -1 -endfunc - -func! s:vacantdict(dict) - let vac = [] - for ic in range(1, max(keys(a:dict))) - if !has_key(a:dict, ic) - cal add(vac, ic) - endif - endfor - retu vac -endfunc - -func! s:normbuf() - if &l:bl && empty(&l:bt) && &l:ma | retu winnr() | endif - for each in range(1, winnr('$')) - winc w - if &l:bl && empty(&l:bt) && &l:ma | retu each | endif - endfor - retu 0 -endfunc - -func! s:leavepre() - if s:cconex | cal ctrlp#clearallcaches() | endif - cal ctrlp#utils#writecache(s:hstry, s:gethistloc()[0], s:gethistloc()[1]) -endfunc - func! s:insertcache(str) let cache_file = ctrlp#utils#cachefile() if filereadable(cache_file) @@ -1236,7 +1257,8 @@ endfunc if has('autocmd') "{{{ aug CtrlPAug au! - au WinLeave,BufLeave ControlP cal s:BufOpen('ControlP', 'del') + au BufEnter ControlP cal s:checkbuf() + au BufLeave ControlP cal s:BufOpen('ControlP', 'del') au VimLeavePre * cal s:leavepre() aug END endif "}}} @@ -1253,15 +1275,16 @@ func! s:SetLines(type) endfunc func! ctrlp#init(type, ...) - let s:nomatches = 1 - let s:firstinit = 1 + if exists('s:init') | retu | endif + let s:matches = 1 + let s:init = 1 let a1 = exists('a:1') ? a:1 : '' cal ctrlp#SetWorkingPath(a1) cal s:BufOpen('ControlP') - cal s:SetupBlank() + cal s:setupblank() cal s:MapKeys() cal s:SetLines(a:type) - cal s:BuildPrompt() + cal s:BuildPrompt(1) cal s:syntax() endfunc "}}} diff --git a/autoload/ctrlp/mrufiles.vim b/autoload/ctrlp/mrufiles.vim index 56b0766..3428574 100644 --- a/autoload/ctrlp/mrufiles.vim +++ b/autoload/ctrlp/mrufiles.vim @@ -12,7 +12,7 @@ endif "}}} " Option variables {{{ func! ctrlp#mrufiles#opts() if !exists('g:ctrlp_mruf_max') - let s:max = 50 + let s:max = 150 else let s:max = g:ctrlp_mruf_max unl g:ctrlp_mruf_max diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index 12bb672..5a48974 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -1,4 +1,4 @@ -*ctrlp.txt* Full path fuzzy file, buffer and MRU file finder. v1.5 +*ctrlp.txt* Full path fuzzy file, buffer and MRU file finder. v1.5.1 *CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'* =============================================================================== # # @@ -25,7 +25,8 @@ CONTENTS *ctrlp-contents* Full path fuzzy file, buffer and MRU file finder with an intuitive interface. Written in pure Vimscript for MacVim and Vim version 7.0+. Has full support for -Vim’s |regexp| as search pattern, and more. +Vim’s |regexp| as search pattern, built-in MRU monitoring, project’s root +finder, and more. See also |ctrlp-input-formats| and |ctrlp-fullregexp|. @@ -54,15 +55,6 @@ Set this to 1 to set full |regexp| search as the default mode: > let g:ctrlp_regexp_search = 0 < - *'g:ctrlp_persistent_input'* -Remember the last input string: - 1 - Remember the last input string. - 2 - Also remember the position of the selection in the match window. - 0 - Clear the input field each time CtrlP starts. -> - let g:ctrlp_persistent_input = 0 -< - *'g:ctrlp_match_window_reversed'* Reverse the sort order of the matched files in the match window. The default setting is from bottom to top: > @@ -133,33 +125,32 @@ Set the parent directory for the '.ctrlp_cache' directory: > Use this to customize the mappings inside |CtrlP|’s prompt to your liking. You only need to keep the lines that you’ve changed the values (inside []): > let g:ctrlp_prompt_mappings = { - \ 'PrtBS()': [''], - \ 'PrtDelete()': [''], - \ 'PrtDeleteWord()': [''], - \ 'PrtClear()': [''], - \ 'PrtSelectMove("j")': ['', ''], - \ 'PrtSelectMove("k")': ['', ''], - \ 'PrtHistory(-1)': [''], - \ 'PrtHistory(1)': [''], - \ 'AcceptSelection("e")': [''], - \ 'AcceptSelection("h")': ['', '', ''], - \ 'AcceptSelection("t")': [''], - \ 'AcceptSelection("v")': [''], - \ 'ToggleFocus()': [''], - \ 'ToggleRegex()': [''], - \ 'ToggleByFname()': [''], - \ 'ToggleType(1)': ['', '', ''], - \ 'ForceUpdate()': [''], - \ 'PrtCurStart()': [''], - \ 'PrtCurEnd()': [''], - \ 'PrtCurLeft()': ['', ''], - \ 'PrtCurRight()': ['', ''], - \ 'PrtClearCache()': [''], - \ 'CreateNewFile()': [''], - \ 'MarkToOpen()': [''], - \ 'OpenMulti()': [''], - \ 'BufOpen("ControlP", "del")': ['', '', ''], + \ 'PrtBS()': [''], + \ 'PrtDelete()': [''], + \ 'PrtDeleteWord()': [''], + \ 'PrtClear()': [''], + \ 'PrtSelectMove("j")': ['', ''], + \ 'PrtSelectMove("k")': ['', ''], + \ 'PrtHistory(-1)': [''], + \ 'PrtHistory(1)': [''], + \ 'AcceptSelection("e")': [''], + \ 'AcceptSelection("h")': ['', '', ''], + \ 'AcceptSelection("t")': [''], + \ 'AcceptSelection("v")': ['', ''], + \ 'ToggleFocus()': [''], + \ 'ToggleRegex()': [''], + \ 'ToggleByFname()': [''], + \ 'ToggleType(1)': ['', '', ''], + \ 'PrtCurStart()': [''], + \ 'PrtCurEnd()': [''], + \ 'PrtCurLeft()': ['', ''], + \ 'PrtCurRight()': ['', ''], + \ 'PrtClearCache()': [''], + \ 'CreateNewFile()': [''], + \ 'MarkToOpen()': [''], + \ 'OpenMulti()': [''], + \ 'PrtExit()': ['', '', ''], \ } < @@ -170,7 +161,7 @@ Set this to 0 to completely disable the Most Recently Used files feature: > *'g:ctrlp_mruf_max'* Specify the number of recently opened files you want |CtrlP| to remember: > - let g:ctrlp_mruf_max = 50 + let g:ctrlp_mruf_max = 150 < *'g:ctrlp_mruf_exclude'* @@ -208,7 +199,7 @@ this. *'g:ctrlp_highlight_match'* Use this to enable/disable highlighting of the matched patterns and to specify the highlight group that’ll be used: > - let g:ctrlp_highlight_match = [1, 'Function'] + let g:ctrlp_highlight_match = [1, 'Identifier'] < *'g:ctrlp_max_files'* @@ -222,12 +213,6 @@ The maximum depth of a directory tree to recurse into: > < Note: the larger the value, the more memory Vim uses. - *'g:ctrlp_live_update'* -Set to 0 to disable the update-as-you-type functionality; press to force -an update: > - let g:ctrlp_live_update = 1 -< - *'g:ctrlp_user_command'* Specify an external tool to use for indexing files instead of Vim’s globpath(). Use %s in place of the target directory: > @@ -277,6 +262,7 @@ files, each in a vertical split. Open the |CtrlP| prompt in find files mode. If no argument is given, the value of |g:ctrlp_working_path_mode| will be used to determine the starting directory. + You can use to auto-complete the path when typing it. *:CtrlPBuffer* :CtrlPBuffer @@ -407,10 +393,6 @@ Once inside the prompt: Refresh the match window and purge the cache for the current directory. - - Force update the match window. - You only need to use this if |g:ctrlp_live_update| has been set to 0. - , , @@ -472,6 +454,8 @@ liked the way Command-T and LustyExplorer deal with user’s input, so I wrote a pure Vimscript version of their prompt window, intended to use it for the aforementioned plugin. +Homepage: http://kien.github.com/ctrlp.vim + Git repository: https://github.com/kien/ctrlp.vim Mercurial repository: https://bitbucket.org/kien/ctrlp.vim @@ -480,9 +464,11 @@ CHANGELOG + New features: Open multiple files. Pass Vim’s ++opt and +cmd to the opening file (section 5.c) + Auto-complete each dir for |:CtrlP| [starting-directory] + New mappings: mark/unmark a file to be opened with . open all marked files. + New option: |g:ctrlp_open_multi| + + Remove |g:ctrlp_persistent_input|, |g:ctrlp_live_update| and . Before 2011/09/29 @@ -524,5 +510,7 @@ Before 2011/09/12 |g:ctrlp_mruf_include| + New command: |:CtrlPMRUFiles| +First public release: 2011/09/06 + =============================================================================== vim:et:ts=2:sw=2:sts=2 diff --git a/plugin/ctrlp.vim b/plugin/ctrlp.vim index db79db2..d6b672a 100644 --- a/plugin/ctrlp.vim +++ b/plugin/ctrlp.vim @@ -4,6 +4,7 @@ " Author: Kien Nguyen " License: MIT " ============================================================================= +" GetLatestVimScripts: 3736 1 :AutoInstall: ctrlp.zip if ( exists('g:loaded_ctrlp') && g:loaded_ctrlp ) || v:version < '700' || &cp fini @@ -13,7 +14,8 @@ let g:loaded_ctrlp = 1 if !exists('g:ctrlp_map') | let g:ctrlp_map = '' | endif if !exists('g:ctrlp_mru_files') | let g:ctrlp_mru_files = 1 | endif -com! -nargs=? CtrlP cal ctrlp#init(0, ) +com! -nargs=? -complete=custom,ctrlp#compl CtrlP cal ctrlp#init(0, ) + com! CtrlPBuffer cal ctrlp#init(1) com! CtrlPMRUFiles cal ctrlp#init(2) com! ClearCtrlPCache cal ctrlp#clearcache() diff --git a/readme.md b/readme.md index dc13427..e134d11 100644 --- a/readme.md +++ b/readme.md @@ -2,8 +2,9 @@ Full path fuzzy __file__, __buffer__ and __MRU__ file finder for Vim. * Written in pure Vimscript for MacVim and Vim 7.0+. -* Has full support for Vim’s regexp as search pattern. -* Can also find file in most recently used files. +* Full support for Vim’s regexp as search pattern. +* Built-in Most Recently Used (MRU) files monitoring. +* Built-in project’s root finder. ![ctrlp][1]