option to limit the number of files; no <esc> in term

This commit is contained in:
Kien N 2011-09-14 19:15:54 +07:00
parent e311264c38
commit 1c7c0ffae7
2 changed files with 66 additions and 8 deletions

View File

@ -128,6 +128,13 @@ else
unl g:ctrlp_highlight_match unl g:ctrlp_highlight_match
endif endif
if !exists('g:ctrlp_max_files')
let s:maxfiles = 20000
else
let s:maxfiles = g:ctrlp_max_files
unl g:ctrlp_max_files
endif
if !exists('g:ctrlp_user_command') if !exists('g:ctrlp_user_command')
let g:ctrlp_user_command = '' let g:ctrlp_user_command = ''
endif endif
@ -169,7 +176,7 @@ func! s:List(dirs, allfiles)
let alldirs = s:dotfiles ? filter(entries, 's:dirfilter(v:val)') : filter(entries, 'isdirectory(v:val)') let alldirs = s:dotfiles ? filter(entries, 's:dirfilter(v:val)') : filter(entries, 'isdirectory(v:val)')
let allfiles = filter(entries2, '!isdirectory(v:val)') let allfiles = filter(entries2, '!isdirectory(v:val)')
cal extend(allfiles, a:allfiles, 0) cal extend(allfiles, a:allfiles, 0)
if empty(alldirs) if empty(alldirs) || s:maxfiles(len(allfiles))
let s:allfiles = allfiles let s:allfiles = allfiles
else else
let dirs = join(alldirs, ',') let dirs = join(alldirs, ',')
@ -321,7 +328,7 @@ func! s:SetupBlank() "{{{
setl cul setl cul
setl nocuc setl nocuc
setl tw=0 setl tw=0
setl wfw setl wfh
if v:version >= '703' if v:version >= '703'
setl nornu setl nornu
setl noudf setl noudf
@ -679,7 +686,11 @@ func! s:MapSpecs(...)
endfor | endfor endfor | endfor
else else
for each in keys(prtmaps) | for kp in prtmaps[each] for each in keys(prtmaps) | for kp in prtmaps[each]
if kp == '<esc>' && ( &term =~? 'xterm' || &term =~? '^vt' )
" do nothing
else
exe 'nn <buffer> <silent>' kp ':cal <SID>'.each.'<cr>' exe 'nn <buffer> <silent>' kp ':cal <SID>'.each.'<cr>'
endif
endfor | endfor endfor | endfor
endif endif
endfunc endfunc
@ -824,6 +835,10 @@ func! s:AcceptSelection(mode,...) "{{{
endif endif
endfor endfor
" switch to the buffer or open the file " switch to the buffer or open the file
let opened = 0
if s:normbuf()
exe s:normbuf().'winc w'
endif
if bufnum > 0 if bufnum > 0
if exists('buftabwinnr') if exists('buftabwinnr')
exe 'norm!' buftabnr.'gt' exe 'norm!' buftabnr.'gt'
@ -831,11 +846,18 @@ func! s:AcceptSelection(mode,...) "{{{
elseif bufwinnr > 0 elseif bufwinnr > 0
exe bufwinnr.'winc w' exe bufwinnr.'winc w'
else else
exe 'b' bufnum if !s:normbuf()
exe 'bo vne'
endif
let cmd = 'b'.bufnum
endif endif
else else
exe 'bo '.cmd.' '.filpath if !s:normbuf() | if md == 'e'
exe 'bo vne'
endif | endif
let cmd = 'bo '.cmd.' '.filpath
endif endif
exe cmd
" jump to line " jump to line
if exists('s:jmpln') && !empty('s:jmpln') if exists('s:jmpln') && !empty('s:jmpln')
exe s:jmpln exe s:jmpln
@ -926,11 +948,14 @@ func! s:statusline(...)
let byfname = '%#Character#\ '.byfname.'\ %*' let byfname = '%#Character#\ '.byfname.'\ %*'
let item = '%#Character#\ '.item.'\ %*' let item = '%#Character#\ '.item.'\ %*'
let slider = '\ <'.prev.'>={'.item.'}=<'.next.'>' let slider = '\ <'.prev.'>={'.item.'}=<'.next.'>'
exe 'setl stl='.focus.byfname.regex.slider let dir = '\ %#LineNr#\ '.escape(getcwd(), ' =#(){}%\').'\ %*'
exe 'setl stl='.focus.byfname.regex.slider.dir
endfunc endfunc
func! s:progress(len) func! s:progress(len)
exe 'setl stl=%#Function#\ '.a:len.'\ %*\ ' let dir = '%#LineNr#\ Scanning:\ '.escape(getcwd(), ' =#(){}%\').'\ %*'
let cnt = '%#Function#\ '.a:len.'\ %*'
exe 'setl stl='.dir.cnt
redr redr
endfunc endfunc
"}}} "}}}
@ -993,6 +1018,26 @@ endfunc
func! s:matchsubstr(item, pat) func! s:matchsubstr(item, pat)
retu match(split(a:item, '[\/]\ze[^\/]\+$')[-1], a:pat) retu match(split(a:item, '[\/]\ze[^\/]\+$')[-1], a:pat)
endfunc endfunc
func! s:maxfiles(len)
if !s:maxfiles
retu 0
elseif s:maxfiles && a:len > s:maxfiles
retu 1
endif
endfunc
" return the first window number with a normal buffer
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
"}}} "}}}
"}}} "}}}

View File

@ -207,6 +207,12 @@ the highlight group thatll be used: >
let g:ctrlp_highlight_match = [1, 'Function'] let g:ctrlp_highlight_match = [1, 'Function']
< <
*'g:ctrlp_max_files'*
The maximum number of files to scan, set this to a higher number if your hard
drives are fast (SSDs, RAID 0, or both) and you work with large projects: >
let g:ctrlp_max_files = 20000
<
*'g:ctrlp_user_command'* *'g:ctrlp_user_command'*
Specify an external tool to use for indexing files instead of Vims globpath(). Specify an external tool to use for indexing files instead of Vims globpath().
Use %s in place of the target directory: > Use %s in place of the target directory: >
@ -346,7 +352,11 @@ Once inside the prompt:
<esc>, <esc>,
<c-c>, <c-c>,
<c-g> <c-g>
Exit |CtrlP| Exit |CtrlP|.
Note: The <esc> (also <c-[>) mapping isnt available in terminal. Use <c-c>
or <c-g> to exit |CtrlP| instead.
http://linux.die.net/man/4/console_codes
Chose your own mappings with |g:ctrlp_prompt_mappings|. Chose your own mappings with |g:ctrlp_prompt_mappings|.
@ -399,6 +409,9 @@ Mercurial repository: https://bitbucket.org/kien/ctrlp.vim
=============================================================================== ===============================================================================
CHANGELOG CHANGELOG
+ Remove <esc> mapping in term.
+ New option: |g:ctrlp_max_files|
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.