fix issue #13 on github

This commit is contained in:
Kien N 2011-09-28 20:42:52 +07:00
parent d488423408
commit 97f797821f
2 changed files with 127 additions and 111 deletions

View File

@ -136,6 +136,10 @@ func! s:opts()
unl g:ctrlp_max_depth unl g:ctrlp_max_depth
endif endif
if s:maxdepth > 200
let s:maxdepth = 200
endif
if !exists('g:ctrlp_live_update') if !exists('g:ctrlp_live_update')
let s:liup = 1 let s:liup = 1
else else
@ -174,12 +178,15 @@ func! ctrlp#reset()
cal s:opts() cal s:opts()
cal ctrlp#utils#opts() cal ctrlp#utils#opts()
if g:ctrlp_mru_files | cal ctrlp#mrufiles#opts() | endif if g:ctrlp_mru_files | cal ctrlp#mrufiles#opts() | endif
" Clear user input
let g:CtrlP_prompt = ['','','']
if exists('g:CtrlP_cline') | unl g:CtrlP_cline | endif
endfunc endfunc
"}}} "}}}
" * ListAllFiles {{{ " * ListAllFiles {{{
func! s:List(dirs, allfiles, depth) func! s:List(dirs, allfiles, depth)
" note: wildignore is ignored when using ** " Note: wildignore is ignored when using **
let glob = s:dotfiles ? '.*\|*' : '*' let glob = s:dotfiles ? '.*\|*' : '*'
let entries = split(globpath(a:dirs, glob), '\n') let entries = split(globpath(a:dirs, glob), '\n')
let entries = filter(entries, 'getftype(v:val) != "link"') let entries = filter(entries, 'getftype(v:val) != "link"')
@ -200,7 +207,7 @@ endfunc
func! s:ListAllFiles(path) func! s:ListAllFiles(path)
let cache_file = ctrlp#utils#cachefile() let cache_file = ctrlp#utils#cachefile()
if g:ctrlp_newcache || !filereadable(cache_file) || !s:caching if g:ctrlp_newcache || !filereadable(cache_file) || !s:caching
" get the list of files " Get the list of files
if empty(g:ctrlp_user_command) if empty(g:ctrlp_user_command)
cal s:List(a:path, [], 0) cal s:List(a:path, [], 0)
else else
@ -219,7 +226,7 @@ func! s:ListAllFiles(path)
retu [] retu []
endtry endtry
endif endif
" remove base directory " Remove base directory
let path = &ssl || !exists('+ssl') ? getcwd().'/' : substitute(getcwd(), '\\', '\\\\', 'g').'\\' let path = &ssl || !exists('+ssl') ? getcwd().'/' : substitute(getcwd(), '\\', '\\\\', 'g').'\\'
cal map(g:ctrlp_allfiles, 'substitute(v:val, path, "", "g")') cal map(g:ctrlp_allfiles, 'substitute(v:val, path, "", "g")')
let read_cache = 0 let read_cache = 0
@ -228,7 +235,7 @@ func! s:ListAllFiles(path)
let read_cache = 1 let read_cache = 1
endif endif
if len(g:ctrlp_allfiles) <= s:compare_lim | cal sort(g:ctrlp_allfiles, 's:complen') | endif if len(g:ctrlp_allfiles) <= s:compare_lim | cal sort(g:ctrlp_allfiles, 's:complen') | endif
" write cache " Write cache
if !read_cache && ( ( g:ctrlp_newcache || !filereadable(cache_file) ) if !read_cache && ( ( g:ctrlp_newcache || !filereadable(cache_file) )
\ && s:caching || len(g:ctrlp_allfiles) > s:nocache_lim ) \ && s:caching || len(g:ctrlp_allfiles) > s:nocache_lim )
if len(g:ctrlp_allfiles) > s:nocache_lim | let s:caching = 1 | endif if len(g:ctrlp_allfiles) > s:nocache_lim | let s:caching = 1 | endif
@ -252,15 +259,15 @@ func! s:ListAllBuffers() "{{{
endfunc "}}} endfunc "}}}
func! s:SplitPattern(str,...) "{{{ func! s:SplitPattern(str,...) "{{{
" ignore spaces " Ignore spaces
let str = s:igspace ? substitute(a:str, ' ', '', 'g') : a:str let str = s:igspace ? substitute(a:str, ' ', '', 'g') : a:str
" clear the jumptoline var " Clear the jumptoline var
if exists('s:jmpln') | unl s:jmpln | endif if exists('s:jmpln') | unl s:jmpln | endif
" If pattern contains :\d (e.g. abc:25) " If pattern contains :\d (e.g. abc:25)
if match(str, ':\d*$') >= 0 if match(str, ':\d*$') >= 0
" get the line to jump to " Get the line to jump to
let s:jmpln = matchstr(str, ':\zs\d*$') let s:jmpln = matchstr(str, ':\zs\d*$')
" remove the line number " Remove the line number
let str = substitute(str, ':\d*$', '', 'g') let str = substitute(str, ':\d*$', '', 'g')
endif endif
let str = substitute(str, '\\\\', '\', 'g') let str = substitute(str, '\\\\', '\', 'g')
@ -272,7 +279,7 @@ func! s:SplitPattern(str,...) "{{{
if exists('+ssl') && !&ssl if exists('+ssl') && !&ssl
cal map(array, 'substitute(v:val, "\\", "\\\\\\", "g")') cal map(array, 'substitute(v:val, "\\", "\\\\\\", "g")')
endif endif
" literal ^ and $ " Literal ^ and $
for each in ['^', '$'] for each in ['^', '$']
cal map(array, 'substitute(v:val, "\\\'.each.'", "\\\\\\'.each.'", "g")') cal map(array, 'substitute(v:val, "\\\'.each.'", "\\\\\\'.each.'", "g")')
endfor endfor
@ -303,7 +310,7 @@ func! s:MatchIt(items, pat, limit)
else else
if match(item, pat) >= 0 | cal add(newitems, item) | endif if match(item, pat) >= 0 | cal add(newitems, item) | endif
endif endif
" stop if reached the limit " Stop if reached the limit
if limit > 0 && len(newitems) == limit | break | endif if limit > 0 && len(newitems) == limit | break | endif
endfor endfor
retu newitems retu newitems
@ -313,22 +320,22 @@ func! s:GetMatchedItems(items, pats, limit)
let items = a:items let items = a:items
let pats = a:pats let pats = a:pats
let limit = a:limit let limit = a:limit
" if items is longer than s:mltipats_lim, use only the last pattern " If items is longer than s:mltipats_lim, use only the last pattern
if len(items) >= s:mltipats_lim if len(items) >= s:mltipats_lim
let pats = [pats[-1]] let pats = [pats[-1]]
endif endif
cal map(pats, 'substitute(v:val, "\\\~", "\\\\\\~", "g")') cal map(pats, 'substitute(v:val, "\\\~", "\\\\\\~", "g")')
" loop through the patterns " Loop through the patterns
for each in pats for each in pats
" if newitems is small, set it as items to search in " If newitems is small, set it as items to search in
if exists('newitems') && len(newitems) < limit if exists('newitems') && len(newitems) < limit
let items = deepcopy(newitems) let items = deepcopy(newitems)
endif endif
if !s:regexp | let each = escape(each, '.') | endif if !s:regexp | let each = escape(each, '.') | endif
if empty(items) " end here if empty(items) " End here
retu exists('newitems') ? newitems : [] retu exists('newitems') ? newitems : []
else " start here, goes back up if has 2 or more in pats else " Start here, goes back up if has 2 or more in pats
" loop through the items " Loop through the items
let newitems = s:MatchIt(items, each, limit) let newitems = s:MatchIt(items, each, limit)
endif endif
endfor endfor
@ -346,16 +353,18 @@ func! s:SetupBlank() "{{{
redr redr
endfunc "}}} endfunc "}}}
"Mightdo: history of entered strings /low /minor
func! s:BufOpen(...) "{{{ func! s:BufOpen(...) "{{{
" a:1 bufname; a:2 delete " a:1 bufname; a:2 delete
let buf = a:1 let buf = a:1
let bufnum = bufnr(buf) " Closing, use s:winnr as a switch to avoid an issue with Vim 7.2
" Closing if exists('s:winnr') && s:winnr > 0
if bufnum > 0 && bufwinnr(bufnum) > 0 try
exe 'bun!' bun!
if s:pinput != 2 && exists('g:CtrlP_cline') catch
unl g:CtrlP_cline winc c
endif endtry
if exists('s:winnr') | unl s:winnr | endif
endif endif
if exists('a:2') if exists('a:2')
" Restore the changed global options " Restore the changed global options
@ -372,11 +381,17 @@ func! s:BufOpen(...) "{{{
let &ea = s:CtrlP_ea let &ea = s:CtrlP_ea
let &gcr = s:CtrlP_gcr let &gcr = s:CtrlP_gcr
let &mfd = s:CtrlP_mfd let &mfd = s:CtrlP_mfd
" cleaning up " Cleaning up
if s:pinput != 2 && exists('g:CtrlP_cline')
unl g:CtrlP_cline
endif
if exists('s:cwd') if exists('s:cwd')
exe 'chdir' s:cwd exe 'chd!' s:cwd
unl s:cwd unl s:cwd
endif endif
if exists('s:focus')
unl s:focus
endif
if exists('s:firstinit') if exists('s:firstinit')
unl s:firstinit unl s:firstinit
endif endif
@ -409,6 +424,8 @@ func! s:BufOpen(...) "{{{
if !exists('g:CtrlP_prompt') || !s:pinput if !exists('g:CtrlP_prompt') || !s:pinput
let g:CtrlP_prompt = ['', '', ''] let g:CtrlP_prompt = ['', '', '']
endif endif
" Workaround for Vim 7.2
let s:winnr = bufwinnr('%')
se magic se magic
se to se to
se tm=0 se tm=0
@ -437,7 +454,7 @@ func! s:Renderer(lines, pat) "{{{
" Output to buffer " Output to buffer
if !empty(nls) if !empty(nls)
setl cul setl cul
" sort if not type 2 (MRU) " Sort if not type 2 (MRU)
if index([2], s:itemtype) < 0 if index([2], s:itemtype) < 0
let s:compat = a:pat let s:compat = a:pat
cal sort(nls, 's:mixedsort') cal sort(nls, 's:mixedsort')
@ -453,7 +470,7 @@ func! s:Renderer(lines, pat) "{{{
keepj norm! gg keepj norm! gg
endif endif
keepj norm! 1| keepj norm! 1|
let b:matched = nls let s:matched = nls
else else
setl nocul setl nocul
cal setline('1', ' == NO MATCHES ==') cal setline('1', ' == NO MATCHES ==')
@ -471,7 +488,7 @@ func! s:UpdateMatches(pat) "{{{
let lines = s:GetMatchedItems(g:ctrlp_lines, pats, s:mxheight) let lines = s:GetMatchedItems(g:ctrlp_lines, pats, s:mxheight)
let pat = pats[-1] let pat = pats[-1]
cal s:Renderer(lines, pat) cal s:Renderer(lines, pat)
" highlighting " Highlighting
if type(s:mathi) == 3 && len(s:mathi) == 2 && s:mathi[0] && exists('*clearmatches') if type(s:mathi) == 3 && len(s:mathi) == 2 && s:mathi[0] && exists('*clearmatches')
let grp = empty(s:mathi[1]) ? 'Function' : s:mathi[1] let grp = empty(s:mathi[1]) ? 'Function' : s:mathi[1]
cal s:highlight(pat, grp) cal s:highlight(pat, grp)
@ -521,6 +538,7 @@ func! s:ForceUpdate() "{{{
cal s:UpdateMatches(str) cal s:UpdateMatches(str)
endfunc "}}} endfunc "}}}
"Mightdo: create new file and its parent dirs if not yet existed /medium /minor
" * Prt Actions {{{ " * Prt Actions {{{
func! s:PrtClear() func! s:PrtClear()
let s:nomatches = 1 let s:nomatches = 1
@ -606,20 +624,20 @@ func! s:PrtSelectMove(dir)
endfunc endfunc
func! s:PrtSelectJump(char,...) func! s:PrtSelectJump(char,...)
let lines = map(b:matched, 'substitute(v:val, "^> ", "", "g")') let lines = map(s:matched, 'substitute(v:val, "^> ", "", "g")')
if exists('a:1') if exists('a:1')
let lines = map(lines, 'split(v:val, ''[\/]\ze[^\/]\+$'')[-1]') let lines = map(lines, 'split(v:val, ''[\/]\ze[^\/]\+$'')[-1]')
endif endif
" cycle through matches, use s:jmpchr to store last jump " Cycle through matches, use s:jmpchr to store last jump
let chr = escape(a:char, '.~') let chr = escape(a:char, '.~')
if match(lines, '\c^'.chr) >= 0 if match(lines, '\c^'.chr) >= 0
" if not exists or does but not for the same char " If not exists or does but not for the same char
let pos = match(lines, '\c^'.chr) let pos = match(lines, '\c^'.chr)
if !exists('s:jmpchr') || ( exists('s:jmpchr') && s:jmpchr[0] != chr ) if !exists('s:jmpchr') || ( exists('s:jmpchr') && s:jmpchr[0] != chr )
let jmpln = pos let jmpln = pos
let s:jmpchr = [chr, pos] let s:jmpchr = [chr, pos]
elseif exists('s:jmpchr') && s:jmpchr[0] == chr elseif exists('s:jmpchr') && s:jmpchr[0] == chr
" start of lines " Start of lines
if s:jmpchr[1] == -1 if s:jmpchr[1] == -1
let s:jmpchr[1] = pos let s:jmpchr[1] = pos
endif endif
@ -665,7 +683,7 @@ func! s:MapSpecs(...)
\ 'PrtSelectMove("j")': ['<c-n>', '<c-j>', '<down>'], \ 'PrtSelectMove("j")': ['<c-n>', '<c-j>', '<down>'],
\ 'PrtSelectMove("k")': ['<c-p>', '<c-k>', '<up>'], \ 'PrtSelectMove("k")': ['<c-p>', '<c-k>', '<up>'],
\ 'AcceptSelection("e")': ['<cr>'], \ 'AcceptSelection("e")': ['<cr>'],
\ 'AcceptSelection("h")': ['<c-cr>', '<c-s>'], \ 'AcceptSelection("h")': ['<c-cr>', '<c-s>', '<c-x>'],
\ 'AcceptSelection("t")': ['<c-t>'], \ 'AcceptSelection("t")': ['<c-t>'],
\ 'AcceptSelection("v")': ['<c-v>'], \ 'AcceptSelection("v")': ['<c-v>'],
\ 'ToggleFocus()': ['<tab>'], \ 'ToggleFocus()': ['<tab>'],
@ -673,9 +691,6 @@ func! s:MapSpecs(...)
\ 'ToggleByFname()': ['<c-d>'], \ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType(1)': ['<c-f>', '<c-up'], \ 'ToggleType(1)': ['<c-f>', '<c-up'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'], \ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'Type(0)': ['<m-1>'],
\ 'Type(1)': ['<m-2>'],
\ 'Type(2)': ['<m-3>'],
\ 'ForceUpdate()': ['<c-o>'], \ 'ForceUpdate()': ['<c-o>'],
\ 'PrtCurStart()': ['<c-a>'], \ 'PrtCurStart()': ['<c-a>'],
\ 'PrtCurEnd()': ['<c-e>'], \ 'PrtCurEnd()': ['<c-e>'],
@ -687,20 +702,10 @@ func! s:MapSpecs(...)
if type(s:urprtmaps) == 4 if type(s:urprtmaps) == 4
cal extend(prtmaps, s:urprtmaps) cal extend(prtmaps, s:urprtmaps)
endif endif
" toggleable mappings for toggleable features
let prttempdis = {
\ 'Type(2)': ['<m-3>'],
\ }
for each in keys(prttempdis)
if g:ctrlp_mru_files && !has_key(prtmaps, each)
cal extend(prtmaps, { each : prttempdis[each] })
elseif !g:ctrlp_mru_files
cal remove(prtmaps, each)
endif
endfor
let lcmap = 'nn <buffer> <silent>' let lcmap = 'nn <buffer> <silent>'
" correct arrow keys in terminal " Correct arrow keys in terminal
if &term =~? 'xterm' || &term =~? '\<k\?vt' || &term =~? 'gnome' if ( has('termresponse') && !empty(v:termresponse) )
\ || &term =~? 'xterm\|\<k\?vt\|gnome\|screen'
for each in ['\A <up>','\B <down>','\C <right>','\D <left>'] for each in ['\A <up>','\B <down>','\C <right>','\D <left>']
exe lcmap.' <esc>['.each exe lcmap.' <esc>['.each
endfor endfor
@ -729,14 +734,14 @@ endfunc
" * Toggling functions {{{ " * Toggling functions {{{
func! s:Focus() func! s:Focus()
retu !exists('b:focus') ? 1 : b:focus retu !exists('s:focus') ? 1 : s:focus
endfunc endfunc
func! s:ToggleFocus() func! s:ToggleFocus()
let b:focus = !exists('b:focus') || b:focus ? 0 : 1 let s:focus = !exists('s:focus') || s:focus ? 0 : 1
cal s:MapKeys(b:focus) cal s:MapKeys(s:focus)
let s:firstinit = 1 let s:firstinit = 1
cal s:BuildPrompt(b:focus) cal s:BuildPrompt(s:focus)
endfunc endfunc
func! s:ToggleRegex() func! s:ToggleRegex()
@ -771,12 +776,13 @@ endfunc
"}}} "}}}
" * SetWorkingPath {{{ " * SetWorkingPath {{{
func! s:FindRoot(curr, mark) func! s:FindRoot(curr, mark, depth)
if !empty(globpath(a:curr, a:mark)) let depth = a:depth + 1
sil! exe 'chdir' a:curr if !empty(globpath(a:curr, a:mark)) || depth > s:maxdepth
sil! exe 'chd!' a:curr
else else
let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '') let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '')
if parent != a:curr | cal s:FindRoot(parent, a:mark) | endif if parent != a:curr | cal s:FindRoot(parent, a:mark, depth) | endif
endif endif
endfunc endfunc
@ -786,7 +792,7 @@ func! ctrlp#SetWorkingPath(...)
if exists('a:1') && len(a:1) == 1 && !type(a:1) if exists('a:1') && len(a:1) == 1 && !type(a:1)
let l:pathmode = a:1 let l:pathmode = a:1
elseif exists('a:1') && len(a:1) > 1 && type(a:1) elseif exists('a:1') && len(a:1) > 1 && type(a:1)
sil! exe 'chdir' a:1 sil! exe 'chd!' a:1
retu retu
endif endif
if match(expand('%:p'), '^\<.\+\>://.*') >= 0 if match(expand('%:p'), '^\<.\+\>://.*') >= 0
@ -794,7 +800,7 @@ func! ctrlp#SetWorkingPath(...)
retu retu
endif endif
if exists('+acd') | se noacd | endif if exists('+acd') | se noacd | endif
sil! exe 'chdir' exists('*fnameescape') ? fnameescape(expand('%:p:h')) : expand('%:p:h') sil! exe 'chd!' exists('*fnameescape') ? fnameescape(expand('%:p:h')) : expand('%:p:h')
if s:pathmode == 1 || l:pathmode == 1 | retu | endif if s:pathmode == 1 || l:pathmode == 1 | retu | endif
let markers = [ let markers = [
\ 'root.dir', \ 'root.dir',
@ -808,15 +814,16 @@ func! ctrlp#SetWorkingPath(...)
cal extend(markers, s:rmarkers, 0) cal extend(markers, s:rmarkers, 0)
endif endif
for marker in markers for marker in markers
cal s:FindRoot(getcwd(), marker) cal s:FindRoot(getcwd(), marker, 0)
if getcwd() != expand('%:p:h') | break | endif if getcwd() != expand('%:p:h') | break | endif
endfor endfor
endfunc endfunc
"}}} "}}}
"Mightdo: jump to tag (requires ctags) or to string in addition to line number /low /big
func! s:AcceptSelection(mode,...) "{{{ func! s:AcceptSelection(mode,...) "{{{
let md = a:mode let md = a:mode
" use .. to go back in the dir tree " Walk backward the dir tree
if md == 'e' && !s:itemtype if md == 'e' && !s:itemtype
let prt = g:CtrlP_prompt let prt = g:CtrlP_prompt
let str = prt[0] . prt[1] . prt[2] let str = prt[0] . prt[1] . prt[2]
@ -827,41 +834,41 @@ func! s:AcceptSelection(mode,...) "{{{
retu retu
endif endif
endif endif
" get the full path " Get the full path
let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$') let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$')
let filpath = s:itemtype ? matchstr : getcwd().ctrlp#utils#lash().matchstr let filpath = s:itemtype ? matchstr : getcwd().ctrlp#utils#lash().matchstr
" If only need the full path " If only need the full path
if exists('a:1') && a:1 | retu filpath | endif if exists('a:1') && a:1 | retu filpath | endif
" Remove the prompt and match window " Manually remove the prompt and match window
cal s:BufOpen('ControlP', 'del') if !has('autocmd') | cal s:BufOpen('ControlP', 'del') | endif
" Split the mode string if it's longer than 1 char " Split the mode string if it's longer than 1 char
if len(md) > 1 if len(md) > 1
let mds = split(md, '\zs') let mds = split(md, '\zs')
let md = mds[0] let md = mds[0]
endif endif
" Do something with the selected entry " Do something with the selected entry
if md == 't' || s:splitwin == 1 " in new tab if md == 't' || s:splitwin == 1 " In new tab
tabnew tabnew
let cmd = 'e' let cmd = 'e'
elseif md == 'h' || s:splitwin == 2 " in new hor split elseif md == 'h' || s:splitwin == 2 " In new hor split
let cmd = 'new' let cmd = 'new'
elseif md == 'v' || s:splitwin == 3 " in new ver split elseif md == 'v' || s:splitwin == 3 " In new ver split
let cmd = 'vne' let cmd = 'vne'
elseif md == 'e' || !s:splitwin " in current window elseif md == 'e' || !s:splitwin " In current window
let cmd = 'e' let cmd = 'e'
endif endif
let bufnum = bufnr(filpath) let bufnum = bufnr(filpath)
let bufwinnr = bufwinnr(bufnum) let bufwinnr = bufwinnr(bufnum)
" check if the buffer's already opened in a tab " Check if the buffer's already opened in a tab
for nr in range(1, tabpagenr('$')) for nr in range(1, tabpagenr('$'))
" get a list of the buffers in the nr tab " Get a list of the buffers in the nr tab
let buflist = tabpagebuflist(nr) let buflist = tabpagebuflist(nr)
" if it has the buffer we're looking for " If it has the buffer we're looking for
if match(buflist, bufnum) >= 0 if match(buflist, bufnum) >= 0
let buftabnr = nr let buftabnr = nr
" get the number of windows " Get the number of windows
let tabwinnrs = tabpagewinnr(nr, '$') let tabwinnrs = tabpagewinnr(nr, '$')
" find the buffer that we know is in this tab " Find the buffer that we know is in this tab
for ewin in range(1, tabwinnrs) for ewin in range(1, tabwinnrs)
if buflist[ewin - 1] == bufnum if buflist[ewin - 1] == bufnum
let buftabwinnr = ewin let buftabwinnr = ewin
@ -869,24 +876,23 @@ func! s:AcceptSelection(mode,...) "{{{
endfor endfor
endif endif
endfor endfor
" switch to existing buffer or open new one " Switch to existing buffer or open new one
let opened = 0 let opened = 0
if s:normbuf() if s:normbuf()
exe s:normbuf().'winc w' exe s:normbuf().'winc w'
endif endif
if bufnum > 0 if bufnum > 0
if exists('buftabwinnr') " in a tab if exists('buftabwinnr') " In a tab
exe 'norm!' buftabnr.'gt' exe 'norm!' buftabnr.'gt'
exe buftabwinnr.'winc w' exe buftabwinnr.'winc w'
elseif bufwinnr > 0 " in a window elseif bufwinnr > 0 " In a window
exe bufwinnr.'winc w' exe bufwinnr.'winc w'
else else
if !s:normbuf() if !s:normbuf()
exe 'bo vne' exe 'bo vne' filpath
else else
exe 'bo' cmd exe 'bo '.cmd.' '.filpath
endif endif
exe 'b'.bufnum
endif endif
else else
let pref = 'bo' let pref = 'bo'
@ -896,32 +902,32 @@ func! s:AcceptSelection(mode,...) "{{{
endif | endif endif | endif
exe 'bo '.cmd.' '.filpath exe 'bo '.cmd.' '.filpath
endif endif
" 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
keepj norm! 0zz norm! 0zz
endif endif
ec ec
endfunc "}}} endfunc "}}}
" * Helper functions {{{ " * Helper functions {{{
" comparing and sorting {{{ " Comparing and sorting {{{
func! s:complen(s1, s2) func! s:complen(s1, s2)
" by length " By length
let len1 = strlen(a:s1) let len1 = strlen(a:s1)
let len2 = strlen(a:s2) let len2 = strlen(a:s2)
retu len1 == len2 ? 0 : len1 > len2 ? 1 : -1 retu len1 == len2 ? 0 : len1 > len2 ? 1 : -1
endfunc endfunc
func! s:compmatlen(s1, s2) func! s:compmatlen(s1, s2)
" by match length " By match length
let mln1 = s:shortest(s:matchlens(a:s1, s:compat)) let mln1 = s:shortest(s:matchlens(a:s1, s:compat))
let mln2 = s:shortest(s:matchlens(a:s2, s:compat)) let mln2 = s:shortest(s:matchlens(a:s2, s:compat))
retu mln1 == mln2 ? 0 : mln1 > mln2 ? 1 : -1 retu mln1 == mln2 ? 0 : mln1 > mln2 ? 1 : -1
endfunc endfunc
func! s:compword(s1, s2) func! s:compword(s1, s2)
" by word-only (no non-word in match) " By word-only (no non-word in match)
let wrd1 = s:wordonly(s:matchlens(a:s1, s:compat)) let wrd1 = s:wordonly(s:matchlens(a:s1, s:compat))
let wrd2 = s:wordonly(s:matchlens(a:s2, s:compat)) let wrd2 = s:wordonly(s:matchlens(a:s2, s:compat))
retu wrd1 == wrd2 ? 0 : wrd1 > wrd2 ? 1 : -1 retu wrd1 == wrd2 ? 0 : wrd1 > wrd2 ? 1 : -1
@ -968,13 +974,13 @@ func! s:mixedsort(s1, s2)
endfunc endfunc
"}}} "}}}
" dealing with statusline {{{ " Dealing with statusline {{{
func! s:statusline(...) func! s:statusline(...)
let itemtypes = { let itemtypes = [
\ 0: ['files', 'fil'], \ ['files', 'fil'],
\ 1: ['buffers', 'buf'], \ ['buffers', 'buf'],
\ 2: ['recent files', 'mru'], \ ['recent files', 'mru'],
\ } \ ]
if !g:ctrlp_mru_files if !g:ctrlp_mru_files
cal remove(itemtypes, 2) cal remove(itemtypes, 2)
endif endif
@ -1001,7 +1007,7 @@ func! s:progress(len)
endfunc endfunc
"}}} "}}}
" working with paths {{{ " Working with paths {{{
func! s:dirfilter(val) func! s:dirfilter(val)
retu isdirectory(a:val) && match(a:val, '[\/]\.\{,2}$') < 0 ? 1 : 0 retu isdirectory(a:val) && match(a:val, '[\/]\.\{,2}$') < 0 ? 1 : 0
endfunc endfunc
@ -1009,12 +1015,12 @@ endfunc
func! s:parentdir(curr) func! s:parentdir(curr)
let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '') let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '')
if parent != a:curr if parent != a:curr
sil! exe 'chdir' parent sil! exe 'lc!' parent
endif endif
endfunc endfunc
"}}} "}}}
" syntax and coloring {{{ " Syntax and coloring {{{
func! s:syntax() func! s:syntax()
syn match CtrlPNoEntries '^ == NO MATCHES ==$' syn match CtrlPNoEntries '^ == NO MATCHES ==$'
syn match CtrlPLineMarker '^>' syn match CtrlPLineMarker '^>'
@ -1027,7 +1033,7 @@ func! s:highlight(pat, grp)
if !empty(a:pat) && a:pat != '..' if !empty(a:pat) && a:pat != '..'
let pat = substitute(a:pat, '\~', '\\~', 'g') let pat = substitute(a:pat, '\~', '\\~', 'g')
if !s:regexp | let pat = escape(pat, '.') | endif if !s:regexp | let pat = escape(pat, '.') | endif
" match only filename " Match only filename
if s:byfname if s:byfname
let pat = substitute(pat, '\[\^\(.\{-}\)\]\\{-}', '[^\\/\1]\\{-}', 'g') let pat = substitute(pat, '\[\^\(.\{-}\)\]\\{-}', '[^\\/\1]\\{-}', 'g')
let pat = substitute(pat, '$', '\\ze[^\\/]*$', 'g') let pat = substitute(pat, '$', '\\ze[^\\/]*$', 'g')
@ -1038,7 +1044,7 @@ func! s:highlight(pat, grp)
endfunc endfunc
"}}} "}}}
" misc {{{ " Misc {{{
func! s:walker(max, pos, dir, ...) func! s:walker(max, pos, dir, ...)
if a:dir == 1 if a:dir == 1
let pos = a:pos < a:max ? a:pos + 1 : 0 let pos = a:pos < a:max ? a:pos + 1 : 0
@ -1071,11 +1077,13 @@ endfunc
"}}} "}}}
"}}} "}}}
aug CtrlPAug "{{{ if has('autocmd') "{{{
au! aug CtrlPAug
au BufLeave,WinLeave,BufUnload ControlP cal s:BufOpen('ControlP', 'del') au!
au VimLeavePre * if s:cconex | cal ctrlp#clearallcaches() | endif au WinLeave,BufLeave ControlP cal s:BufOpen('ControlP', 'del')
aug END "}}} au VimLeavePre * if s:cconex | cal ctrlp#clearallcaches() | endif
aug END
endif "}}}
" * Initialization {{{ " * Initialization {{{
func! s:SetLines(type) func! s:SetLines(type)

View File

@ -54,18 +54,21 @@ Set this to 1 to set full |regexp| search as the default mode: >
let g:ctrlp_regexp_search = 0 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 = 1
<
*'g:ctrlp_match_window_reversed'* *'g:ctrlp_match_window_reversed'*
Reverse the sort order of the matched files in the match window. The default Reverse the sort order of the matched files in the match window. The default
setting is from bottom to top: > setting is from bottom to top: >
let g:ctrlp_match_window_reversed = 1 let g:ctrlp_match_window_reversed = 1
< <
*'g:ctrlp_persistent_input'*
Remember the last input string. Set this to 2 to also remember the last
position of the selection in the match window and 0 to disable this feature: >
let g:ctrlp_persistent_input = 1
<
*'g:ctrlp_split_window'* *'g:ctrlp_split_window'*
Use this option to specify how the file is to be opened when pressing <cr>: Use this option to specify how the file is to be opened when pressing <cr>:
1 - in a new tab 1 - in a new tab
@ -142,7 +145,7 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'PrtSelectMove("j")': ['<c-n>', '<c-j>', '<down>'], \ 'PrtSelectMove("j")': ['<c-n>', '<c-j>', '<down>'],
\ 'PrtSelectMove("k")': ['<c-p>', '<c-k>', '<up>'], \ 'PrtSelectMove("k")': ['<c-p>', '<c-k>', '<up>'],
\ 'AcceptSelection("e")': ['<cr>'], \ 'AcceptSelection("e")': ['<cr>'],
\ 'AcceptSelection("h")': ['<c-cr>', '<c-s>'], \ 'AcceptSelection("h")': ['<c-cr>', '<c-s>', '<c-x>'],
\ 'AcceptSelection("t")': ['<c-t>'], \ 'AcceptSelection("t")': ['<c-t>'],
\ 'AcceptSelection("v")': ['<c-v>'], \ 'AcceptSelection("v")': ['<c-v>'],
\ 'ToggleFocus()': ['<tab>'], \ 'ToggleFocus()': ['<tab>'],
@ -217,7 +220,7 @@ The maximum number of files to scan, set to 0 for no limit: >
The maximum depth of a directory tree to recurse into: > The maximum depth of a directory tree to recurse into: >
let g:ctrlp_max_depth = 40 let g:ctrlp_max_depth = 40
< <
Note: keep it smaller than 200. The larger the value, the more memory Vim uses. Note: the larger the value, the more memory Vim uses.
*'g:ctrlp_live_update'* *'g:ctrlp_live_update'*
Set to 0 to disable the update-as-you-type functionality; press <c-o> to force Set to 0 to disable the update-as-you-type functionality; press <c-o> to force
@ -362,7 +365,8 @@ Once inside the prompt:
Open selected file in a 'vertical' split Open selected file in a 'vertical' split
<c-cr>, <c-cr>,
<c-s> <c-s>,
<c-x>
Open selected file in a 'horizontal' split Open selected file in a 'horizontal' split
<F5> <F5>
@ -424,6 +428,10 @@ Mercurial repository: https://bitbucket.org/kien/ctrlp.vim
=============================================================================== ===============================================================================
CHANGELOG CHANGELOG
+ Added a new open-in-horizontal-split mapping: <c-x>
Before 2011/09/19
+ New command: |ResetCtrlP| + New command: |ResetCtrlP|
+ New options: |g:ctrlp_max_files|, + New options: |g:ctrlp_max_files|,
|g:ctrlp_max_depth|, |g:ctrlp_max_depth|,
@ -457,4 +465,4 @@ The updates are shown in reverse chronological order, from newest (top) to
oldest (bottom). oldest (bottom).
=============================================================================== ===============================================================================
vim:nofen:et:ts=2:sw=2:sts=2 vim:et:ts=2:sw=2:sts=2