Version 1.6.6

* Allow running commands like `:diffthis` when opening multiple files.
* Add experimental extensions:
  + undo.vim (requires v7.3.005+)
  + rtscript.vim (find vimscripts in runtimepath)
* Include the workaround for <bs> and <c-h> for MS-Win. Resolve #62.
* Mention custom_ignore in readme and on the homepage. Resolve #63.
* Check the present of cwd in returned paths. Fix #64.
* Trigger Vim to remove cwd from display-names. Fix #65.
* Some internal changes and additions.
This commit is contained in:
Kien N 2012-01-06 13:22:55 +07:00
parent 93637eade6
commit 969075718a
10 changed files with 391 additions and 135 deletions

View File

@ -2,7 +2,7 @@
" File: autoload/ctrlp.vim
" Description: Fuzzy file, buffer, mru and tag finder.
" Author: Kien Nguyen <github.com/kien>
" Version: 1.6.5
" Version: 1.6.6
" =============================================================================
" Static variables {{{1
@ -42,6 +42,7 @@ fu! s:opts()
if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en
let s:glob = s:dotfiles ? '.*\|*' : '*'
let s:maxdepth = min([s:maxdepth, 100])
let s:igntype = empty(s:usrign) ? -1 : type(s:usrign)
let g:ctrlp_builtins = 2
if !empty(s:extensions) | for each in s:extensions
exe 'ru autoload/ctrlp/'.each.'.vim'
@ -54,7 +55,7 @@ let s:lash = ctrlp#utils#lash()
" Global options
let s:glbs = { 'magic': 1, 'to': 1, 'tm': 0, 'sb': 1, 'hls': 0, 'im': 0,
\ 'report': 9999, 'sc': 0, 'ss': 0, 'siso': 0, 'mfd': 200, 'mouse': 'n',
\ 'gcr': 'a:blinkon0' }
\ 'gcr': 'a:blinkon0', 'ic': 1, 'scs': 1 }
if s:lazy
cal extend(s:glbs, { 'ut': ( s:lazy > 1 ? s:lazy : 250 ) })
@ -67,13 +68,8 @@ fu! s:Open()
if exists('g:ctrlp_log') && g:ctrlp_log
sil! exe 'redi >>' ctrlp#utils#cachedir().s:lash.'ctrlp.log'
en
let [s:cwd, s:winres] = [getcwd(), winrestcmd()]
let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)]
let [s:crword, s:crline] = [expand('<cword>'), getline('.')]
let [s:tagfiles, s:crcursor] = [s:tagfiles(), getpos('.')]
let [s:crbufnr, s:crvisual] = [bufnr('%'), s:lastvisual()]
let s:currwin = s:mwbottom ? winnr() : winnr() + has('autocmd')
sil! exe s:mwbottom ? 'bo' : 'to' '1new ControlP'
cal s:getenv()
sil! exe 'keepa' ( s:mwbottom ? 'bo' : 'to' ) '1new ControlP'
let [s:bufnr, s:prompt] = [bufnr('%'), ['', '', '']]
abc <buffer>
if !exists('s:hstry')
@ -97,9 +93,15 @@ fu! s:Close()
endfo
if exists('s:glb_acd') | let &acd = s:glb_acd | en
let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []]
exe s:winres
if s:winres[1] >= &lines && s:winres[2] == winnr('$')
exe s:winres[0]
en
unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr
\ g:ctrlp_nolimit
if exists('g:ctrlp_ext_vars')
cal map(filter(copy(g:ctrlp_ext_vars),
\ 'exists("v:val[4]")'), 'eval(v:val[4])')
en
cal ctrlp#recordhist()
if exists('g:ctrlp_log') && g:ctrlp_log
sil! redi END
@ -159,9 +161,6 @@ endf
fu! s:GlobPath(dirs, depth)
let entries = split(globpath(a:dirs, s:glob), "\n")
if s:usrign != ''
cal filter(entries, 'v:val !~ s:usrign')
en
let [dnf, depth] = [ctrlp#dirnfile(entries), a:depth + 1]
cal extend(g:ctrlp_allfiles, dnf[1])
if !empty(dnf[0]) && !s:maxf(len(g:ctrlp_allfiles)) && depth <= s:maxdepth
@ -215,7 +214,7 @@ fu! s:Buffers() "{{{1
retu allbufs
endf
" * MatchedItems() {{{1
fu! s:MatchIt(items, pat, limit, ispathitem, mfunc)
fu! s:MatchIt(items, pat, limit, mfunc)
let newitems = []
for item in a:items
if call(a:mfunc, [item, a:pat]) >= 0 | cal add(newitems, item) | en
@ -227,7 +226,9 @@ endf
fu! s:MatchedItems(items, pats, limit)
let [items, pats, limit, ipt] = [a:items, a:pats, a:limit, s:ispathitem()]
" If items is longer than s:mltipats_lim, use only the last pattern
if len(items) >= s:mltipats_lim | let pats = [pats[-1]] | en
if len(items) >= s:mltipats_lim || ( exists('s:height') && s:height > 20 )
let pats = [pats[-1]]
en
cal map(pats, 'substitute(v:val, "\\\~", "\\\\\\~", "g")')
if !s:regexp | cal map(pats, 'escape(v:val, ".")') | en
let mfunc = s:byfname && ipt ? 's:matchfname'
@ -243,7 +244,7 @@ fu! s:MatchedItems(items, pats, limit)
retu exists('newitems') ? newitems : []
el " Start here, go back up if have 2 or more in pats
" Loop through the items
let newitems = s:MatchIt(items, pat, limit, ipt, mfunc)
let newitems = s:MatchIt(items, pat, limit, mfunc)
en
endfo
let s:matches = len(newitems)
@ -320,7 +321,9 @@ fu! s:Render(lines, pat)
keepj norm! 1|
cal s:unmarksigns()
cal s:remarksigns()
if exists('s:cline') | cal cursor(s:cline, 1) | en
if exists('s:cline') && !exists('g:ctrlp_nolimit')
cal cursor(s:cline, 1)
en
" Highlighting
if s:dohighlight()
cal s:highlight(a:pat, empty(s:mathi[1]) ? 'Identifier' : s:mathi[1])
@ -460,7 +463,7 @@ endf
fu! s:PrtSelectMove(dir)
exe 'norm!' a:dir
let s:cline = line('.')
if !exists('g:ctrlp_nolimit') | let s:cline = line('.') | en
if line('$') > winheight(0) | cal s:BuildPrompt(0, s:Focus()) | en
endf
@ -483,7 +486,7 @@ fu! s:PrtSelectJump(char, ...)
let [jmpln, s:jmpchr] = [npos == -1 ? pos : npos, [chr, npos]]
en
keepj exe jmpln + 1
let s:cline = line('.')
if !exists('g:ctrlp_nolimit') | let s:cline = line('.') | en
if line('$') > winheight(0) | cal s:BuildPrompt(0, s:Focus()) | en
en
endf
@ -549,7 +552,7 @@ endf
fu! s:MapSpecs(...)
let [lcmap, prtmaps] = ['nn <buffer> <silent>', {
\ 'PrtBS()': ['<bs>'],
\ 'PrtBS()': ['<bs>', '<c-]>'],
\ 'PrtDelete()': ['<del>'],
\ 'PrtDeleteWord()': ['<c-w>'],
\ 'PrtClear()': ['<c-u>'],
@ -557,11 +560,11 @@ fu! s:MapSpecs(...)
\ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
\ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'],
\ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
\ 'AcceptSelection("e")': ['<cr>', '<c-m>', '<2-LeftMouse>'],
\ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'],
\ 'AcceptSelection("t")': ['<c-t>', '<MiddleMouse>'],
\ 'AcceptSelection("v")': ['<c-v>', '<c-q>', '<RightMouse>'],
\ 'ToggleFocus()': ['<tab>'],
\ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'],
\ 'ToggleFocus()': ['<tab>', '<c-i>'],
\ 'ToggleRegex()': ['<c-r>'],
\ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType(1)': ['<c-f>', '<c-up>'],
@ -572,7 +575,7 @@ fu! s:MapSpecs(...)
\ 'PrtInsert("+")': ['<F6>'],
\ 'PrtCurStart()': ['<c-a>'],
\ 'PrtCurEnd()': ['<c-e>'],
\ 'PrtCurLeft()': ['<c-h>', '<left>'],
\ 'PrtCurLeft()': ['<c-h>', '<left>', '<c-^>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'PrtClearCache()': ['<F5>'],
\ 'PrtDeleteMRU()': ['<F7>'],
@ -581,11 +584,14 @@ fu! s:MapSpecs(...)
\ 'OpenMulti()': ['<c-o>'],
\ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
\ }]
if !has('gui_running') && ( has('win32') || has('win64') )
cal add(prtmaps['PrtBS()'], remove(prtmaps['PrtCurLeft()'], 0))
en
if type(s:urprtmaps) == 4
cal extend(prtmaps, s:urprtmaps)
en
" Correct arrow keys in terminal
if ( has('termresponse') && !empty(v:termresponse) )
if ( has('termresponse') && match(v:termresponse, "\<ESC>") >= 0 )
\ || &term =~? 'xterm\|\<k\?vt\|gnome\|screen\|linux'
for each in ['\A <up>','\B <down>','\C <right>','\D <left>']
exe lcmap.' <esc>['.each
@ -648,11 +654,7 @@ fu! s:ToggleType(dir)
unl! g:ctrlp_nolimit
cal s:SetLines(s:itemtype)
cal s:PrtSwitcher()
if s:itemtype > 2
if exists('g:ctrlp_ext_vars['.s:extid.'][4][0]')
let g:ctrlp_nolimit = g:ctrlp_ext_vars[s:extid][4][0]
en
el
if s:itemtype < 3 && has('syntax') && exists('g:syntax_on')
cal s:syntax()
en
endf
@ -695,7 +697,7 @@ fu! ctrlp#acceptfile(mode, matchstr, ...)
if s:jmptobuf && bufnum > 0 && md =~ 'e\|t'
let [jmpb, bufwinnr] = [1, bufwinnr(bufnum)]
let buftab = s:jmptobuf > 1 ? s:buftab(bufnum, md) : [0, 0]
let j2l = a:0 ? a:1 : str2nr(matchstr(s:tail(), '^ +\zs\d\+$'))
let j2l = a:0 ? a:1 : str2nr(matchstr(s:tail(), '^ +\D*\zs\d\+\ze\D*'))
en
" Switch to existing buffer or open new one
if exists('jmpb') && bufwinnr > 0 && md != 't'
@ -716,9 +718,7 @@ fu! ctrlp#acceptfile(mode, matchstr, ...)
endf
fu! s:SpecInputs()
let str = join(s:prompt, '')
let type = s:itemtype > 2 ?
\ g:ctrlp_ext_vars[s:itemtype - ( g:ctrlp_builtins + 1 )][3] : s:itemtype
let [str, type] = [join(s:prompt, ''), s:type()]
if str == '..' && type =~ '0\|dir'
cal s:parentdir(getcwd())
cal s:SetLines(s:itemtype)
@ -771,7 +771,10 @@ fu! s:CreateNewFile() "{{{1
endf
" * OpenMulti() {{{1
fu! s:MarkToOpen()
if s:bufnr <= 0 || !s:opmul || s:itemtype > g:ctrlp_builtins | retu | en
if s:bufnr <= 0 || !s:opmul
\ || ( s:itemtype > g:ctrlp_builtins && s:type() !~ 'rts' )
retu
en
let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$')
if empty(matchstr) | retu | en
let filpath = s:itemtype ? matchstr : getcwd().s:lash.matchstr
@ -801,10 +804,10 @@ endf
fu! s:OpenMulti()
if !exists('s:marked') || !s:opmul
cal s:AcceptSelection('e')
retu
cal s:AcceptSelection('e') | retu
en
let mkd = s:marked
cal s:sanstail(join(s:prompt, ''))
cal s:PrtExit()
" Try not to open a new tab
let [ntab, norwins] = [0, s:normbuf()]
@ -821,8 +824,8 @@ fu! s:OpenMulti()
if ntab | tabnew | en
let [ic, wnr] = [1, exists('wnr') ? wnr : 1]
let cmds = { 'v': 'vne', 'h': 'new', 't': 'tabe' }
let spt = len(s:opmul) > 1 ? cmds[matchstr(s:opmul, '\w$')] : 'vne'
let nr = matchstr(s:opmul, '^\d\+')
let [nr, md] = matchlist(s:opmul, '\v^(\d+)(\w)$')[1:2]
let spt = len(s:opmul) > 1 ? cmds[md] : 'vne'
exe wnr.'winc w'
for va in values(mkd)
let cmd = ic == 1 ? 'e' : spt
@ -853,8 +856,9 @@ endf
fu! s:comparent(s1, s2)
" By same parent dir
if match(s:crfpath, escape(getcwd(), '.^$*\')) >= 0
let [as1, as2] = [getcwd().s:lash.a:s1, getcwd().s:lash.a:s2]
let cwd = getcwd()
if match(s:crfpath, escape(cwd, '.^$*\')) >= 0
let [as1, as2] = [cwd.s:lash.a:s1, cwd.s:lash.a:s2]
let [loc1, loc2] = [s:getparent(as1), s:getparent(as2)]
if loc1 == s:crfpath && loc2 != s:crfpath | retu -1 | en
if loc2 == s:crfpath && loc1 != s:crfpath | retu 1 | en
@ -933,13 +937,15 @@ endf
" Paths {{{2
fu! s:ispathitem()
let ext = s:itemtype - ( g:ctrlp_builtins + 1 )
retu s:itemtype < 3 || ( s:itemtype > 2 && g:ctrlp_ext_vars[ext][3] == 'dir' )
retu s:itemtype < 3
\ || ( s:itemtype > 2 && g:ctrlp_ext_vars[ext][3] =~ 'dir\|rts' )
endf
fu! ctrlp#dirnfile(entries)
let [items, cwd] = [[[], []], getcwd().s:lash]
for each in a:entries
let etype = getftype(each)
if s:igntype >= 0 && s:usrign(each, etype) | con | en
if etype == 'dir'
if s:dotfiles | if match(each, '[\/]\.\{,2}$') < 0
cal add(items[0], each)
@ -960,6 +966,12 @@ fu! ctrlp#dirnfile(entries)
retu items
endf
fu! s:usrign(item, type)
retu s:igntype == 1 ? a:item =~ s:usrign
\ : s:igntype == 4 && has_key(s:usrign, a:type) && s:usrign[a:type] != ''
\ ? a:item =~ s:usrign[a:type] : 0
endf
fu! s:samerootsyml(each, isfile, cwd)
let resolve = resolve(a:each)
let resolve = ( a:isfile ? fnamemodify(resolve, ':p:h') : resolve ).s:lash
@ -967,8 +979,12 @@ fu! s:samerootsyml(each, isfile, cwd)
endf
fu! ctrlp#rmbasedir(items)
let idx = strlen(getcwd()) + 1
retu map(a:items, 'strpart(v:val, idx)')
let cwd = getcwd()
if !stridx(a:items[0], cwd)
let idx = strlen(cwd) + 1
retu map(a:items, 'strpart(v:val, idx)')
en
retu a:items
endf
fu! s:parentdir(curr)
@ -977,11 +993,11 @@ fu! s:parentdir(curr)
endf
fu! s:getparent(item)
retu split(a:item, '[\/]\ze[^\/]\+[\/:]\?$')[0]
endf
fu! s:getgrand(item)
retu split(a:item, '[\/]\ze[^\/]\+[\/][^\/]\+[\/:]\?$')[0]
let parent = substitute(a:item, '[\/][^\/]\+[\/:]\?$', '', '')
if parent == '' || match(parent, '[\/]') < 0
let parent .= s:lash
en
retu parent
endf
fu! s:createparentdirs(arr)
@ -992,21 +1008,6 @@ fu! s:createparentdirs(arr)
retu curr
endf
fu! s:listdirs(path, parent)
let [str, dirs] = ['', split(s:glbpath(a:path, '*', 1), "\n")]
for entry in filter(dirs, 'isdirectory(v:val)')
let str .= a:parent . split(entry, '[\/]')[-1] . "\n"
endfo
retu str
endf
fu! ctrlp#cpl(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)
endf
fu! s:findroot(curr, mark, depth, type)
let [depth, notfound] = [a:depth + 1, empty(s:glbpath(a:curr, a:mark, 1))]
if !notfound || depth > s:maxdepth
@ -1036,7 +1037,7 @@ fu! ctrlp#setdir(path, ...)
try
exe cmd.' '.ctrlp#fnesc(a:path)
cat
cal ctrlp#msg("Can't change working dir. Directory not exists.")
cal ctrlp#msg("Can't change working directory.")
endt
endf
" Highlighting {{{2
@ -1063,8 +1064,7 @@ fu! s:highlight(pat, grp)
endf
fu! s:dohighlight()
retu type(s:mathi) == 3 && len(s:mathi) > 1 && s:mathi[0]
\ && exists('*clearmatches')
retu len(s:mathi) > 1 && s:mathi[0] && exists('*clearmatches')
endf
" Prompt history {{{2
fu! s:gethistloc()
@ -1203,6 +1203,19 @@ fu! s:sanstail(str)
retu substitute(str, '\\\ze:', '', 'g')
endf
" Misc {{{2
fu! s:getenv()
let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]]
let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)]
let [s:crword, s:crline] = [expand('<cword>'), getline('.')]
let [s:tagfiles, s:crcursor] = [s:tagfiles(), getpos('.')]
let [s:crbufnr, s:crvisual] = [bufnr('%'), s:lastvisual()]
if exists('g:ctrlp_extensions') && index(g:ctrlp_extensions, 'undo') >= 0
\ && v:version > 702 && has('patch005') && exists('*undotree')
let s:undotree = undotree()
en
let s:currwin = s:mwbottom ? winnr() : winnr() + has('autocmd')
endf
fu! s:lastvisual()
let cview = winsaveview()
let [ovreg, ovtype] = [getreg('v'), getregtype('v')]
@ -1229,6 +1242,7 @@ fu! s:openfile(cmd, filpath, ...)
if !empty(tail)
sil! norm! zvzz
en
cal ctrlp#setdir(getcwd(), haslocaldir() ? 'lc!' : 'cd!')
endt
endf
@ -1292,10 +1306,29 @@ fu! s:insertcache(str)
cal s:writecache(0, ctrlp#utils#cachefile())
endf
" Extensions {{{2
fu! s:type()
retu s:itemtype > 2 ?
\ g:ctrlp_ext_vars[s:itemtype - ( g:ctrlp_builtins + 1 )][3] : s:itemtype
endf
fu! s:tagfiles()
retu filter(map(tagfiles(), 'fnamemodify(v:val, ":p")'), 'filereadable(v:val)')
endf
fu! ctrlp#allbufs()
let bufs = []
for each in range(1, bufnr('$'))
if getbufvar(each, '&bl')
let bufname = bufname(each)
if strlen(bufname) && bufname != 'ControlP'
cal add(bufs, fnamemodify(bufname, ':p'))
en
en
endfo
cal filter(bufs, 'filereadable(v:val)')
retu bufs
endf
fu! ctrlp#exit()
cal s:PrtExit()
endf

View File

@ -2,6 +2,9 @@
" File: autoload/ctrlp/buffertag.vim
" Description: Buffer Tag extension
" Maintainer: Kien Nguyen <github.com/kien>
" Credits: Much of the code was taken from tagbar.vim by Jan Larres, plus
" a few lines from taglist.vim by Yegappan Lakshmanan and from
" buffertag.vim by Takeshi Nishida.
" =============================================================================
" Init {{{1
@ -10,8 +13,8 @@ if exists('g:loaded_ctrlp_buftag') && g:loaded_ctrlp_buftag
en
let g:loaded_ctrlp_buftag = 1
let s:buftag_var = ['ctrlp#buffertag#init(s:crfile, s:crbufnr)',
\ 'ctrlp#buffertag#accept', 'buffer tags', 'bft']
let s:buftag_var = ['ctrlp#buffertag#init(s:crfile)', 'ctrlp#buffertag#accept',
\ 'buffer tags', 'bft', 'ctrlp#buffertag#exit()']
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:buftag_var) : [s:buftag_var]
@ -167,16 +170,16 @@ fu! s:process(fname, ftype)
let ftime = getftime(a:fname)
if has_key(g:ctrlp_buftags, a:fname)
\ && g:ctrlp_buftags[a:fname]['time'] >= ftime
let data = g:ctrlp_buftags[a:fname]['data']
let lines = g:ctrlp_buftags[a:fname]['lines']
el
let data = s:exectagsonfile(a:fname, a:ftype)
let cache = { a:fname : { 'time': ftime, 'data': data } }
let [raw, lines] = [split(data, '\n\+'), []]
for line in raw | if len(split(line, ';"')) == 2
cal add(lines, s:parseline(line))
en | endfo
let cache = { a:fname : { 'time': ftime, 'lines': lines } }
cal extend(g:ctrlp_buftags, cache)
en
let [raw, lines] = [split(data, '\n\+'), []]
for line in raw | if len(split(line, ';"')) == 2
cal add(lines, s:parseline(line))
en | endfo
retu lines
endf
@ -184,17 +187,27 @@ fu! s:parseline(line)
let eval = '\v^([^\t]+)\t(.+)\t\/\^(.+)\$\/\;\"\t(.+)\tline(no)?\:(\d+)'
let vals = matchlist(a:line, eval)
if empty(vals) | retu '' | en
retu vals[1].' '.vals[4].'|'.vals[6].'| '.vals[3]
let [bufnr, bufname] = [bufnr(vals[2]), fnamemodify(vals[2], ':p:t')]
retu vals[1].' '.vals[4].'|'.bufnr.':'.bufname.'|'.vals[6].'| '.vals[3]
endf
" Public {{{1
fu! ctrlp#buffertag#init(fname, bufnr)
fu! ctrlp#buffertag#init(fname)
let fname = exists('s:bufname') ? s:bufname : a:fname
let bufs = exists('s:btmode') && s:btmode ? ctrlp#allbufs() : [fname]
let lines = []
for each in bufs
let tftype = get(split(getbufvar(each, '&ft'), '\.'), 0, '')
cal extend(lines, s:process(each, tftype))
endfo
sy match CtrlPTabExtra '\zs\t.*\ze$'
hi link CtrlPTabExtra Comment
retu s:process(a:fname, get(split(getbufvar(a:bufnr, '&ft'), '\.'), 0, ''))
retu lines
endf
fu! ctrlp#buffertag#accept(mode, str)
cal ctrlp#exit()
let vals = matchlist(a:str, '\v^[^\t]+\t+[^\t|]+\|(\d+)\:[^\t|]+\|(\d+)\|')
let [bufnr, linenr] = [vals[1], vals[2]]
if a:mode == 't'
tab sp
elsei a:mode == 'h'
@ -202,12 +215,23 @@ fu! ctrlp#buffertag#accept(mode, str)
elsei a:mode == 'v'
vs
en
cal ctrlp#j2l(matchstr(a:str, '^[^\t]\+\t\+[^\t|]\+|\zs\d\+\ze|'))
if exists('s:btmode') && s:btmode
exe 'hid b' bufnr
en
cal ctrlp#j2l(linenr)
endf
fu! ctrlp#buffertag#id()
fu! ctrlp#buffertag#cmd(mode, ...)
let s:btmode = a:mode
if a:0 && !empty(a:1)
let s:bufname = fnamemodify(a:1, ':p')
en
retu s:id
endf
fu! ctrlp#buffertag#exit()
unl! s:btmode s:bufname
endf
"}}}
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2

View File

@ -15,7 +15,6 @@ let s:ars = [
\ 's:maxfiles',
\ 's:compare_lim',
\ 's:glob',
\ 's:usrign',
\ ]
let s:dir_var = ['ctrlp#dir#init('.join(s:ars, ', ').')', 'ctrlp#dir#accept',
@ -28,9 +27,6 @@ let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Utilities {{{1
fu! s:globdirs(dirs, depth)
let entries = split(globpath(a:dirs, s:glob), "\n")
if s:usrign != ''
cal filter(entries, 'v:val !~ s:usrign')
en
let [dirs, depth] = [ctrlp#dirnfile(entries)[0], a:depth + 1]
cal extend(g:ctrlp_alldirs, dirs)
if !empty(dirs) && !s:max(len(g:ctrlp_alldirs), s:maxfiles)

View File

@ -1,9 +1,16 @@
" =============================================================================
" File: autoload/ctrlp/line.vim
" Description: Line extension - find a line in any buffer.
" Description: Line extension - Find a line in any buffer
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['line']
" Create A Command:
" com! CtrlPLine cal ctrlp#init(ctrlp#line#id())
"}}}
" Init {{{1
if exists('g:loaded_ctrlp_line') && g:loaded_ctrlp_line
fini
@ -18,16 +25,7 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Public {{{1
fu! ctrlp#line#init()
let [bufs, lines] = [[], []]
for each in range(1, bufnr('$'))
if getbufvar(each, '&bl')
let bufname = bufname(each)
if strlen(bufname) && bufname != 'ControlP'
cal add(bufs, fnamemodify(bufname, ':p'))
en
en
endfo
cal filter(bufs, 'filereadable(v:val)')
let [bufs, lines] = [ctrlp#allbufs(), []]
for each in bufs
let from_file = readfile(each)
cal map(from_file, 'tr(v:val, '' '', '' '')')

View File

@ -11,7 +11,7 @@ en
let g:loaded_ctrlp_quickfix = 1
let s:var_qf = ['ctrlp#quickfix#init()', 'ctrlp#quickfix#accept', 'quickfix',
\ 'qfx', [1]]
\ 'qfx']
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:var_qf) : [s:var_qf]

View File

@ -0,0 +1,45 @@
" =============================================================================
" File: autoload/ctrlp/rtscript.vim
" Description: Runtime scripts extension - Find vimscripts in runtimepath
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['rtscript']
" Create A Command:
" com! CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id())
"}}}
" Init {{{1
if exists('g:loaded_ctrlp_rtscript') && g:loaded_ctrlp_rtscript
fini
en
let [g:loaded_ctrlp_rtscript, g:ctrlp_newrts] = [1, 0]
let s:rtscript_var = ['ctrlp#rtscript#init()', 'ctrlp#rtscript#accept',
\ 'runtime scripts', 'rts']
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:rtscript_var) : [s:rtscript_var]
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Public {{{1
fu! ctrlp#rtscript#init()
if g:ctrlp_newrts || !exists('g:ctrlp_rtscache')
let entries = split(globpath(&rtp, '**/*.\(vim\|txt\)'), "\n")
let [g:ctrlp_rtscache, g:ctrlp_newrts] = [ctrlp#dirnfile(entries)[1], 0]
en
retu g:ctrlp_rtscache
endf
fu! ctrlp#rtscript#accept(mode, str)
cal ctrlp#acceptfile(a:mode, a:str)
endf
fu! ctrlp#rtscript#id()
retu s:id
endf
"}}}
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2

116
autoload/ctrlp/undo.vim Normal file
View File

@ -0,0 +1,116 @@
" =============================================================================
" File: autoload/ctrlp/undo.vim
" Description: Undo extension - Browse undo history (requires Vim 7.3.005+)
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['undo']
" Create A Command:
" com! CtrlPUndo cal ctrlp#init(ctrlp#undo#id())
"}}}
" Init {{{1
if ( exists('g:loaded_ctrlp_undo') && g:loaded_ctrlp_undo )
\ || !( v:version > 702 && has('patch005') )
fini
en
let g:loaded_ctrlp_undo = 1
let s:undo_var = ['ctrlp#undo#init(s:undotree)', 'ctrlp#undo#accept',
\ 'undo', 'udo']
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:undo_var) : [s:undo_var]
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Utilities {{{1
fu! s:flatten(tree)
let flatdict = {}
for each in a:tree
cal extend(flatdict, { each['seq'] : each['time'] })
if has_key(each, 'alt')
cal extend(flatdict, s:flatten(each['alt']))
en
endfo
retu flatdict
endf
fu! s:humantime(nr)
let elapsed = localtime() - a:nr
let mins = elapsed / 60
let hrs = elapsed / 3600
let days = elapsed / 86400
let wks = elapsed / 604800
let mons = elapsed / 2592000
let yrs = elapsed / 31536000
let text = [
\ ' second ago',
\ ' seconds ago',
\ ' minutes ago',
\ ' hours ago',
\ ' days ago',
\ ' weeks ago',
\ ' months ago',
\ ' years ago',
\ ]
if yrs > 1
retu yrs.text[7]
elsei mons > 1
retu mons.text[6]
elsei wks > 1
retu wks.text[5]
elsei days > 1
retu days.text[4]
elsei hrs > 1
retu hrs.text[3]
elsei mins > 1
retu mins.text[2]
elsei elapsed == 1
retu elapsed.text[0]
elsei elapsed < 120
retu elapsed.text[1]
en
endf
fu! s:syntax()
sy match CtrlPUndoT '\d\+ \zs[^ ]\+\ze'
sy match CtrlPUndoBr '\[\|\]'
sy match CtrlPUndoNr '\[\d\+\]$' contains=CtrlPUndoBr
hi link CtrlPUndoT Directory
hi link CtrlPUndoBr Comment
hi link CtrlPUndoNr String
endf
fu! s:dict2list(dict)
let dict = map(a:dict, 's:humantime(v:val)')
retu map(keys(dict), 'eval(''[v:val, dict[v:val]]'')')
endf
fu! s:compval(...)
retu a:2[0] - a:1[0]
endf
" Public {{{1
fu! ctrlp#undo#init(undo)
let entries = a:undo['entries']
if empty(entries) | retu [] | en
cal s:syntax()
let g:ctrlp_nolimit = 1
let entries = sort(s:dict2list(s:flatten(entries)), 's:compval')
retu map(entries, 'v:val[1]." [".v:val[0]."]"')
endf
fu! ctrlp#undo#accept(mode, str)
let undon = matchstr(a:str, '\[\zs\d\+\ze\]')
if empty(undon) | retu | en
cal ctrlp#exit()
exe 'u' undon
endf
fu! ctrlp#undo#id()
retu s:id
endf
"}}}
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2

View File

@ -1,4 +1,4 @@
*ctrlp.txt* Fuzzy file, buffer, mru and tag finder. v1.6.5
*ctrlp.txt* Fuzzy file, buffer, mru and tag finder. v1.6.6
*CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'*
===============================================================================
# #
@ -128,7 +128,7 @@ Set the directory to store the cache files: >
Use this to customize the mappings inside |CtrlP|s prompt to your liking. You
only need to keep the lines that youve changed the values (inside []): >
let g:ctrlp_prompt_mappings = {
\ 'PrtBS()': ['<bs>'],
\ 'PrtBS()': ['<bs>', '<c-]>'],
\ 'PrtDelete()': ['<del>'],
\ 'PrtDeleteWord()': ['<c-w>'],
\ 'PrtClear()': ['<c-u>'],
@ -136,18 +136,22 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
\ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'],
\ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
\ 'AcceptSelection("e")': ['<cr>', '<c-m>', '<2-LeftMouse>'],
\ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'],
\ 'AcceptSelection("t")': ['<c-t>', '<MiddleMouse>'],
\ 'AcceptSelection("v")': ['<c-v>', '<c-q>', '<RightMouse>'],
\ 'ToggleFocus()': ['<tab>'],
\ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'],
\ 'ToggleFocus()': ['<tab>', '<c-i>'],
\ 'ToggleRegex()': ['<c-r>'],
\ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType(1)': ['<c-f>', '<c-up>'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'PrtInsert("w")': ['<F2>'],
\ 'PrtInsert("s")': ['<F3>'],
\ 'PrtInsert("v")': ['<F4>'],
\ 'PrtInsert("+")': ['<F6>'],
\ 'PrtCurStart()': ['<c-a>'],
\ 'PrtCurEnd()': ['<c-e>'],
\ 'PrtCurLeft()': ['<c-h>', '<left>'],
\ 'PrtCurLeft()': ['<c-h>', '<left>', '<c-^>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'PrtClearCache()': ['<F5>'],
\ 'PrtDeleteMRU()': ['<F7>'],
@ -157,12 +161,13 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
\ }
<
If you have problem with <bs> moving left instead of deleting a char, add this
to your |vimrc|: >
let g:ctrlp_prompt_mappings = {
\ 'PrtBS()': ['<c-h>'],
\ 'PrtCurLeft()': ['<left>'],
\ }
Note: In some terminals, its not possible to remap <c-h> without also changing
<bs>. So if pressing <bs> moves the cursor to the left instead of deleting a
char for you, add this to your |vimrc| to change the default <c-h> mapping: >
let g:ctrlp_prompt_mappings = {
\ 'PrtBS()': ['<bs>', '<c-]>', '<c-h>'],
\ 'PrtCurLeft()': ['<left>', '<c-^>'],
\ }
<
*'g:ctrlp_mruf_max'*
@ -203,18 +208,26 @@ e.g. exclude version control directories: >
set wildignore+=*/.git/*,*/.hg/*,*/.svn/* " Linux/MacOSX
set wildignore+=.git\*,.hg\*,.svn\* " Windows
<
Note: the `*/` in front of each glob is required.
Note #1: the `*/` in front of each glob is required.
Other note: |wildignore| influences the result of |expand()|, |globpath()| and
Note #2: |wildignore| influences the result of |expand()|, |globpath()| and
|glob()| which many plugins use to find stuff on the system (e.g. fugitive.vim
looks for .git/, some other plugins look for external exe tools on Windows).
So be a little mindful of what you put in your |wildignore|.
*'g:ctrlp_custom_ignore'*
In addition to |'wildignore'|, use this for files and directories you want only
|CtrlP| to not show. Use |regexp| to specify the pattern: >
|CtrlP| to not show. Use |regexp| to specify the patterns: >
let g:ctrlp_custom_ignore = ''
<
Examples: >
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$'
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|\.hg$\|\.svn$',
\ 'file': '\.exe$\|\.so$\|\.dll$',
\ 'link': 'bad_symbolic_link',
\ }
>
*'g:ctrlp_highlight_match'*
Use this to enable/disable highlighting of the matched patterns and to specify
@ -251,11 +264,11 @@ Use a version control listing command when inside a repository, this is a lot
faster when working with large projects: >
let g:ctrlp_user_command = [repo_marker, vcs_ls_command, fallback_command]
<
If the fallback_command is empty or not defined, globpath() will then be used
If the fallback_command is empty or not defined, |globpath()| will then be used
when searching outside a repo.
Examples: >
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 -I .']
<
*'g:ctrlp_open_new_file'*
@ -407,13 +420,21 @@ Once inside the prompt:~
Move the cursor to the 'end' of the prompt
<c-h>,
<left>
<left>,
<c-^>
Move the cursor one character to the 'left'
<c-l>,
<right>
Move the cursor one character to the 'right'
<c-]>,
<bs>
Delete the preceding character
<del>
Delete the current character
<c-w>
Delete a preceding inner word
@ -459,7 +480,7 @@ Once inside the prompt:~
<esc>,
<c-c>,
<c-g>
Exit |CtrlP|. <c-c> can also be used to stop the file scan.
Exit |CtrlP|. <c-c> can also be used to stop the scan.
Choose your own mappings with |g:ctrlp_prompt_mappings|.
@ -483,16 +504,19 @@ b) Vim |regexp|. If the input string contains '*' or '|', itll be treated as
a Vims |regexp| |pattern| without any modification.
e.g. 'abc\d*efg' will be read as 'abc\d*efg'.
See also |ctrlp-fullregexp| (key map) and |g:ctrlp_regexp_search| (option).
See also |ctrlp-fullregexp| (keymap) and |g:ctrlp_regexp_search| (option).
c) End the string with a colon ':' followed by a Vim command to execute that
command after opening the file. If you need to use ':' in the command,
escape it with a backslash: '\:'.
command after opening the file. If you need to use ':' literally, escape it
with a backslash: '\:'. When opening multiple files, the command will be
executed on each opening file.
e.g. 'abc:45' will open the selected file and jump to line 45.
'abc:/my\:function' will open the selected file and jump to the first
instance of 'my:function'.
'abc:+setf\ myfiletype|50' will open the selected file and set its
filetype to 'myfiletype' then jump to line 50.
filetype to 'myfiletype', then jump to line 50.
'abc:difft' will open the selected file and run |:diffthis| on the first
four files.
See also Vims |++opt| and |+cmd|.
@ -532,11 +556,13 @@ Available extensions:~
locations of the tags file(s). Example: `set tags+=tags/help,doc/tags`
*:CtrlPBufTag*
*:CtrlPBufTagAll*
* Buffer Tag mode:~
- Name: 'buffertag'
- Command: ':CtrlPBufTag'
- Search for a tag within the current buffer and jump to the definition.
Requires |exuberant_ctags|.
- Commands: ':CtrlPBufTag [buffer-name]',
':CtrlPBufTagAll'.
- Search for a tag within the current buffer or all buffers and jump to the
definition. Requires |exuberant_ctags| or compatible programs.
*:CtrlPQuickfix*
* Quickfix mode:~
@ -547,7 +573,7 @@ Available extensions:~
*:CtrlPDir*
* Directory mode:~
- Name: 'dir'
- Command: ':CtrlPDir'
- Command: ':CtrlPDir [starting-directory]'
- Search for a directory and change the working directory to it.
- Mappings:
+ <cr> change the local working directory for |CtrlP| and keep it open.
@ -634,8 +660,12 @@ Special thanks:~
===============================================================================
CHANGELOG *ctrlp-changelog*
+ Extend |g:ctrlp_custom_ignore| to specifically filter dir, file and link.
Before 2012/01/05~
+ New feature: Buffer Tag extension.
+ New command: |:CtrlPBufTag|.
+ New commands: |:CtrlPBufTag|, |:CtrlPBufTagAll|.
+ New options: |g:ctrlp_cmd|,
|g:ctrlp_custom_ignore|

View File

@ -13,7 +13,7 @@ let [g:loaded_ctrlp, g:ctrlp_lines, g:ctrlp_allfiles] = [1, [], []]
if !exists('g:ctrlp_map') | let g:ctrlp_map = '<c-p>' | en
if !exists('g:ctrlp_cmd') | let g:ctrlp_cmd = 'CtrlP' | en
com! -n=? -com=custom,ctrlp#cpl CtrlP cal ctrlp#init(0, <q-args>)
com! -n=? -com=dir CtrlP cal ctrlp#init(0, <q-args>)
com! CtrlPBuffer cal ctrlp#init(1)
com! CtrlPMRUFiles cal ctrlp#init(2)
@ -32,21 +32,27 @@ cal ctrlp#mrufiles#init()
if !exists('g:ctrlp_extensions') | fini | en
if index(g:ctrlp_extensions, 'tag') >= 0
let g:ctrlp_alltags = [] | com! CtrlPTag cal ctrlp#init(ctrlp#tag#id())
let s:ext = g:ctrlp_extensions
if index(s:ext, 'tag') >= 0
let g:ctrlp_alltags = []
com! CtrlPTag cal ctrlp#init(ctrlp#tag#id())
en
if index(g:ctrlp_extensions, 'quickfix') >= 0
if index(s:ext, 'quickfix') >= 0
com! CtrlPQuickfix cal ctrlp#init(ctrlp#quickfix#id())
en
if index(g:ctrlp_extensions, 'dir') >= 0
if index(s:ext, 'dir') >= 0
let g:ctrlp_alldirs = []
com! -n=? -com=custom,ctrlp#cpl CtrlPDir
\ cal ctrlp#init(ctrlp#dir#id(), <q-args>)
com! -n=? -com=dir CtrlPDir cal ctrlp#init(ctrlp#dir#id(), <q-args>)
en
if index(g:ctrlp_extensions, 'buffertag') >= 0
if index(s:ext, 'buffertag') >= 0
let g:ctrlp_buftags = {}
com! CtrlPBufTag cal ctrlp#init(ctrlp#buffertag#id())
com! -n=? -com=buffer CtrlPBufTag
\ cal ctrlp#init(ctrlp#buffertag#cmd(0, <q-args>))
com! CtrlPBufTagAll cal ctrlp#init(ctrlp#buffertag#cmd(1))
en
unl s:ext

View File

@ -1,5 +1,5 @@
# ctrlp.vim
Full path fuzzy __file__, __buffer__ and __MRU__ file finder for Vim.
Full path fuzzy __file__, __buffer__, __mru__ and __tag__ finder for Vim.
* Written in pure Vimscript for MacVim and Vim 7.0+.
* Full support for Vims regexp as search pattern.
@ -50,12 +50,20 @@ e.g. `abc:45` will open the file matched the pattern and jump to line 45.
root.dir
.vimprojects
* 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`
and/or the option `g:ctrlp_custom_ignore`.
Examples:
```vim
set wildignore+=*/.git/*,*/.hg/*,*/.svn/* " for Linux/MacOSX
set wildignore+=.git\*,.hg\*,.svn\* " for Windows
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$'
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|\.hg$\|\.svn$',
\ 'file': '\.exe$\|\.so$\|\.dll$',
\ 'link': 'bad_symbolic_link',
\ }
```
* Use a custom file listing command with: