Find root with '/' and '\'

* Submit '/' or '\' to find the project's root. Close #30.
* Add wig flag to glob() and globpath() in addition to expand().
* Make handling working directory less intrusive.
This commit is contained in:
Kien N 2011-11-12 22:00:50 +07:00
parent 72b7ab4883
commit 0af1cdc791
6 changed files with 281 additions and 262 deletions

View File

@ -1,15 +1,15 @@
" ============================================================================= " =============================================================================
" File: autoload/ctrlp.vim " File: autoload/ctrlp.vim
" Description: Full path fuzzy file, buffer and MRU file finder for Vim " Description: Fuzzy file, buffer and MRU file finder.
" Author: Kien Nguyen <github.com/kien> " Author: Kien Nguyen <github.com/kien>
" Version: 1.5.9 " Version: 1.6.0
" ============================================================================= " =============================================================================
" Static variables {{{ " Static variables {{{
fu! s:opts() fu! s:opts()
let opts = { let opts = {
\ 'g:ctrlp_by_filename': ['s:byfname', 0], \ 'g:ctrlp_by_filename': ['s:byfname', 0],
\ 'g:ctrlp_clear_cache_on_exit': ['s:cconex', 1], \ 'g:ctrlp_clear_cache_on_exit': ['s:clrex', 1],
\ 'g:ctrlp_dont_split': ['s:nosplit', ''], \ 'g:ctrlp_dont_split': ['s:nosplit', ''],
\ 'g:ctrlp_dotfiles': ['s:dotfiles', 1], \ 'g:ctrlp_dotfiles': ['s:dotfiles', 1],
\ 'g:ctrlp_extensions': ['s:extensions', []], \ 'g:ctrlp_extensions': ['s:extensions', []],
@ -20,7 +20,7 @@ fu! s:opts()
\ 'g:ctrlp_max_depth': ['s:maxdepth', 40], \ 'g:ctrlp_max_depth': ['s:maxdepth', 40],
\ 'g:ctrlp_max_files': ['s:maxfiles', 20000], \ 'g:ctrlp_max_files': ['s:maxfiles', 20000],
\ 'g:ctrlp_max_height': ['s:mxheight', 10], \ 'g:ctrlp_max_height': ['s:mxheight', 10],
\ 'g:ctrlp_open_multi': ['s:opmul', 1], \ 'g:ctrlp_open_multi': ['s:opmul', '1v'],
\ 'g:ctrlp_open_new_file': ['s:newfop', 3], \ 'g:ctrlp_open_new_file': ['s:newfop', 3],
\ 'g:ctrlp_prompt_mappings': ['s:urprtmaps', 0], \ 'g:ctrlp_prompt_mappings': ['s:urprtmaps', 0],
\ 'g:ctrlp_regexp_search': ['s:regexp', 0], \ 'g:ctrlp_regexp_search': ['s:regexp', 0],
@ -42,8 +42,7 @@ fu! s:opts()
let s:glob = s:dotfiles ? '.*\|*' : '*' let s:glob = s:dotfiles ? '.*\|*' : '*'
let s:cache_dir = exists('g:ctrlp_cache_dir') ? g:ctrlp_cache_dir : $HOME let s:cache_dir = exists('g:ctrlp_cache_dir') ? g:ctrlp_cache_dir : $HOME
let s:maxdepth = min([s:maxdepth, 100]) let s:maxdepth = min([s:maxdepth, 100])
let s:mru = g:ctrlp_mru_files let g:ctrlp_builtins = 2
let g:ctrlp_builtins = s:mru + 1
if !empty(s:extensions) | for each in s:extensions if !empty(s:extensions) | for each in s:extensions
exe 'ru autoload/ctrlp/'.each.'.vim' exe 'ru autoload/ctrlp/'.each.'.vim'
endfo | en endfo | en
@ -53,19 +52,20 @@ cal s:opts()
let s:lash = ctrlp#utils#lash() let s:lash = ctrlp#utils#lash()
" Global options " Global options
let s:glbs = { 'magic': 1, 'to': 1, 'tm': 0, 'sb': 1, 'hls': 0, let s:glbs = { 'magic': 1, 'to': 1, 'tm': 0, 'sb': 1, 'hls': 0, 'im': 0,
\ 'im': 0, 'report': 9999, 'sc': 0, 'ss': 0, 'siso': 0, \ 'report': 9999, 'sc': 0, 'ss': 0, 'siso': 0, 'mfd': 200, 'mouse': 'n',
\ 'mfd': 200, 'gcr': 'a:block-PmenuSel-blinkon0', 'mouse': 'n' } \ 'gcr': 'a:block-PmenuSel-blinkon0' }
" Limiters " Limiters
let [s:compare_lim, s:nocache_lim, s:mltipats_lim] = [3000, 4000, 2000] let [s:compare_lim, s:nocache_lim, s:mltipats_lim] = [3000, 4000, 2000]
"}}} "}}}
" * Open & Close {{{ " * Open & Close {{{
fu! s:Open() fu! s:Open()
let s:winres = winrestcmd() let [s:cwd, s:winres] = [getcwd(), winrestcmd()]
let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)]
sil! exe s:mwbottom ? 'bo' : 'to' '1new ControlP' sil! exe s:mwbottom ? 'bo' : 'to' '1new ControlP'
let s:currwin = s:mwbottom ? winnr('#') : winnr('#') + 1 let s:currwin = s:mwbottom ? winnr('#') : winnr('#') + 1
let [s:winnr, s:bufnr, s:prompt] = [bufwinnr('%'), bufnr('%'), ['', '', '']] let [s:bufnr, s:prompt] = [bufnr('%'), ['', '', '']]
abc <buffer> abc <buffer>
if !exists('s:hstry') if !exists('s:hstry')
let hst = filereadable(s:gethistloc()[1]) ? s:gethistdata() : [''] let hst = filereadable(s:gethistloc()[1]) ? s:gethistdata() : ['']
@ -88,40 +88,43 @@ fu! s:Close()
endfo endfo
if exists('s:glb_acd') | let &acd = s:glb_acd | en if exists('s:glb_acd') | let &acd = s:glb_acd | en
let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []] let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []]
sil! exe 'chd!' s:cwd
exe s:winres exe s:winres
unl! s:focus s:hisidx s:hstgot s:marked s:winnr s:statypes s:cline s:cwd unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr
\ s:init s:savestr s:winres \ s:crfile s:crfpath
cal s:recordhist(join(s:prompt, '')) cal s:recordhist(join(s:prompt, ''))
ec ec
endf endf
"}}} "}}}
" * Clear caches {{{ " * Clear caches {{{
fu! ctrlp#clearcache() fu! ctrlp#clr()
let g:ctrlp_newcache = 1 let g:ctrlp_newcache = 1
endf endf
fu! ctrlp#clearallcaches() fu! ctrlp#clra(...)
if !exists('a:1') && ( has('dialog_gui') || has('dialog_con') ) &&
\ confirm("Delete all cache files?", "&OK\n&Cancel") != 1 | retu | en
let cache_dir = ctrlp#utils#cachedir() let cache_dir = ctrlp#utils#cachedir()
if isdirectory(cache_dir) && match(cache_dir, '.ctrlp_cache') >= 0 if isdirectory(cache_dir)
let cache_files = split(globpath(cache_dir, '*.txt'), '\n') let cache_files = split(s:glbpath(cache_dir, '*.txt', 1), "\n")
cal filter(cache_files, '!isdirectory(v:val)') cal filter(cache_files, '!isdirectory(v:val)')
sil! cal map(cache_files, 'delete(v:val)') sil! cal map(cache_files, 'delete(v:val)')
en en
cal ctrlp#clearcache() cal ctrlp#clr()
endf endf
fu! ctrlp#reset() fu! ctrlp#reset()
if ( has('dialog_gui') || has('dialog_con') ) &&
\ confirm("Reset and apply new options?", "&OK\n&Cancel") != 1 | retu | en
cal s:opts() cal s:opts()
cal ctrlp#utils#opts() cal ctrlp#utils#opts()
if s:mru | cal ctrlp#mrufiles#opts() | en cal ctrlp#mrufiles#opts()
let s:prompt = ['', '', ''] let s:prompt = ['', '', '']
unl! s:cline unl! s:cline
endf endf
"}}} "}}}
" * Files() {{{ " * Files() {{{
fu! s:GlobPath(dirs, allfiles, depth) fu! s:GlobPath(dirs, allfiles, depth)
let entries = split(globpath(a:dirs, s:glob), '\n') let entries = split(globpath(a:dirs, s:glob), "\n")
let entries = filter(entries, 'getftype(v:val) != "link"') let entries = filter(entries, 'getftype(v:val) != "link"')
let g:ctrlp_allfiles = filter(copy(entries), '!isdirectory(v:val)') let g:ctrlp_allfiles = filter(copy(entries), '!isdirectory(v:val)')
let ftrfunc = s:dotfiles ? 's:dirfilter(v:val)' : 'isdirectory(v:val)' let ftrfunc = s:dotfiles ? 's:dirfilter(v:val)' : 'isdirectory(v:val)'
@ -140,7 +143,7 @@ fu! s:UserCommand(path, lscmd)
let [ssl, &ssl, path] = [&ssl, 0, tr(path, '/', '\')] let [ssl, &ssl, path] = [&ssl, 0, tr(path, '/', '\')]
en en
let path = exists('*shellescape') ? shellescape(path) : path let path = exists('*shellescape') ? shellescape(path) : path
let g:ctrlp_allfiles = split(system(printf(a:lscmd, path)), '\n') let g:ctrlp_allfiles = split(system(printf(a:lscmd, path)), "\n")
if exists('+ssl') && exists('ssl') if exists('+ssl') && exists('ssl')
let &ssl = ssl let &ssl = ssl
cal map(g:ctrlp_allfiles, 'tr(v:val, "\\", "/")') cal map(g:ctrlp_allfiles, 'tr(v:val, "\\", "/")')
@ -223,7 +226,7 @@ fu! s:MatchedItems(items, pats, limit)
retu newitems retu newitems
endf endf
"}}} "}}}
fu! s:SplitPattern(str,...) "{{{ fu! s:SplitPattern(str, ...) "{{{
let str = s:sanstail(a:str) let str = s:sanstail(a:str)
let s:savestr = str let s:savestr = str
if s:regexp || match(str, '\\\(zs\|ze\|<\|>\)\|[*|]') >= 0 if s:regexp || match(str, '\\\(zs\|ze\|<\|>\)\|[*|]') >= 0
@ -255,39 +258,39 @@ endf "}}}
fu! s:Render(lines, pat) fu! s:Render(lines, pat)
let lines = a:lines let lines = a:lines
" Setup the match window " Setup the match window
sil! exe '%d _ | res' min([len(lines), s:mxheight]) let s:height = min([len(lines), s:mxheight])
sil! exe '%d _ | res' s:height
" Print the new items " Print the new items
if empty(lines) if empty(lines)
setl nocul setl nocul
cal setline(1, ' == NO MATCHES ==') cal setline(1, ' == NO MATCHES ==')
cal s:unmarksigns() cal s:unmarksigns()
el retu
setl cul
" Sort if not MRU
if ( s:mru && s:itemtype != 2 ) || !s:mru
let s:compat = a:pat
cal sort(lines, 's:mixedsort')
unl s:compat
en
if s:mwreverse | cal reverse(lines) | en
let s:matched = copy(lines)
cal map(lines, 'substitute(v:val, "^", "> ", "")')
cal setline(1, lines)
exe 'keepj norm!' s:mwreverse ? 'G' : 'gg'
keepj norm! 1|
cal s:unmarksigns()
cal s:remarksigns()
en en
setl cul
" Sort if not MRU
if s:itemtype != 2 || !empty(join(s:prompt, ''))
let s:compat = a:pat
cal sort(lines, 's:mixedsort')
unl s:compat
en
if s:mwreverse | cal reverse(lines) | en
let s:matched = copy(lines)
cal map(lines, 'substitute(v:val, "^", "> ", "")')
cal setline(1, lines)
exe 'keepj norm!' s:mwreverse ? 'G' : 'gg'
keepj norm! 1|
cal s:unmarksigns()
cal s:remarksigns()
if exists('s:cline') | cal cursor(s:cline, 1) | en if exists('s:cline') | cal cursor(s:cline, 1) | en
" Highlighting " Highlighting
if type(s:mathi) == 3 && len(s:mathi) == 2 && s:mathi[0] if type(s:mathi) == 3 && len(s:mathi) == 2 && s:mathi[0]
\ && exists('*clearmatches') && !empty(lines) \ && exists('*clearmatches')
let grp = empty(s:mathi[1]) ? 'Identifier' : s:mathi[1] cal s:highlight(a:pat, empty(s:mathi[1]) ? 'Identifier' : s:mathi[1])
cal s:highlight(a:pat, grp)
en en
endf endf
fu! s:Update(pat,...) fu! s:Update(pat, ...)
let pat = a:pat let pat = a:pat
" Get the previous string if existed " Get the previous string if existed
let oldstr = exists('s:savestr') ? s:savestr : '' let oldstr = exists('s:savestr') ? s:savestr : ''
@ -299,11 +302,10 @@ fu! s:Update(pat,...)
retu retu
en en
let lines = s:MatchedItems(g:ctrlp_lines, pats, s:mxheight) let lines = s:MatchedItems(g:ctrlp_lines, pats, s:mxheight)
let pat = pats[-1] cal s:Render(lines, pats[-1])
cal s:Render(lines, pat)
endf endf
fu! s:BuildPrompt(upd,...) fu! s:BuildPrompt(upd, ...)
let base = ( s:regexp ? 'r' : '>' ).( s:byfname ? 'd' : '>' ).'> ' let base = ( s:regexp ? 'r' : '>' ).( s:byfname ? 'd' : '>' ).'> '
let [estr, prt] = ['"\', copy(s:prompt)] let [estr, prt] = ['"\', copy(s:prompt)]
cal map(prt, 'escape(v:val, estr)') cal map(prt, 'escape(v:val, estr)')
@ -365,8 +367,8 @@ fu! s:PrtDeleteWord()
let str = matchstr(str, '^.\+\W\ze\w\+$') let str = matchstr(str, '^.\+\W\ze\w\+$')
elsei match(str, '\w\W\+$') >= 0 elsei match(str, '\w\W\+$') >= 0
let str = matchstr(str, '^.\+\w\ze\W\+$') let str = matchstr(str, '^.\+\w\ze\W\+$')
elsei match(str, '[ ]\+$') >= 0 elsei match(str, '\s\+$') >= 0
let str = matchstr(str, '^.*[^ ]\+\ze[ ]\+$') let str = matchstr(str, '^.*[^ \t]\+\ze\s\+$')
elsei match(str, ' ') <= 0 elsei match(str, ' ') <= 0
let str = '' let str = ''
en en
@ -412,7 +414,7 @@ fu! s:PrtSelectMove(dir)
let s:cline = line('.') let s:cline = line('.')
endf endf
fu! s:PrtSelectJump(char,...) fu! s:PrtSelectJump(char, ...)
let lines = copy(s:matched) let lines = copy(s:matched)
if exists('a:1') if exists('a:1')
cal map(lines, 'split(v:val, ''[\/]\ze[^\/]\+$'')[-1]') cal map(lines, 'split(v:val, ''[\/]\ze[^\/]\+$'')[-1]')
@ -438,17 +440,26 @@ endf
" Hooks {{{ " Hooks {{{
fu! s:PrtClearCache() fu! s:PrtClearCache()
let s:force = 1 let s:force = 1
if s:itemtype == 0 if !s:itemtype
cal ctrlp#clearcache() cal ctrlp#clr()
cal s:SetLines(s:itemtype) cal s:SetLines(s:itemtype)
cal s:BuildPrompt(1) cal s:BuildPrompt(1)
elsei s:mru && s:itemtype == 2 elsei s:itemtype == 2
let g:ctrlp_lines = ctrlp#mrufiles#list(-1, 1) let g:ctrlp_lines = ctrlp#mrufiles#list(-1, 1)
cal s:BuildPrompt(1) cal s:BuildPrompt(1)
en en
unl s:force unl s:force
endf endf
fu! s:PrtDeleteMRU()
if s:itemtype == 2
let s:force = 1
let g:ctrlp_lines = ctrlp#mrufiles#list(-1, 2)
cal s:BuildPrompt(1)
unl s:force
en
endf
fu! s:PrtExit() fu! s:PrtExit()
if !has('autocmd') | cal s:Close() | en if !has('autocmd') | cal s:Close() | en
exe s:currwin.'winc w' exe s:currwin.'winc w'
@ -473,7 +484,7 @@ fu! s:MapKeys(...)
" Normal keys " Normal keys
let pfunc = exists('a:1') && !a:1 ? 'PrtSelectJump' : 'PrtAdd' let pfunc = exists('a:1') && !a:1 ? 'PrtSelectJump' : 'PrtAdd'
let dojmp = s:byfname && pfunc == 'PrtSelectJump' ? ', 1' : '' let dojmp = s:byfname && pfunc == 'PrtSelectJump' ? ', 1' : ''
for each in range(32,126) for each in range(32, 126)
let cmd = "nn \<buffer> \<silent> \<char-%d> :\<c-u>cal \<SID>%s(\"%s\"%s)\<cr>" let cmd = "nn \<buffer> \<silent> \<char-%d> :\<c-u>cal \<SID>%s(\"%s\"%s)\<cr>"
exe printf(cmd, each, pfunc, escape(nr2char(each), '"|\'), dojmp) exe printf(cmd, each, pfunc, escape(nr2char(each), '"|\'), dojmp)
endfo endfo
@ -506,12 +517,13 @@ fu! s:MapSpecs(...)
\ 'PrtCurLeft()': ['<c-h>', '<left>'], \ 'PrtCurLeft()': ['<c-h>', '<left>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'], \ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'PrtClearCache()': ['<F5>'], \ 'PrtClearCache()': ['<F5>'],
\ 'PrtDeleteMRU()': ['<F8>'],
\ 'CreateNewFile()': ['<c-y>'], \ 'CreateNewFile()': ['<c-y>'],
\ 'MarkToOpen()': ['<c-z>'], \ 'MarkToOpen()': ['<c-z>'],
\ 'OpenMulti()': ['<c-o>'], \ 'OpenMulti()': ['<c-o>'],
\ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'], \ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
\ }] \ }]
if type(s:urprtmaps) == 4 && !empty(s:urprtmaps) if type(s:urprtmaps) == 4
cal extend(prtmaps, s:urprtmaps) cal extend(prtmaps, s:urprtmaps)
en en
" Correct arrow keys in terminal " Correct arrow keys in terminal
@ -584,30 +596,28 @@ fu! s:PrtSwitcher()
cal s:BuildPrompt(1, s:Focus(), 1) cal s:BuildPrompt(1, s:Focus(), 1)
endf endf
"}}} "}}}
fu! ctrlp#SetWorkingPath(...) "{{{ fu! s:SetWD(...) "{{{
let [pathmode, s:cwd] = [s:pathmode, getcwd()] let pathmode = s:pathmode
if exists('a:1') && len(a:1) == 1 && !type(a:1) if exists('a:1') && len(a:1) == 1 && !type(a:1)
let pathmode = a:1 let pathmode = a:1
elsei exists('a:1') && len(a:1) > 1 && type(a:1) elsei exists('a:1') && len(a:1) > 1 && type(a:1)
sil! exe 'chd!' a:1 cal s:setdir(a:1) | retu
retu
en en
if match(expand('%:p', 1), '^\<.\+\>://.*') >= 0 || !pathmode if !exists('a:2')
retu if match(s:crfile, '^\<.\+\>://.*') >= 0 || !pathmode | retu | en
if exists('+acd') | let [s:glb_acd, &acd] = [&acd, 0] | en
cal s:setdir(s:crfpath)
en en
if exists('+acd') | let [s:glb_acd, &acd] = [&acd, 0] | en
let path = expand('%:p:h', 1)
let path = exists('*fnameescape') ? fnameescape(path) : escape(path, '%#')
sil! exe 'chd!' path
if pathmode == 1 | retu | en if pathmode == 1 | retu | en
let markers = ['root.dir','.git/','.hg/','.vimprojects','_darcs/','.bzr/'] let markers = ['root.dir','.git/','.hg/','.vimprojects','_darcs/','.bzr/']
if type(s:rmarkers) == 3 && !empty(s:rmarkers) if type(s:rmarkers) == 3 && !empty(s:rmarkers)
cal extend(markers, s:rmarkers, 0) cal extend(markers, s:rmarkers, 0)
en en
for marker in markers for marker in markers
let found = s:findroot(getcwd(), marker, 0, 0) cal s:findroot(getcwd(), marker, 0, 0)
if getcwd() != expand('%:p:h', 1) || found | brea | en if exists('s:foundroot') | brea | en
endfo endfo
unl! s:foundroot
endf "}}} endf "}}}
" * AcceptSelection() {{{ " * AcceptSelection() {{{
fu! ctrlp#acceptfile(mode, matchstr) fu! ctrlp#acceptfile(mode, matchstr)
@ -644,29 +654,14 @@ fu! ctrlp#acceptfile(mode, matchstr)
endf endf
fu! s:AcceptSelection(mode) fu! s:AcceptSelection(mode)
if a:mode == 'e' if a:mode == 'e' | if s:specinputs() | retu | en | en
let str = join(s:prompt, '')
if str == '..' && !s:itemtype
cal s:parentdir(getcwd())
cal s:SetLines(s:itemtype)
cal s:PrtClear()
retu
elsei str == '?'
cal s:PrtExit()
let hlpwin = &columns > 159 ? '| vert res 80' : ''
sil! exe 'bo vert h ctrlp-mappings' hlpwin '| norm! 0'
retu
en
en
" Get the selected line " Get the selected line
let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$') let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$')
if empty(matchstr) | retu | en if empty(matchstr) | retu | en
" Do something with it " Do something with it
let rhs = s:mru ? '0\|1\|2' : '0\|1' let actfunc = s:itemtype =~ '0\|1\|2' ? 'ctrlp#acceptfile'
let actfunc = s:itemtype =~ rhs ? 'ctrlp#acceptfile'
\ : g:ctrlp_ext_vars[s:itemtype - ( g:ctrlp_builtins + 1 )][1] \ : g:ctrlp_ext_vars[s:itemtype - ( g:ctrlp_builtins + 1 )][1]
cal call(actfunc, [a:mode, matchstr]) cal call(actfunc, [a:mode, matchstr])
ec
endf endf
"}}} "}}}
fu! s:CreateNewFile() "{{{ fu! s:CreateNewFile() "{{{
@ -747,14 +742,15 @@ fu! s:OpenMulti()
en en
if ntab | tabnew | en if ntab | tabnew | en
let [ic, wnr] = [1, exists('wnr') ? wnr : 1] let [ic, wnr] = [1, exists('wnr') ? wnr : 1]
let cmds = { 'v': 'vne', 'h': 'new', 't': 'tabe' }
let spt = len(s:opmul) > 1 ? cmds[s:opmul[1]] : 'vne'
exe wnr.'winc w' exe wnr.'winc w'
for key in keys(mkd) for key in keys(mkd)
let cmd = ic == 1 ? 'e' : 'vne' let cmd = ic == 1 ? 'e' : spt
cal s:openfile(cmd, mkd[key]) cal s:openfile(cmd, mkd[key])
if s:opmul > 1 && s:opmul < ic | clo! if s:opmul[0] > 1 && s:opmul[0] < ic | clo!
el | let ic += 1 | en el | let ic += 1 | en
endfo endfo
ec
endf endf
"}}} "}}}
" ** Helper functions {{{ " ** Helper functions {{{
@ -791,9 +787,9 @@ fu! s:matchlens(str, pat, ...)
let lens = exists('a:2') ? a:2 : {} let lens = exists('a:2') ? a:2 : {}
let nr = exists('a:3') ? a:3 : 0 let nr = exists('a:3') ? a:3 : 0
if match(a:str, a:pat, st) != -1 if match(a:str, a:pat, st) != -1
let [str, mend] = [matchstr(a:str, a:pat, st), matchend(a:str, a:pat, st)] let [mst, mnd] = [matchstr(a:str, a:pat, st), matchend(a:str, a:pat, st)]
let lens = extend(lens, { nr : [len(str), str] }) let lens = extend(lens, { nr : [len(mst), mst] })
let lens = s:matchlens(a:str, a:pat, mend, lens, nr + 1) let lens = s:matchlens(a:str, a:pat, mnd, lens, nr + 1)
en en
retu lens retu lens
endf endf
@ -814,14 +810,12 @@ fu! s:wordonly(lens)
endf endf
fu! s:mixedsort(s1, s2) fu! s:mixedsort(s1, s2)
let [cmatlen, clen] = [s:compmatlen(a:s1, a:s2), s:complen(a:s1, a:s2)] let [cml, cln] = [s:compmatlen(a:s1, a:s2), s:complen(a:s1, a:s2)]
let rhs = s:mru ? '0\|1\|2' : '0\|1' if s:itemtype =~ '0\|1\|2' && s:height < 21
if s:itemtype =~ rhs let [ctm, wrd] = [s:comptime(a:s1, a:s2), s:compword(a:s1, a:s2)]
let [ctime, cword] = [s:comptime(a:s1, a:s2), s:compword(a:s1, a:s2)] retu 6 * cml + 3 * ctm + 2 * cln + wrd
retu 6 * cmatlen + 3 * ctime + 2 * clen + cword
el
retu 2 * cmatlen + clen
en en
retu 2 * cml + cln
endf endf
"}}} "}}}
" Statusline {{{ " Statusline {{{
@ -832,7 +826,6 @@ fu! s:statusline(...)
\ ['buffers', 'buf'], \ ['buffers', 'buf'],
\ ['mru files', 'mru'], \ ['mru files', 'mru'],
\ ] \ ]
if !s:mru | cal remove(s:statypes, 2) | en
if exists('g:ctrlp_ext_vars') | for each in g:ctrlp_ext_vars if exists('g:ctrlp_ext_vars') | for each in g:ctrlp_ext_vars
cal add(s:statypes, [ each[2], each[3] ]) cal add(s:statypes, [ each[2], each[3] ])
endfo | en endfo | en
@ -872,9 +865,7 @@ endf
fu! s:parentdir(curr) fu! s:parentdir(curr)
let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '') let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '')
if parent != a:curr if parent != a:curr | cal s:setdir(parent) | en
sil! exe 'lc!' parent
en
endf endf
fu! s:createparentdirs(arr) fu! s:createparentdirs(arr)
@ -885,15 +876,15 @@ fu! s:createparentdirs(arr)
retu curr retu curr
endf endf
fu! s:listdirs(path,parent) fu! s:listdirs(path, parent)
let str = '' let [str, dirs] = [split(s:glbpath(a:path, '*', 1), "\n"), '']
for entry in filter(split(globpath(a:path, '*'), '\n'), 'isdirectory(v:val)') for entry in filter(dirs, 'isdirectory(v:val)')
let str .= a:parent . split(entry, '[\/]')[-1] . "\n" let str .= a:parent . split(entry, '[\/]')[-1] . "\n"
endfo endfo
retu str retu str
endf endf
fu! ctrlp#compl(A,L,P) fu! ctrlp#cpl(A, L, P)
let haslash = match(a:A, '[\/]') let haslash = match(a:A, '[\/]')
let parent = substitute(a:A, '[^\/]*$', '', 'g') let parent = substitute(a:A, '[^\/]*$', '', 'g')
let path = !haslash ? parent : haslash > 0 ? getcwd().s:lash.parent : getcwd() let path = !haslash ? parent : haslash > 0 ? getcwd().s:lash.parent : getcwd()
@ -901,25 +892,36 @@ fu! ctrlp#compl(A,L,P)
endf endf
fu! s:findroot(curr, mark, depth, type) fu! s:findroot(curr, mark, depth, type)
let [depth, notfound] = [a:depth + 1, empty(globpath(a:curr, a:mark))] let [depth, notfound] = [a:depth + 1, empty(s:glbpath(a:curr, a:mark, 1))]
if !notfound || depth > s:maxdepth if !notfound || depth > s:maxdepth
if notfound if notfound | cal s:setdir(s:cwd) | en
if exists('s:cwd')
sil! exe 'chd!' s:cwd
en
retu 0
en
if a:type if a:type
let s:vcsroot = depth <= s:maxdepth ? a:curr : '' let s:vcsroot = depth <= s:maxdepth ? a:curr : ''
el el
sil! exe 'chd!' a:curr cal s:setdir(a:curr)
retu 1 let s:foundroot = 1
en en
el el
let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '') let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/:]\?$', '', '')
if parent != a:curr | cal s:findroot(parent, a:mark, depth, a:type) | en if parent != a:curr | cal s:findroot(parent, a:mark, depth, a:type) | en
en en
endf endf
fu! s:glbpath(...)
retu call('globpath', v:version > 701 ? [a:1, a:2, a:3] : [a:1, a:2])
endf
fu! s:fnesc(path)
retu exists('*fnameescape') ? fnameescape(a:path) : escape(a:path, " %#*?|<\"\n")
endf
fu! s:setdir(path)
try
exe 'lc!' s:fnesc(a:path)
cat
cal s:msg("Can't change working dir. Directory not exists.")
endt
endf
"}}} "}}}
" Highlighting {{{ " Highlighting {{{
fu! s:syntax() fu! s:syntax()
@ -1031,33 +1033,31 @@ fu! s:normbuf()
endf endf
fu! s:normcmd(cmd) fu! s:normcmd(cmd)
if !empty(s:nosplit) && match([bufname('%'), &l:ft], s:nosplit) >=0 if !empty(s:nosplit) && match([bufname('%'), &l:ft], s:nosplit) >= 0
retu a:cmd retu a:cmd
en en
" Find a regular buffer " Find a regular buffer
let norwins = s:normbuf() let norwins = s:normbuf()
let norwin = empty(norwins) ? 0 : norwins[0] let norwin = empty(norwins) ? 0 : norwins[0]
" If there's at least 1
if norwin if norwin
" But not the current
if index(norwins, winnr()) < 0 if index(norwins, winnr()) < 0
exe norwin.'winc w' exe norwin.'winc w'
en en
retu a:cmd retu a:cmd
el
retu 'bo vne'
en en
retu 'bo vne'
endf endf
fu! s:setupblank() fu! s:setupblank()
setl noswf nobl nonu nowrap nolist nospell cul nocuc wfh fdc=0 tw=0 bt=nofile bh=unload setl noswf nobl nonu nowrap nolist nospell nocuc wfh
setl fdc=0 fdl=99 tw=0 bt=nofile bh=unload
if v:version >= 703 if v:version >= 703
setl nornu noudf cc=0 setl nornu noudf cc=0
en en
endf endf
fu! s:leavepre() fu! s:leavepre()
if s:cconex | cal ctrlp#clearallcaches() | en if s:clrex | cal ctrlp#clra(1) | en
cal ctrlp#utils#writecache(s:hstry, s:gethistloc()[0], s:gethistloc()[1]) cal ctrlp#utils#writecache(s:hstry, s:gethistloc()[0], s:gethistloc()[1])
endf endf
@ -1084,20 +1084,38 @@ fu! s:sanstail(str)
if match(str, ':\([^:]\|\\:\)*$') >= 0 if match(str, ':\([^:]\|\\:\)*$') >= 0
let s:optail = matchstr(str, ':\zs\([^:]\|\\:\)*$') let s:optail = matchstr(str, ':\zs\([^:]\|\\:\)*$')
retu substitute(str, ':\([^:]\|\\:\)*$', '', 'g') retu substitute(str, ':\([^:]\|\\:\)*$', '', 'g')
el
retu str
en en
retu str
endf endf
"}}} "}}}
" Misc {{{ " Misc {{{
fu! s:specinputs()
let str = join(s:prompt, '')
if str == '..' && !s:itemtype
cal s:parentdir(getcwd())
cal s:SetLines(0)
cal s:PrtClear()
retu 1
elsei ( str == '/' || str == '\' ) && !s:itemtype
cal s:SetWD(2, 0)
cal s:SetLines(0)
cal s:PrtClear()
retu 1
elsei str == '?'
cal s:PrtExit()
let hlpwin = &columns > 159 ? '| vert res 80' : ''
sil! exe 'bo vert h ctrlp-mappings' hlpwin '| norm! 0'
retu 1
en
retu 0
endf
fu! s:openfile(cmd, filpath) fu! s:openfile(cmd, filpath)
let cmd = a:cmd == 'e' && &modified ? 'new' : a:cmd let cmd = a:cmd == 'e' && &modified ? 'hid e' : a:cmd
try try
exe cmd.s:tail().' '.escape(a:filpath, '%# ') exe cmd.s:tail().' '.s:fnesc(a:filpath)
cat cat
echoh Identifier cal s:msg("Operation can't be completed. Make sure filename is valid.")
echon "CtrlP: Operation can't be completed. Make sure filename is valid."
echoh None
fina fina
if !empty(s:tail()) if !empty(s:tail())
sil! norm! zOzz sil! norm! zOzz
@ -1105,6 +1123,10 @@ fu! s:openfile(cmd, filpath)
endt endt
endf endf
fu! s:msg(msg)
echoh Identifier | echon "CtrlP: ".a:msg | echoh None
endf
fu! s:writecache(read_cache, cache_file) fu! s:writecache(read_cache, cache_file)
if !a:read_cache && ( ( g:ctrlp_newcache || !filereadable(a:cache_file) ) if !a:read_cache && ( ( g:ctrlp_newcache || !filereadable(a:cache_file) )
\ && s:caching || len(g:ctrlp_allfiles) > s:nocache_lim ) \ && s:caching || len(g:ctrlp_allfiles) > s:nocache_lim )
@ -1144,7 +1166,6 @@ fu! s:maxfiles(len)
endf endf
fu! s:insertcache(str) fu! s:insertcache(str)
if match(a:str, '|\|?\|:\|"\|\*\|<\|>') >= 0 | retu | en
let [data, g:ctrlp_newcache, str] = [g:ctrlp_allfiles, 1, a:str] let [data, g:ctrlp_newcache, str] = [g:ctrlp_allfiles, 1, a:str]
if strlen(str) <= strlen(data[0]) if strlen(str) <= strlen(data[0])
let pos = 0 let pos = 0
@ -1162,21 +1183,19 @@ fu! s:insertcache(str)
endf endf
fu! s:lscommand() fu! s:lscommand()
let usercmd = g:ctrlp_user_command let cmd = g:ctrlp_user_command
if type(usercmd) == 1 if type(cmd) == 1
retu usercmd retu cmd
elsei type(usercmd) == 3 && len(usercmd) >= 2 elsei type(cmd) == 3 && len(cmd) >= 2 && !empty(cmd[0]) && !empty(cmd[1])
\ && !empty(usercmd[0]) && !empty(usercmd[1]) let rmarker = cmd[0]
let rmarker = usercmd[0]
" Find a repo root " Find a repo root
cal s:findroot(getcwd(), rmarker, 0, 1) cal s:findroot(getcwd(), rmarker, 0, 1)
if !exists('s:vcsroot') || ( exists('s:vcsroot') && empty(s:vcsroot) ) if !exists('s:vcsroot') || ( exists('s:vcsroot') && empty(s:vcsroot) )
" Try the secondary_command " Try the secondary_command
retu len(usercmd) == 3 ? usercmd[2] : '' retu len(cmd) == 3 ? cmd[2] : ''
el
let s:vcscmd = s:lash == '\' ? 1 : 0
retu usercmd[1]
en en
let s:vcscmd = s:lash == '\' ? 1 : 0
retu cmd[1]
en en
endf endf
"}}} "}}}
@ -1189,7 +1208,6 @@ fu! s:SetLines(type)
\ 's:Buffers()', \ 's:Buffers()',
\ 'ctrlp#mrufiles#list(-1)', \ 'ctrlp#mrufiles#list(-1)',
\ ] \ ]
if !s:mru | cal remove(types, 2) | en
if exists('g:ctrlp_ext_vars') | for each in g:ctrlp_ext_vars if exists('g:ctrlp_ext_vars') | for each in g:ctrlp_ext_vars
cal add(types, each[0]) cal add(types, each[0])
endfo | en endfo | en
@ -1199,9 +1217,9 @@ endf
fu! ctrlp#init(type, ...) fu! ctrlp#init(type, ...)
if exists('s:init') | retu | en if exists('s:init') | retu | en
let [s:matches, s:init] = [1, 1] let [s:matches, s:init] = [1, 1]
let path = exists('a:1') ? a:1 : '' let input = exists('a:1') ? a:1 : ''
cal ctrlp#SetWorkingPath(path)
cal s:Open() cal s:Open()
cal s:SetWD(input)
cal s:MapKeys() cal s:MapKeys()
cal s:SetLines(a:type) cal s:SetLines(a:type)
cal s:BuildPrompt(1) cal s:BuildPrompt(1)

View File

@ -7,9 +7,10 @@
" Static variables {{{ " Static variables {{{
fu! ctrlp#mrufiles#opts() fu! ctrlp#mrufiles#opts()
let opts = { let opts = {
\ 'g:ctrlp_mruf_max': ['s:max', 150], \ 'g:ctrlp_mruf_max': ['s:max', 150],
\ 'g:ctrlp_mruf_include': ['s:include', ''], \ 'g:ctrlp_mruf_include': ['s:include', ''],
\ 'g:ctrlp_mruf_exclude': ['s:exclude', ''], \ 'g:ctrlp_mruf_exclude': ['s:exclude', ''],
\ 'g:ctrlp_mruf_case_sensitive': ['s:csen', 1],
\ } \ }
for key in keys(opts) for key in keys(opts)
let def = string(exists(key) ? eval(key) : opts[key][1]) let def = string(exists(key) ? eval(key) : opts[key][1])
@ -18,15 +19,18 @@ fu! ctrlp#mrufiles#opts()
endf endf
cal ctrlp#mrufiles#opts() cal ctrlp#mrufiles#opts()
"}}} "}}}
fu! ctrlp#mrufiles#list(bufnr,...) "{{{ fu! ctrlp#mrufiles#list(bufnr, ...) "{{{
if s:locked | retu | en if s:locked | retu | en
" Get the list " Get the list
let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru' let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru'
let cafile = cadir.ctrlp#utils#lash().'cache.txt' let cafile = cadir.ctrlp#utils#lash().'cache.txt'
let mrufs = ctrlp#utils#readfile(cafile) let mrufs = ctrlp#utils#readfile(cafile)
" Remove non-existent files " Remove non-existent files
if exists('a:1') if exists('a:1') && a:1 == 1
let mrufs = s:rmdeleted(mrufs, cadir, cafile) let mrufs = s:rmdeleted(mrufs, cadir, cafile)
elsei exists('a:1') && a:1 == 2
cal ctrlp#utils#writecache([], cadir, cafile)
retu []
en en
" Return the list " Return the list
if a:bufnr == -1 | retu mrufs | en if a:bufnr == -1 | retu mrufs | en
@ -39,18 +43,16 @@ fu! ctrlp#mrufiles#list(bufnr,...) "{{{
retu retu
en en
" Remove old matched entry " Remove old matched entry
cal filter(mrufs, 'v:val !=# filename') cal filter(mrufs, 'v:val !='.( s:csen ? "#" : "?" ).' filename')
" Insert new one " Insert new one
cal insert(mrufs, filename) cal insert(mrufs, filename)
" Remove oldest entry " Remove oldest entry
if len(mrufs) > s:max if len(mrufs) > s:max | cal remove(mrufs, s:max, -1) | en
cal remove(mrufs, s:max, -1)
en
cal ctrlp#utils#writecache(mrufs, cadir, cafile) cal ctrlp#utils#writecache(mrufs, cadir, cafile)
endf "}}} endf "}}}
fu! s:rmdeleted(mrufs, cadir, cafile) "{{{ fu! s:rmdeleted(mrufs, cadir, cafile) "{{{
for each in range(len(a:mrufs) - 1, 0, -1) for each in range(len(a:mrufs) - 1, 0, -1)
if empty(glob(a:mrufs[each])) if empty(ctrlp#utils#glob(a:mrufs[each], 1))
cal remove(a:mrufs, each) cal remove(a:mrufs, each)
en en
endfo endfo

View File

@ -27,9 +27,8 @@ fu! ctrlp#utils#readfile(file)
unl data | let data = [] unl data | let data = []
en en
retu data retu data
el
retu []
en en
retu []
endf endf
fu! ctrlp#utils#mkdir(dir) fu! ctrlp#utils#mkdir(dir)
@ -38,7 +37,7 @@ fu! ctrlp#utils#mkdir(dir)
en en
endf endf
fu! ctrlp#utils#writecache(lines,...) fu! ctrlp#utils#writecache(lines, ...)
let cache_dir = exists('a:1') ? a:1 : ctrlp#utils#cachedir() let cache_dir = exists('a:1') ? a:1 : ctrlp#utils#cachedir()
cal ctrlp#utils#mkdir(cache_dir) cal ctrlp#utils#mkdir(cache_dir)
" write cache " write cache
@ -53,6 +52,10 @@ endf
fu! ctrlp#utils#lash() fu! ctrlp#utils#lash()
retu &ssl || !exists('+ssl') ? '/' : '\' retu &ssl || !exists('+ssl') ? '/' : '\'
endf endf
fu! ctrlp#utils#glob(...)
retu call('glob', v:version > 701 ? [a:1, a:2] : [a:1])
endf
"}}} "}}}
" vim:fen:fdl=0:fdc=1:ts=2:sw=2:sts=2 " vim:fen:fdl=0:fdc=1:ts=2:sw=2:sts=2

View File

@ -1,4 +1,4 @@
*ctrlp.txt* Full path fuzzy file, buffer and MRU file finder. v1.5.9 *ctrlp.txt* Fuzzy file, buffer and MRU file finder. v1.6.0
*CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'* *CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'*
=============================================================================== ===============================================================================
# # # #
@ -30,7 +30,7 @@ finder, and more.
=============================================================================== ===============================================================================
2. Options *ctrlp-options* 2. Options *ctrlp-options*
Below are the available options and their default values. Below are the available options and their default values:~
*'g:ctrlp_map'* *'g:ctrlp_map'*
Use this option to change the mapping to invoke |CtrlP| in |Normal| mode: > Use this option to change the mapping to invoke |CtrlP| in |Normal| mode: >
@ -48,7 +48,7 @@ Set this to 1 to set search by filename (not full path) as the default: >
< <
*'g:ctrlp_regexp_search'* *'g:ctrlp_regexp_search'*
Set this to 1 to set |regexp| search as the default mode: > Set this to 1 to set |regexp| search as the default: >
let g:ctrlp_regexp_search = 0 let g:ctrlp_regexp_search = 0
< <
@ -75,7 +75,6 @@ tab if the selected buffers opened in another tab: >
< <
*'g:ctrlp_working_path_mode'* *'g:ctrlp_working_path_mode'*
*SetWorkingPath()*
When starting up the prompt, temporarily set the working directory (i.e. the When starting up the prompt, temporarily set the working directory (i.e. the
|current-directory|) to: |current-directory|) to:
1 - the parent directory of the current file. 1 - the parent directory of the current file.
@ -90,16 +89,14 @@ When starting up the prompt, temporarily set the working directory (i.e. the
> >
let g:ctrlp_working_path_mode = 2 let g:ctrlp_working_path_mode = 2
< <
You can use this functionality outside of |CtrlP| by adding the following line
to your |.vimrc|; the parameter is the same (1, 2 or 0): >
au BufEnter * cal ctrlp#SetWorkingPath(2)
<
*'g:ctrlp_root_markers'* *'g:ctrlp_root_markers'*
Use this to set your own root markers for the |SetWorkingPath()| function, in Use this to set your own root markers in addition to the default ones. Your
addition to the default ones. Your markers will take precedence: > markers will take precedence: >
let g:ctrlp_root_markers = [''] let g:ctrlp_root_markers = ['']
< <
These markers (builtins and yours) will serve as identifier for the '/' and '\'
special inputs (section 5.e)
*'g:ctrlp_use_caching'* *'g:ctrlp_use_caching'*
Set this to 0 to disable per-session caching. When disabled, caching will still Set this to 0 to disable per-session caching. When disabled, caching will still
@ -130,10 +127,10 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'PrtSelectMove("k")': ['<c-k>', '<up>'], \ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
\ 'PrtHistory(-1)': ['<c-n>'], \ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'], \ 'PrtHistory(1)': ['<c-p>'],
\ 'AcceptSelection("e")': ['<cr>'], \ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
\ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'], \ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'],
\ 'AcceptSelection("t")': ['<c-t>'], \ 'AcceptSelection("t")': ['<c-t>', '<MiddleMouse>'],
\ 'AcceptSelection("v")': ['<c-v>', '<c-q>'], \ 'AcceptSelection("v")': ['<c-v>', '<c-q>', '<RightMouse>'],
\ 'ToggleFocus()': ['<tab>'], \ 'ToggleFocus()': ['<tab>'],
\ 'ToggleRegex()': ['<c-r>'], \ 'ToggleRegex()': ['<c-r>'],
\ 'ToggleByFname()': ['<c-d>'], \ 'ToggleByFname()': ['<c-d>'],
@ -144,6 +141,7 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'PrtCurLeft()': ['<c-h>', '<left>'], \ 'PrtCurLeft()': ['<c-h>', '<left>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'], \ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'PrtClearCache()': ['<F5>'], \ 'PrtClearCache()': ['<F5>'],
\ 'PrtDeleteMRU()': ['<F8>'],
\ 'CreateNewFile()': ['<c-y>'], \ 'CreateNewFile()': ['<c-y>'],
\ 'MarkToOpen()': ['<c-z>'], \ 'MarkToOpen()': ['<c-z>'],
\ 'OpenMulti()': ['<c-o>'], \ 'OpenMulti()': ['<c-o>'],
@ -151,11 +149,6 @@ only need to keep the lines that youve changed the values (inside []): >
\ } \ }
< <
*'g:ctrlp_mru_files'*
Set this to 0 to completely disable the Most Recently Used files feature: >
let g:ctrlp_mru_files = 1
<
*'g:ctrlp_mruf_max'* *'g:ctrlp_mruf_max'*
Specify the number of recently opened files you want |CtrlP| to remember: > Specify the number of recently opened files you want |CtrlP| to remember: >
let g:ctrlp_mruf_max = 150 let g:ctrlp_mruf_max = 150
@ -179,6 +172,12 @@ Example: >
let g:ctrlp_mruf_include = '\.py$\|\.rb$' let g:ctrlp_mruf_include = '\.py$\|\.rb$'
< <
*'g:ctrlp_mruf_case_sensitive'*
Match this with your file system case-sensitivity setting to avoid duplicate
MRU entries: >
let g:ctrlp_mruf_case_sensitive = 1
<
*'g:ctrlp_dotfiles'* *'g:ctrlp_dotfiles'*
Set this to 0 if you dont want |CtrlP| to search for dotfiles and dotdirs: > Set this to 0 if you dont want |CtrlP| to search for dotfiles and dotdirs: >
let g:ctrlp_dotfiles = 1 let g:ctrlp_dotfiles = 1
@ -229,11 +228,12 @@ Examples: >
let g:ctrlp_user_command = 'find %s -type f | grep (?!tmp/.*)' let g:ctrlp_user_command = 'find %s -type f | grep (?!tmp/.*)'
let g:ctrlp_user_command = 'dir %s /-n /b /s /a-d | findstr .*\.py$' let g:ctrlp_user_command = 'dir %s /-n /b /s /a-d | findstr .*\.py$'
< <
Use a version control listing command when inside a repository: > Use a version control listing command when inside a repository, this is a lot
let g:ctrlp_user_command = [marker, command, secondary_command] faster when working with large projects: >
let g:ctrlp_user_command = [repo_marker, vcs_ls_command, fallback_command]
< <
If the secondary_command is empty or not defined, globpath() will be used when If the fallback_command is empty or not defined, globpath() will then be used
outside a repo. Examples: > when outside a repo. Examples: >
let g:ctrlp_user_command = ['.git/', 'cd %s && git ls-files'] let g:ctrlp_user_command = ['.git/', 'cd %s && git ls-files']
let g:ctrlp_user_command = ['.hg/', 'hg --cwd %s locate --fullpath -I .'] let g:ctrlp_user_command = ['.hg/', 'hg --cwd %s locate --fullpath -I .']
< <
@ -257,25 +257,28 @@ value mirrors Vims global |'history'| option. E.g. `set history=50`: >
Set to 0 to disable prompts history. Set to 0 to disable prompts history.
*'g:ctrlp_open_multi'* *'g:ctrlp_open_multi'*
If non-zero this will enable opening multiple files with <c-z> and <c-o>: > If non-zero, this will enable opening multiple files with <c-z> and <c-o>: >
let g:ctrlp_open_multi = 1 let g:ctrlp_open_multi = '1v'
< <
If bigger than 1, itll be used as the maximum number of windows to create when For the number:
opening the files (the rest will be hidden buffers). If is 1, <c-o> will open If bigger than 1, itll be used as the maximum number of windows or tabs to
all files, each in a vertical split. create when opening the files (the rest will be hidden buffers). If is 1,
<c-o> will open all files, each in a new window or new tab.
For the letter:
t - each in a tab
h - each in a horizontal split
v - each in a vertical split
*'g:ctrlp_dont_split'* *'g:ctrlp_dont_split'*
When opening a file with <cr>, |CtrlP| avoids opening it in windows created by When opening a file with <cr>, |CtrlP| avoids opening it in windows created by
plugins. Use this to setup some exceptions: > plugins, help and quickfix. Use this to setup some exceptions: >
let g:ctrlp_dont_split = '' let g:ctrlp_dont_split = ''
< <
Acceptable values are partial names or filetypes of the special buffers. Acceptable values are partial names or filetypes of the special buffers. Use
Use |regexp| to specify the pattern. |regexp| to specify the pattern. Example: >
Example: > let g:ctrlp_dont_split = 'netrw\|help'
let g:ctrlp_dont_split = 'netrw\|myplugin'
< <
=============================================================================== ===============================================================================
3. Commands *ctrlp-commands* 3. Commands *ctrlp-commands*
@ -290,13 +293,13 @@ Example: >
:CtrlPBuffer :CtrlPBuffer
Open the |CtrlP| prompt in find buffer mode. Open the |CtrlP| prompt in find buffer mode.
*:CtrlPMRUFiles* *:CtrlPMRU*
:CtrlPMRUFiles :CtrlPMRU
Open the |CtrlP| prompt in find Most-Recently-Used file mode. Open the |CtrlP| prompt in find Most-Recently-Used file mode.
*:ClearCtrlPCache* *:ClearCtrlPCache*
:ClearCtrlPCache :ClearCtrlPCache
Flush the cache for the current working directory. Same as pressing <F5> Flush the cache for the current working directory. The same as pressing <F5>
inside |CtrlP|. inside |CtrlP|.
*:ClearAllCtrlPCaches* *:ClearAllCtrlPCaches*
@ -305,26 +308,19 @@ Example: >
*:ResetCtrlP* *:ResetCtrlP*
:ResetCtrlP :ResetCtrlP
Reset all options, take in new values of the option variables (section 2). Reset all options, take in new values of the option variables in section 2.
The following commands ignore the value of |g:ctrlp_working_path_mode|: -------------------------------------------------------------------------------
The following commands ignore the current value of |g:ctrlp_working_path_mode|:
*:CtrlPCurWD* :CtrlPCurWD *:CtrlPCurWD*
:CtrlPCurWD
This acts like |:CtrlP| with |path_mode| = 0 This acts like |:CtrlP| with |path_mode| = 0
Find files in the |current-directory|.
*:CtrlPCurFile* :CtrlPCurFile *:CtrlPCurFile*
:CtrlPCurFile
This acts like |:CtrlP| with |path_mode| = 1 This acts like |:CtrlP| with |path_mode| = 1
Find files in the same directory as the active buffer, regardless of what
the |current-directory| is.
*:CtrlPRoot* :CtrlPRoot *:CtrlPRoot*
:CtrlPRoot
This acts like |:CtrlP| with |path_mode| = 2 This acts like |:CtrlP| with |path_mode| = 2
Find files in the projects root directory.
Check |working_path_mode| to see how |CtrlP| finds a root.
=============================================================================== ===============================================================================
4. Mappings *ctrlp-mappings* 4. Mappings *ctrlp-mappings*
@ -333,7 +329,7 @@ The following commands ignore the value of |g:ctrlp_working_path_mode|:
<c-p> <c-p>
Default |Normal| mode mapping to open the |CtrlP| prompt. Default |Normal| mode mapping to open the |CtrlP| prompt.
Once inside the prompt: Once inside the prompt:~
<c-r> *'ctrlp-fullregexp'* <c-r> *'ctrlp-fullregexp'*
Toggle between the string mode (section 5.a & b) and full |regexp| mode. Toggle between the string mode (section 5.a & b) and full |regexp| mode.
@ -418,6 +414,9 @@ Once inside the prompt:
Refresh the match window and purge the cache for the current directory. Refresh the match window and purge the cache for the current directory.
Or remove deleted files from MRU list. Or remove deleted files from MRU list.
<F8>
Clear the MRU list.
<esc>, <esc>,
<c-c>, <c-c>,
<c-g> <c-g>
@ -425,7 +424,7 @@ Once inside the prompt:
Chose your own mappings with |g:ctrlp_prompt_mappings|. Chose your own mappings with |g:ctrlp_prompt_mappings|.
When inside the match window (press <tab> to switch): When inside the match window (press <tab> to switch):~
a-z a-z
0-9 0-9
@ -436,8 +435,7 @@ When inside the match window (press <tab> to switch):
=============================================================================== ===============================================================================
5. Input Formats *ctrlp-input-formats* 5. Input Formats *ctrlp-input-formats*
*ctrlp-prompt-input-formats* Formats for inputting in the prompt:~
Formats for inputting in the prompt:
a) Simple string. a) Simple string.
e.g. 'abc' is understood internally as 'a[^a]\{-}b[^b]\{-}c' e.g. 'abc' is understood internally as 'a[^a]\{-}b[^b]\{-}c'
@ -459,37 +457,41 @@ c) End the string with a colon ':' followed by a Vim command to execute that
See also Vims |++opt| and |+cmd|. See also Vims |++opt| and |+cmd|.
d) Type exactly two dots (..) at the start of the line and press enter to go d) Type exactly two dots '..' at the start of the prompt and press enter to go
backward in the directory tree by 1 level. If the parent directory is backward in the directory tree by 1 level. If the parent directory is
large, this might be slow. large, this might be slow.
e) Type the name of a non-existent file and press <c-y> to create it. e) Similarly submit '/' or '\' to find and go to the projects root. If the
e.g. 'parentdir/file.txt' will create a directory named 'parentdir' as well project is large, using a VCS listing command to look for files might help
as 'file.txt'. Use '\' in place of '/' on Windows (if |'ssl'| is not set). speeding up the intial scan (see |g:ctrlp_user_command| for more details).
f) Submit ? to open this help file. f) Type the name of a non-existent file and press <c-y> to create it.
e.g. 'parentdir/file.txt' will create a directory named 'parentdir' as well
as 'file.txt'.
Use '\' in place of '/' on Windows (if |'ssl'| is not set).
g) Submit ? to open this help file.
=============================================================================== ===============================================================================
EXTENDING *ctrlp-extending* EXTENDING *ctrlp-extending*
Extending |CtrlP| is made to be incredibly simple. Just create a .vim file Extending |CtrlP| is very simple. Simply create a .vim file following a short
following a short guidelines, place the file in the right spot and add a line guidelines, place it in autoload/ctrlp/ and add its name to your .vimrc.
to your .vimrc.
To see how it all works, get the sample.vim from the 'extensions' branch on the To see how it all works, get the sample.vim from the 'extensions' branch on the
git repository (https://github.com/kien/ctrlp.vim/tree/extensions), and place main git repository (https://github.com/kien/ctrlp.vim/tree/extensions), and
it (along with the parent directories) somewhere in your runtimepath. Then put place it (along with the parent directories) somewhere in your runtimepath.
this into your .vimrc: > Then put this into your .vimrc: >
let g:ctrlp_extensions = ['sample'] let g:ctrlp_extensions = ['sample']
< <
A 4th search type will show up the next time you open |CtrlP|. A 4th search type will show up the next time you open |CtrlP|.
For more details, check out the comments inside sample.vim. For more details, check out the comments inside sample.vim.~
=============================================================================== ===============================================================================
CREDITS *ctrlp-credits* CREDITS *ctrlp-credits*
Developed by Kien Nguyen (github.com/kien), primarily based on the Command-T Developed by Kien Nguyen (github.com/kien), initially based on the Command-T
and the LustyExplorer plugins. No code was taken from these plugins, but I did and the LustyExplorer plugins. No code was taken from these plugins, but I did
clone the majority of their (awesome) interfaces and the way they work. clone the majority of their (awesome) interfaces and the way they work.
@ -509,7 +511,7 @@ THANKS *ctrlp-thanks*
Thanks to everyone that has submitted ideas, bug reports or helped debugging on Thanks to everyone that has submitted ideas, bug reports or helped debugging on
gibhub, bitbucket, and through email. gibhub, bitbucket, and through email.
Special thanks: Special thanks:~
* Woojong Koh <github.com/wjkoh> * Woojong Koh <github.com/wjkoh>
Forked and suggested the support for VCS listing commands. Forked and suggested the support for VCS listing commands.
@ -517,25 +519,34 @@ Special thanks:
=============================================================================== ===============================================================================
CHANGELOG *ctrlp-changelog* CHANGELOG *ctrlp-changelog*
+ New option: |g:ctrlp_dont_split| Before 2011/11/13~
Before 2011/10/30 + New special input: '/' and '\' find root (section 5.e)
+ New mapping: <F8> clear MRU.
+ Remove ctrlp#SetWorkingPath().
+ Remove |g:ctrlp_mru_files|, make MRU permanent.
+ Extend |g:ctrlp_open_multi|, add new ways to open files.
+ New option: |g:ctrlp_dont_split|,
|g:ctrlp_mruf_case_sensitive|
Before 2011/10/30~
+ New feature: Support for custom extensions. + New feature: Support for custom extensions.
<F5> now removes non-existent files from MRU list. <F5> also removes non-existent files from MRU list.
+ New option: |g:ctrlp_jump_to_buffer| + New option: |g:ctrlp_jump_to_buffer|
Before 2011/10/12 Before 2011/10/12~
+ New features: Open multiple files. + New features: Open multiple files.
Pass Vims ++opt and +cmd to the opening file (section 5.c) Pass Vims |++opt| and |+cmd| to the opening file
(section 5.c)
Auto-complete each dir for |:CtrlP| [starting-directory] Auto-complete each dir for |:CtrlP| [starting-directory]
+ New mappings: <c-z> mark/unmark a file to be opened with <c-o>. + New mappings: <c-z> mark/unmark a file to be opened with <c-o>.
<c-o> open all marked files. <c-o> open all marked files.
+ New option: |g:ctrlp_open_multi| + New option: |g:ctrlp_open_multi|
+ Remove |g:ctrlp_persistent_input|, |g:ctrlp_live_update| and <c-^>. + Remove |g:ctrlp_persistent_input|, |g:ctrlp_live_update| and <c-^>.
Before 2011/09/29 Before 2011/09/29~
+ New mappings: <c-n>, <c-p> next/prev string in the input history. + New mappings: <c-n>, <c-p> next/prev string in the input history.
<c-y> create a new file and its parent dirs. <c-y> create a new file and its parent dirs.
@ -543,7 +554,7 @@ Before 2011/09/29
|g:ctrlp_max_history| |g:ctrlp_max_history|
+ Added a new open-in-horizontal-split mapping: <c-x> + Added a new open-in-horizontal-split mapping: <c-x>
Before 2011/09/19 Before 2011/09/19~
+ New command: |ResetCtrlP| + New command: |ResetCtrlP|
+ New options: |g:ctrlp_max_files|, + New options: |g:ctrlp_max_files|,
@ -551,16 +562,16 @@ Before 2011/09/19
|g:ctrlp_live_update| |g:ctrlp_live_update|
+ New mapping: <c-^> + New mapping: <c-^>
Before 2011/09/12 Before 2011/09/12~
+ Ability to cycle through matched lines in the match window. + Ability to cycle through matched lines in the match window.
+ Extended the behavior of |g:ctrlp_persistent_input| + Extend the behavior of |g:ctrlp_persistent_input|
+ Extended the behavior of |:CtrlP| + Extend the behavior of |:CtrlP|
+ New options: |g:ctrlp_dotfiles|, + New options: |g:ctrlp_dotfiles|,
|g:ctrlp_clear_cache_on_exit|, |g:ctrlp_clear_cache_on_exit|,
|g:ctrlp_highlight_match|, |g:ctrlp_highlight_match|,
|g:ctrlp_user_command| |g:ctrlp_user_command|
+ New input format: '..' (section 5.d) + New special input: '..' (section 5.d)
+ New mapping: <F5>. + New mapping: <F5>.
+ New commands: |:CtrlPCurWD|, + New commands: |:CtrlPCurWD|,
|:CtrlPCurFile|, |:CtrlPCurFile|,
@ -575,7 +586,7 @@ Before 2011/09/12
|g:ctrlp_mruf_include| |g:ctrlp_mruf_include|
+ New command: |:CtrlPMRUFiles| + New command: |:CtrlPMRUFiles|
First public release: 2011/09/06 First public release: 2011/09/06~
=============================================================================== ===============================================================================
vim:et:ts=2:sw=2:sts=2 vim:et:ts=2:sw=2:sts=2

View File

@ -1,34 +1,32 @@
" ============================================================================= " =============================================================================
" File: plugin/ctrlp.vim " File: plugin/ctrlp.vim
" Description: Full path fuzzy file, buffer and MRU file finder for Vim. " Description: Fuzzy file, buffer and MRU file finder.
" Author: Kien Nguyen <github.com/kien> " Author: Kien Nguyen <github.com/kien>
" License: MIT
" ============================================================================= " =============================================================================
" GetLatestVimScripts: 3736 1 :AutoInstall: ctrlp.zip " GetLatestVimScripts: 3736 1 :AutoInstall: ctrlp.zip
if ( exists('g:loaded_ctrlp') && g:loaded_ctrlp ) || v:version < '700' || &cp if ( exists('g:loaded_ctrlp') && g:loaded_ctrlp ) || v:version < 700 || &cp
fini fini
endif en
let g:loaded_ctrlp = 1 let g:loaded_ctrlp = 1
if !exists('g:ctrlp_map') | let g:ctrlp_map = '<c-p>' | endif if !exists('g:ctrlp_map') | let g:ctrlp_map = '<c-p>' | en
if !exists('g:ctrlp_mru_files') | let g:ctrlp_mru_files = 1 | endif
com! -nargs=? -complete=custom,ctrlp#compl CtrlP cal ctrlp#init(0, <q-args>) com! -na=? -comp=custom,ctrlp#cpl CtrlP cal ctrlp#init(0, <q-args>)
com! CtrlPBuffer cal ctrlp#init(1) com! CtrlPBuffer cal ctrlp#init(1)
com! CtrlPMRUFiles cal ctrlp#init(2) com! CtrlPMRUFiles cal ctrlp#init(2)
com! ClearCtrlPCache cal ctrlp#clearcache()
com! ClearAllCtrlPCaches cal ctrlp#clearallcaches() com! ClearCtrlPCache cal ctrlp#clr()
com! ClearAllCtrlPCaches cal ctrlp#clra()
com! ResetCtrlP cal ctrlp#reset()
com! CtrlPCurWD cal ctrlp#init(0, 0) com! CtrlPCurWD cal ctrlp#init(0, 0)
com! CtrlPCurFile cal ctrlp#init(0, 1) com! CtrlPCurFile cal ctrlp#init(0, 1)
com! CtrlPRoot cal ctrlp#init(0, 2) com! CtrlPRoot cal ctrlp#init(0, 2)
com! ResetCtrlP cal ctrlp#reset()
exe 'nn <silent>' g:ctrlp_map ':<c-u>CtrlP<cr>' exe 'nn <silent>' g:ctrlp_map ':<c-u>CtrlP<cr>'
if g:ctrlp_mru_files | cal ctrlp#mrufiles#init() | endif cal ctrlp#mrufiles#init()
let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []] let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []]

View File

@ -5,6 +5,7 @@ Full path fuzzy __file__, __buffer__ and __MRU__ file finder for Vim.
* Full support for Vims regexp as search pattern. * Full support for Vims regexp as search pattern.
* Built-in Most Recently Used (MRU) files monitoring. * Built-in Most Recently Used (MRU) files monitoring.
* Built-in projects root finder. * Built-in projects root finder.
* Open Multiple Files.
* [Extensible][3]. * [Extensible][3].
![ctrlp][1] ![ctrlp][1]
@ -18,7 +19,7 @@ Once CtrlP is open:
* Press `<c-f>` and `<c-b>` to switch between find file, buffer, and MRU file modes. * Press `<c-f>` and `<c-b>` to switch between find file, buffer, and MRU file modes.
* Press `<c-d>` to switch to filename only search instead of full path. * Press `<c-d>` to switch to filename only search instead of full path.
* Use `*` or `|` in the prompt to submit the string as a Vims regexp pattern. * Use `*` or `|` in the prompt to submit the string as a Vims regexp pattern.
* Or press `<c-r>` to switch to full regexp search mode. * Or press `<c-r>` to switch to regexp mode.
* End the input string with a colon `:` followed by a command to execute after opening the file. * End the input string with a colon `:` followed by a command to execute after opening the file.
e.g. `abc:45` will open the file matched the pattern and jump to line 45. e.g. `abc:45` will open the file matched the pattern and jump to line 45.
* Submit two dots `..` as the input string to go backward the directory tree by 1 level. * Submit two dots `..` as the input string to go backward the directory tree by 1 level.
@ -49,20 +50,6 @@ e.g. `abc:45` will open the file matched the pattern and jump to line 45.
root.dir root.dir
.vimprojects .vimprojects
* You can also use the set-working-directory functionality above outside of CtrlP
by adding the following line to your vimrc.
The parameter is the same (0, 1 or 2):
```vim
au BufEnter * cal ctrlp#SetWorkingPath(2)
```
* Enable/Disable Most Recently Used files monitoring and its functionalities:
```vim
let g:ctrlp_mru_files = 1
```
* If you want to exclude directories or files from the search, you can use the Vims option `wildignore`. * If you want to exclude directories or files from the search, you can use the Vims option `wildignore`.
Examples: Examples: