Tag and Quickfix extensions

* New extensions for searching tag and quickfix.
* Option to update the results lazily. Close #37.
This commit is contained in:
Kien N 2011-11-28 19:52:28 +07:00
parent dee2f5a998
commit ef9e072c5f
8 changed files with 333 additions and 134 deletions

View File

@ -2,11 +2,12 @@
" File: autoload/ctrlp.vim
" Description: Fuzzy file, buffer and MRU file finder.
" Author: Kien Nguyen <github.com/kien>
" Version: 1.6.1
" Version: 1.6.2
" =============================================================================
" Static variables {{{
fu! s:opts()
let hst = exists('+hi') ? &hi : 20
let opts = {
\ 'g:ctrlp_by_filename': ['s:byfname', 0],
\ 'g:ctrlp_clear_cache_on_exit': ['s:clrex', 1],
@ -15,12 +16,14 @@ fu! s:opts()
\ 'g:ctrlp_extensions': ['s:extensions', []],
\ 'g:ctrlp_follow_symlinks': ['s:folsym', 0],
\ 'g:ctrlp_highlight_match': ['s:mathi', [1, 'Identifier']],
\ 'g:ctrlp_lazy_update': ['s:lazy', 0],
\ 'g:ctrlp_jump_to_buffer': ['s:jmptobuf', 1],
\ 'g:ctrlp_match_window_bottom': ['s:mwbottom', 1],
\ 'g:ctrlp_match_window_reversed': ['s:mwreverse', 1],
\ 'g:ctrlp_max_depth': ['s:maxdepth', 40],
\ 'g:ctrlp_max_files': ['s:maxfiles', 20000],
\ 'g:ctrlp_max_height': ['s:mxheight', 10],
\ 'g:ctrlp_max_history': ['s:maxhst', hst],
\ 'g:ctrlp_open_multi': ['s:opmul', '1v'],
\ 'g:ctrlp_open_new_file': ['s:newfop', 3],
\ 'g:ctrlp_prompt_mappings': ['s:urprtmaps', 0],
@ -28,16 +31,13 @@ fu! s:opts()
\ 'g:ctrlp_root_markers': ['s:rmarkers', []],
\ 'g:ctrlp_split_window': ['s:splitwin', 0],
\ 'g:ctrlp_use_caching': ['s:caching', 1],
\ 'g:ctrlp_user_command': ['s:usrcmd', ''],
\ 'g:ctrlp_working_path_mode': ['s:pathmode', 2],
\ }
for [ke, va] in items(opts)
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1]) '| unl!' ke
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1])
endfo
if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en
if !exists('g:ctrlp_user_command') | let g:ctrlp_user_command = '' | en
let s:maxhst = exists('g:ctrlp_max_history') ? g:ctrlp_max_history
\ : exists('+hi') ? &hi : 20
unl! g:ctrlp_max_history
if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en
" Note: wildignore is ignored when using **
let s:glob = s:dotfiles ? '.*\|*' : '*'
let s:maxdepth = min([s:maxdepth, 100])
@ -53,7 +53,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:block-PmenuSel-blinkon0' }
\ 'gcr': 'a:block-PmenuSel-blinkon0', 'ut': ( s:lazy > 1 ? s:lazy : 250 ) }
" Limiters
let [s:compare_lim, s:nocache_lim, s:mltipats_lim] = [3000, 4000, 2000]
@ -62,6 +62,7 @@ let [s:compare_lim, s:nocache_lim, s:mltipats_lim] = [3000, 4000, 2000]
fu! s:Open()
let [s:cwd, s:winres] = [getcwd(), winrestcmd()]
let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)]
let [s:crword, s:crvisual] = [expand('<cword>'), s:lastvisual()]
sil! exe s:mwbottom ? 'bo' : 'to' '1new ControlP'
let s:currwin = s:mwbottom ? winnr('#') : winnr('#') + 1
let [s:bufnr, s:prompt] = [bufnr('%'), ['', '', '']]
@ -89,14 +90,14 @@ fu! s:Close()
let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []]
exe s:winres
unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr
\ s:crfile s:crfpath
\ s:crfile s:crfpath s:crword s:crvisual g:ctrlp_nolimit
cal s:recordhist(join(s:prompt, ''))
ec
endf
"}}}
" * Clear caches {{{
fu! ctrlp#clr()
let g:ctrlp_newcache = 1
fu! ctrlp#clr(...)
exe 'let g:ctrlp_new'.( exists('a:1') ? a:1 : 'cache' ).' = 1'
endf
fu! ctrlp#clra(...)
@ -117,7 +118,6 @@ fu! ctrlp#reset()
cal s:opts()
cal ctrlp#utils#opts()
cal ctrlp#mrufiles#opts()
let s:prompt = ['', '', '']
unl! s:cline
endf
"}}}
@ -196,7 +196,8 @@ endf "}}}
" * MatchedItems() {{{
fu! s:MatchIt(items, pat, limit)
let [items, pat, limit, newitems] = [a:items, a:pat, a:limit, []]
let mfunc = s:byfname ? 's:matchsubstr' : 'match'
let mfunc = s:byfname ? 's:matchfname'
\ : s:itemtype > 2 ? 's:matchtab' : 'match'
for item in items
if call(mfunc, [item, pat]) >= 0 | cal add(newitems, item) | en
if limit > 0 && len(newitems) >= limit | brea | en
@ -209,13 +210,13 @@ fu! s:MatchedItems(items, pats, limit)
" If items is longer than s:mltipats_lim, use only the last pattern
if len(items) >= s:mltipats_lim | let pats = [pats[-1]] | en
cal map(pats, 'substitute(v:val, "\\\~", "\\\\\\~", "g")')
if !s:regexp | cal map(pats, 'escape(v:val, ".")') | en
" Loop through the patterns
for each in pats
" If newitems is small, set it as items to search in
if exists('newitems') && len(newitems) < limit
let items = copy(newitems)
en
if !s:regexp | let each = escape(each, '.') | en
if empty(items) " End here
retu exists('newitems') ? newitems : []
el " Start here, go back up if have 2 or more in pats
@ -246,10 +247,10 @@ fu! s:SplitPattern(str, ...) "{{{
let nitem = !empty(array) ? array[0] : ''
let newpats = [nitem]
if len(array) > 1
for i in range(1, len(array) - 1)
for item in range(1, len(array) - 1)
" Separator
let sep = exists('a:1') ? a:1 : '[^'.array[i-1].']\{-}'
let nitem .= sep.array[i]
let sep = exists('a:1') ? a:1 : '[^'.array[item-1].']\{-}'
let nitem .= sep.array[item]
cal add(newpats, nitem)
endfo
en
@ -266,11 +267,13 @@ fu! s:Render(lines, pat)
setl nocul
cal setline(1, ' == NO MATCHES ==')
cal s:unmarksigns()
if s:dohighlight() | cal clearmatches() | en
retu
en
setl cul
" Sort if not MRU
if s:itemtype != 2 || !empty(join(s:prompt, ''))
if ( s:itemtype != 2 && !exists('g:ctrlp_nolimit') )
\ || !empty(join(s:prompt, ''))
let s:compat = a:pat
cal sort(lines, 's:mixedsort')
unl s:compat
@ -285,34 +288,40 @@ fu! s:Render(lines, pat)
cal s:remarksigns()
if exists('s:cline') | cal cursor(s:cline, 1) | en
" Highlighting
if type(s:mathi) == 3 && len(s:mathi) == 2 && s:mathi[0]
\ && exists('*clearmatches')
if s:dohighlight()
cal s:highlight(a:pat, empty(s:mathi[1]) ? 'Identifier' : s:mathi[1])
en
endf
fu! s:Update(pat, ...)
let pat = a:pat
fu! s:Update(str)
" Get the previous string if existed
let oldstr = exists('s:savestr') ? s:savestr : ''
let pats = s:SplitPattern(pat)
let pats = s:SplitPattern(a:str)
" Get the new string sans tail
let notail = substitute(pat, ':\([^:]\|\\:\)*$', '', 'g')
let notail = substitute(a:str, ':\([^:]\|\\:\)*$', '', 'g')
" Stop if the string's unchanged
if notail == oldstr && !empty(notail) && !exists('a:1') && !exists('s:force')
if notail == oldstr && !empty(notail) && !exists('s:force')
retu
en
let lines = s:MatchedItems(g:ctrlp_lines, pats, s:mxheight)
let lines = exists('g:ctrlp_nolimit') && empty(notail) ? copy(g:ctrlp_lines)
\ : s:MatchedItems(g:ctrlp_lines, pats, s:mxheight)
cal s:Render(lines, pats[-1])
endf
fu! s:ForceUpdate()
let [estr, prt] = ['"\', copy(s:prompt)]
cal map(prt, 'escape(v:val, estr)')
cal s:Update(join(prt, ''))
endf
fu! s:BuildPrompt(upd, ...)
let base = ( s:regexp ? 'r' : '>' ).( s:byfname ? 'd' : '>' ).'> '
let [estr, prt] = ['"\', copy(s:prompt)]
cal map(prt, 'escape(v:val, estr)')
let str = join(prt, '')
if a:upd && ( s:matches || s:regexp || match(str, '[*|]') >= 0 )
sil! cal call('s:Update', exists('a:2') ? [str, a:2] : [str])
let lazy = empty(str) || exists('s:force') || !has('autocmd') ? 0 : s:lazy
if a:upd && ( s:matches || s:regexp || match(str, '[*|]') >= 0 ) && !lazy
sil! cal s:Update(str)
en
sil! cal s:statusline()
" Toggling
@ -364,18 +373,23 @@ endf
fu! s:PrtDeleteWord()
unl! s:hstgot
let [str, s:matches] = [s:prompt[0], 1]
if match(str, '\W\w\+$') >= 0
let str = matchstr(str, '^.\+\W\ze\w\+$')
elsei match(str, '\w\W\+$') >= 0
let str = matchstr(str, '^.\+\w\ze\W\+$')
elsei match(str, '\s\+$') >= 0
let str = matchstr(str, '^.*[^ \t]\+\ze\s\+$')
elsei match(str, ' ') <= 0
let str = ''
en
let str = match(str, '\W\w\+$') >= 0 ? matchstr(str, '^.\+\W\ze\w\+$')
\ : match(str, '\w\W\+$') >= 0 ? matchstr(str, '^.\+\w\ze\W\+$')
\ : match(str, '\s\+$') >= 0 ? matchstr(str, '^.*[^ \t]\+\ze\s\+$')
\ : match(str, ' ') <= 0 ? '' : str
let s:prompt[0] = str
cal s:BuildPrompt(1)
endf
fu! s:PrtInsert(type)
unl! s:hstgot
" Insert current word, search register, last visual and clipboard
let s:prompt[0] .= a:type == 'w' ? s:crword
\ : a:type == 's' ? getreg('/')
\ : a:type == 'v' ? s:crvisual
\ : a:type == '+' ? substitute(getreg('+'), '\n', '\\n', 'g') : s:prompt[0]
cal s:BuildPrompt(1)
endf
"}}}
" Movement {{{
fu! s:PrtCurLeft()
@ -405,14 +419,14 @@ endf
fu! s:PrtCurEnd()
let prt = s:prompt
let str = join(prt, '')
let [prt[0], prt[1], prt[2]] = [str, '', '']
let [prt[0], prt[1], prt[2]] = [join(prt, ''), '', '']
cal s:BuildPrompt(0)
endf
fu! s:PrtSelectMove(dir)
exe 'norm!' a:dir
let s:cline = line('.')
if line('$') > winheight(0) | cal s:BuildPrompt(0, s:Focus()) | en
endf
fu! s:PrtSelectJump(char, ...)
@ -435,20 +449,25 @@ fu! s:PrtSelectJump(char, ...)
en
keepj exe jmpln + 1
let s:cline = line('.')
if line('$') > winheight(0) | cal s:BuildPrompt(0, s:Focus()) | en
en
endf
"}}}
" Hooks {{{
" Misc {{{
fu! s:PrtClearCache()
let s:force = 1
if !s:itemtype
if s:itemtype == 1 | retu | en
if s:itemtype == 0
cal ctrlp#clr()
cal s:SetLines(s:itemtype)
cal s:BuildPrompt(1)
elsei s:itemtype == 2
let g:ctrlp_lines = ctrlp#mrufiles#list(-1, 1)
cal s:BuildPrompt(1)
elsei s:itemtype > 2
cal ctrlp#clr(s:statypes[s:itemtype][1])
en
if s:itemtype == 2
let g:ctrlp_lines = ctrlp#mrufiles#list(-1, 1)
el
cal s:SetLines(s:itemtype)
en
let s:force = 1
cal s:BuildPrompt(1)
unl s:force
endf
@ -475,8 +494,9 @@ fu! s:PrtHistory(...)
" Limit idx within 0 and hslen
let idx = idx < 0 ? 0 : idx >= hslen ? hslen > 1 ? hslen - 1 : 0 : idx
let s:prompt = [hst[idx], '', '']
let [s:hisidx, s:hstgot] = [idx, 1]
let [s:hisidx, s:hstgot, s:force] = [idx, 1, 1]
cal s:BuildPrompt(1)
unl s:force
endf
"}}}
"}}}
@ -513,12 +533,16 @@ fu! s:MapSpecs(...)
\ '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>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'PrtClearCache()': ['<F5>'],
\ 'PrtDeleteMRU()': ['<F8>'],
\ 'PrtDeleteMRU()': ['<F7>'],
\ 'CreateNewFile()': ['<c-y>'],
\ 'MarkToOpen()': ['<c-z>'],
\ 'OpenMulti()': ['<c-o>'],
@ -546,6 +570,10 @@ fu! s:MapSpecs(...)
\ 'PrtCurRight()',
\ 'PrtHistory(-1)',
\ 'PrtHistory(1)',
\ 'PrtInsert("w")',
\ 'PrtInsert("s")',
\ 'PrtInsert("v")',
\ 'PrtInsert("+")',
\ ]
for ke in prtunmaps | for kp in prtmaps[ke]
exe lcmap kp '<Nop>'
@ -582,19 +610,23 @@ endf
fu! s:ToggleType(dir)
let ext = exists('g:ctrlp_ext_vars') ? len(g:ctrlp_ext_vars) : 0
let s:itemtype = s:walker(g:ctrlp_builtins + ext, s:itemtype, a:dir)
cal s:Type(s:itemtype)
endf
fu! s:Type(type)
let s:itemtype = a:type
let s:extid = s:itemtype - ( g:ctrlp_builtins + 1 )
unl! g:ctrlp_nolimit
cal s:SetLines(s:itemtype)
cal s:PrtSwitcher()
cal s:syntax()
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
cal s:syntax()
en
endf
fu! s:PrtSwitcher()
let s:matches = 1
cal s:BuildPrompt(1, s:Focus(), 1)
let [s:force, s:matches] = [1, 1]
cal s:BuildPrompt(1, s:Focus())
unl s:force
endf
"}}}
fu! s:SetWD(...) "{{{
@ -602,12 +634,12 @@ fu! s:SetWD(...) "{{{
if exists('a:1') && len(a:1) == 1 && !type(a:1)
let pathmode = a:1
elsei exists('a:1') && len(a:1) > 1 && type(a:1)
cal s:setdir(a:1) | retu
cal ctrlp#setdir(a:1) | retu
en
if !exists('a:2')
if match(s:crfile, '^\<.\+\>://.*') >= 0 || !pathmode | retu | en
if exists('+acd') | let [s:glb_acd, &acd] = [&acd, 0] | en
cal s:setdir(s:crfpath)
cal ctrlp#setdir(s:crfpath)
en
if pathmode == 1 | retu | en
let markers = ['root.dir','.git/','.hg/','.vimprojects','_darcs/','.bzr/']
@ -639,15 +671,9 @@ fu! ctrlp#acceptfile(mode, matchstr)
exe bufwinnr.'winc w'
el
" Determine the command to use
if md == 't' || s:splitwin == 1
let cmd = 'tabe'
elsei md == 'h' || s:splitwin == 2
let cmd = 'new'
elsei md == 'v' || s:splitwin == 3
let cmd = 'vne'
el
let cmd = s:normcmd('e')
en
let cmd = md == 't' || s:splitwin == 1 ? 'tabe'
\ : md == 'h' || s:splitwin == 2 ? 'new'
\ : md == 'v' || s:splitwin == 3 ? 'vne' : ctrlp#normcmd('e')
" Open new window/buffer
cal s:openfile(cmd, filpath)
en
@ -679,15 +705,9 @@ fu! s:CreateNewFile() "{{{
let filpath = getcwd().s:lash.optyp
cal s:insertcache(str)
cal s:PrtExit()
if s:newfop == 1
let cmd = 'tabe'
elsei s:newfop == 2
let cmd = 'new'
elsei s:newfop == 3
let cmd = 'vne'
el
let cmd = s:normcmd('e')
en
let cmd = s:newfop == 1 ? 'tabe'
\ : s:newfop == 2 ? 'new'
\ : s:newfop == 3 ? 'vne' : ctrlp#normcmd('e')
cal s:openfile(cmd, filpath)
en
endf "}}}
@ -808,7 +828,7 @@ fu! s:mixedsort(s1, s2)
if s:itemtype < 3 && s:height < 51
let par = s:comparent(a:s1, a:s2)
if s:height < 21
retu 6 * cml + 3 * par + 2 * s:comptime(a:s1, a:s2) + 1 * cln
retu 6 * cml + 3 * par + 2 * s:comptime(a:s1, a:s2) + cln
en
retu 3 * cml + 2 * par + cln
en
@ -862,7 +882,7 @@ endf
fu! s:parentdir(curr)
let parent = s:getparent(a:curr)
if parent != a:curr | cal s:setdir(parent) | en
if parent != a:curr | cal ctrlp#setdir(parent) | en
endf
fu! s:getparent(item)
@ -899,11 +919,11 @@ 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
if notfound | cal s:setdir(s:cwd) | en
if notfound | cal ctrlp#setdir(s:cwd) | en
if a:type
let s:vcsroot = depth <= s:maxdepth ? a:curr : ''
el
cal s:setdir(a:curr)
cal ctrlp#setdir(a:curr)
let s:foundroot = 1
en
el
@ -916,15 +936,15 @@ fu! s:glbpath(...)
retu call('globpath', v:version > 701 ? [a:1, a:2, a:3] : [a:1, a:2])
endf
fu! s:fnesc(path)
fu! ctrlp#fnesc(path)
retu exists('*fnameescape') ? fnameescape(a:path) : escape(a:path, " %#*?|<\"\n")
endf
fu! s:setdir(path)
fu! ctrlp#setdir(path)
try
exe 'lc!' s:fnesc(a:path)
exe 'lc!' ctrlp#fnesc(a:path)
cat
cal s:msg("Can't change working dir. Directory not exists.")
cal ctrlp#msg("Can't change working dir. Directory not exists.")
endt
endf
"}}}
@ -938,7 +958,7 @@ endf
fu! s:highlight(pat, grp)
cal clearmatches()
if !empty(a:pat) && a:pat != '..'
if !empty(a:pat) && a:pat != '..' && s:itemtype < 3
let pat = substitute(a:pat, '\~', '\\~', 'g')
if !s:regexp | let pat = escape(pat, '.') | en
" Match only filename
@ -950,6 +970,11 @@ fu! s:highlight(pat, grp)
cal matchadd('CtrlPLineMarker', '^>')
en
endf
fu! s:dohighlight()
retu type(s:mathi) == 3 && len(s:mathi) == 2 && s:mathi[0]
\ && exists('*clearmatches')
endf
"}}}
" Prompt history {{{
fu! s:gethistloc()
@ -1033,7 +1058,7 @@ fu! s:normbuf()
retu winnrs
endf
fu! s:normcmd(cmd)
fu! ctrlp#normcmd(cmd)
if !empty(s:nosplit) && match([bufname('%'), &l:ft], s:nosplit) >= 0
retu a:cmd
en
@ -1111,20 +1136,30 @@ fu! s:specinputs()
retu 0
endf
fu! s:lastvisual()
let [cview, oreg, oreg_type] = [winsaveview(), getreg('v'), getregtype('v')]
norm! gv"vy
let selected = substitute(getreg('v'), '\n', '\\n', 'g')
cal setreg('v', oreg, oreg_type)
cal winrestview(cview)
retu selected
endf
fu! s:openfile(cmd, filpath)
let cmd = a:cmd == 'e' && &modified ? 'hid e' : a:cmd
let tail = s:tail()
try
exe cmd.s:tail().' '.s:fnesc(a:filpath)
exe cmd.tail.' '.ctrlp#fnesc(a:filpath)
cat
cal s:msg("Operation can't be completed. Make sure filename is valid.")
cal ctrlp#msg("Operation can't be completed. Make sure filename is valid.")
fina
if !empty(s:tail())
if !empty(tail)
sil! norm! zOzz
en
endt
endf
fu! s:msg(msg)
fu! ctrlp#msg(msg)
echoh Identifier | echon "CtrlP: ".a:msg | echoh None
endf
@ -1158,10 +1193,14 @@ fu! s:walker(max, pos, dir)
retu a:dir > 0 ? a:pos < a:max ? a:pos + 1 : 0 : a:pos > 0 ? a:pos - 1 : a:max
endf
fu! s:matchsubstr(item, pat)
fu! s:matchfname(item, pat)
retu match(split(a:item, '[\/]\ze[^\/]\+$')[-1], a:pat)
endf
fu! s:matchtab(item, pat)
retu match(split(a:item, '\t[^\t]\+$')[0], a:pat)
endf
fu! s:maxfiles(len)
retu s:maxfiles && a:len > s:maxfiles ? 1 : 0
endf
@ -1184,7 +1223,7 @@ fu! s:insertcache(str)
endf
fu! s:lscommand()
let cmd = g:ctrlp_user_command
let cmd = s:usrcmd
if type(cmd) == 1
retu cmd
elsei type(cmd) == 3 && len(cmd) >= 2 && !empty(cmd[0]) && !empty(cmd[1])
@ -1232,6 +1271,9 @@ if has('autocmd') "{{{
au BufEnter ControlP cal s:checkbuf()
au BufLeave ControlP cal s:Close()
au VimLeavePre * cal s:leavepre()
if s:lazy
au CursorHold ControlP cal s:ForceUpdate()
en
aug END
en "}}}

View File

@ -7,13 +7,13 @@
" Static variables {{{
fu! ctrlp#mrufiles#opts()
let opts = {
\ 'g:ctrlp_mruf_max': ['s:max', 150],
\ 'g:ctrlp_mruf_max': ['s:max', 250],
\ 'g:ctrlp_mruf_include': ['s:include', ''],
\ 'g:ctrlp_mruf_exclude': ['s:exclude', ''],
\ 'g:ctrlp_mruf_case_sensitive': ['s:csen', 1],
\ }
for [ke, va] in items(opts)
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1]) '| unl!' ke
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1])
endfo
endf
cal ctrlp#mrufiles#opts()

View File

@ -0,0 +1,56 @@
" =============================================================================
" File: autoload/ctrlp/quickfix.vim
" Description: Quickfix extension
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" Init {{{
if exists('g:loaded_ctrlp_quickfix') && g:loaded_ctrlp_quickfix
fini
en
let g:loaded_ctrlp_quickfix = 1
let s:var_qf = ['ctrlp#quickfix#init()', 'ctrlp#quickfix#accept', 'quickfix',
\ 'qfx', [1]]
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]
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
fu! s:lineout(dict)
retu printf('%s|%d:%d| %s', bufname(a:dict['bufnr']), a:dict['lnum'],
\ a:dict['col'], matchstr(a:dict['text'], '\s*\zs.*\S'))
endf
"}}}
" Public {{{
fu! ctrlp#quickfix#init()
let g:ctrlp_nolimit = 1
sy match CtrlPqfLineCol '|\zs\d\+:\d\+\ze|'
hi def link CtrlPqfLineCol Search
retu map(getqflist(), 's:lineout(v:val)')
endf
fu! ctrlp#quickfix#accept(mode, str)
let items = matchlist(a:str, '^\([^|]\+\ze\)|\(\d\+\):\(\d\+\)|')
let [md, filpath] = [a:mode, fnamemodify(items[1], ':p')]
if empty(filpath) | retu | en
cal ctrlp#exit()
let cmd = md == 't' ? 'tabe' : md == 'h' ? 'new' : md == 'v' ? 'vne'
\ : ctrlp#normcmd('e')
let cmd = cmd == 'e' && &modified ? 'hid e' : cmd
try
exe cmd.' '.ctrlp#fnesc(filpath)
cat
cal ctrlp#msg("Invalid command or argument.")
fina
cal cursor(items[2], items[3]) | sil! norm! zOzz
endt
endf
fu! ctrlp#quickfix#id()
retu s:id
endf
"}}}
" vim:fen:fdl=0:ts=2:sw=2:sts=2

58
autoload/ctrlp/tag.vim Normal file
View File

@ -0,0 +1,58 @@
" =============================================================================
" File: autoload/ctrlp/tag.vim
" Description: Tag file extension
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" Init {{{
if exists('g:loaded_ctrlp_tag') && g:loaded_ctrlp_tag
fini
en
let [g:loaded_ctrlp_tag, g:ctrlp_newtag] = [1, 0]
let s:tag_var = ['ctrlp#tag#init()', 'ctrlp#tag#accept', 'tags', 'tag']
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:tag_var) : [s:tag_var]
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
"}}}
" Public {{{
fu! ctrlp#tag#init()
if exists('s:cwd') && s:cwd == getcwd()
let newtags = 0
el
let s:cwd = getcwd()
let newtags = 1
en
if ( newtags && !exists('g:ctrlp_alltags['''.s:cwd.''']') ) || g:ctrlp_newtag
let alltags = map(taglist('.*'), 'v:val["name"]." ".v:val["filename"]')
cal extend(g:ctrlp_alltags, { s:cwd : alltags })
let g:ctrlp_newtag = 0
en
sy match CtrlPTagFilename '\zs\t.*\ze$'
hi link CtrlPTagFilename Comment
retu g:ctrlp_alltags[s:cwd]
endf
fu! ctrlp#tag#accept(mode, str)
cal ctrlp#exit()
let md = a:mode
let cmd = md == 't' ? 'tabnew' : md == 'h' ? 'new' : md == 'v' ? 'vne'
\ : ctrlp#normcmd('ene')
let cmd = cmd == 'ene' && &modified ? 'hid ene' : cmd
try
exe cmd
cal ctrlp#setdir(s:cwd)
exe 'ta' split(a:str, '\t[^\t]\+$')[0]
cat
cal ctrlp#msg("Tag not found.")
endt
endf
fu! ctrlp#tag#id()
retu s:id
endf
"}}}
" vim:fen:fdl=0:ts=2:sw=2:sts=2

View File

@ -26,9 +26,10 @@ fu! ctrlp#utils#cachedir()
retu s:cache_dir
endf
fu! ctrlp#utils#cachefile()
let cache_file = substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').'.txt'
retu s:cache_dir.s:lash.cache_file
fu! ctrlp#utils#cachefile(...)
let tail = exists('a:1') ? '.'.a:1 : ''
let cache_file = substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').tail.'.txt'
retu exists('a:1') ? cache_file : s:cache_dir.s:lash.cache_file
endf
fu! ctrlp#utils#readfile(file)

View File

@ -1,4 +1,4 @@
*ctrlp.txt* Fuzzy file, buffer and MRU file finder. v1.6.1
*ctrlp.txt* Fuzzy file, buffer and MRU file finder. v1.6.2
*CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'*
===============================================================================
# #
@ -18,6 +18,7 @@ CONTENTS *ctrlp-contents*
3. Commands.....................................|ctrlp-commands|
4. Mappings.....................................|ctrlp-mappings|
5. Input Formats................................|ctrlp-input-formats|
6. Extensions...................................|ctrlp-extensions|
===============================================================================
1. Intro *ctrlp-intro*
@ -27,6 +28,8 @@ Written in pure Vimscript for MacVim and Vim version 7.0+. Has full support for
Vims |regexp| as search pattern, built-in MRU monitoring, projects root
finder, and more.
To enable optional extensions (tag, quickfix ...), see |ctrlp-extensions|.
===============================================================================
2. Options *ctrlp-options*
@ -141,7 +144,7 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'PrtCurLeft()': ['<c-h>', '<left>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'PrtClearCache()': ['<F5>'],
\ 'PrtDeleteMRU()': ['<F8>'],
\ 'PrtDeleteMRU()': ['<F7>'],
\ 'CreateNewFile()': ['<c-y>'],
\ 'MarkToOpen()': ['<c-z>'],
\ 'OpenMulti()': ['<c-o>'],
@ -151,7 +154,7 @@ only need to keep the lines that youve changed the values (inside []): >
*'g:ctrlp_mruf_max'*
Specify the number of recently opened files you want |CtrlP| to remember: >
let g:ctrlp_mruf_max = 150
let g:ctrlp_mruf_max = 250
<
*'g:ctrlp_mruf_exclude'*
@ -194,7 +197,7 @@ this.
Other note: |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).
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_highlight_match'*
@ -215,8 +218,8 @@ The maximum depth of a directory tree to recurse into: >
Note: the larger these values, the more memory Vim uses.
*'g:ctrlp_user_command'*
Specify an external tool to use for listing files instead of using Vims
globpath(). Use %s in place of the target directory: >
Specify an external tool to use for listing files instead of Vims globpath().
Use %s in place of the target directory: >
let g:ctrlp_user_command = ''
<
Examples: >
@ -233,7 +236,7 @@ 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
when outside a repo.
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 .']
@ -252,7 +255,7 @@ pressing <c-y>:
*'g:ctrlp_max_history'*
The maximum number of input strings you want |CtrlP| to remember. The default
value mirrors Vims global |'history'| option. E.g. `set history=50`: >
value mirrors Vims global |'history'| option: >
let g:ctrlp_max_history = &history
<
Set to 0 to disable prompts history.
@ -285,23 +288,32 @@ Set this to 1 to follow symbolic links when listing files: >
let g:ctrlp_follow_symlinks = 0
<
*'g:ctrlp_lazy_update'*
Set this to 1 to enable the lazy-update feature: only update the match window
after typings been stopped for a certain amount of time: >
let g:ctrlp_lazy_update = 0
<
If is 1, update after 250ms. If bigger than 1, the number will be used as the
delay time in milliseconds.
===============================================================================
3. Commands *ctrlp-commands*
*:CtrlP*
:CtrlP [starting-directory]
Open the |CtrlP| prompt in find file mode.
Open |CtrlP| in find file mode.
If no argument is given, the value of |g:ctrlp_working_path_mode| will be
used to determine the starting directory.
You can use <tab> to auto-complete the [starting-directory] when typing it.
*:CtrlPBuffer*
:CtrlPBuffer
Open the |CtrlP| prompt in find buffer mode.
Open |CtrlP| in find buffer mode.
*:CtrlPMRU*
:CtrlPMRU
Open the |CtrlP| prompt in find Most-Recently-Used file mode.
Open |CtrlP| in find Most-Recently-Used file mode.
*:ClearCtrlPCache*
:ClearCtrlPCache
@ -333,7 +345,7 @@ The following commands ignore the current value of |g:ctrlp_working_path_mode|:
*'ctrlp-<c-p>'*
<c-p>
Default |Normal| mode mapping to open the |CtrlP| prompt.
Default |Normal| mode mapping to open the |CtrlP| prompt in find file mode.
Once inside the prompt:~
@ -349,12 +361,11 @@ Once inside the prompt:~
<c-f>, 'forward'
<c-up>
Scroll to the 'next' search type in the sequence. Currently file, buffer
and most recently used file (MRU) are available.
Scroll to the 'next' search mode in the sequence.
<c-b>, 'backward'
<c-down>
Scroll to the 'previous' search type in the sequence.
Scroll to the 'previous' search mode in the sequence.
<tab>
Toggle the focus between the match window and the prompt.
@ -388,7 +399,7 @@ Once inside the prompt:~
Clear the input field
<cr>
Open selected file with the method specified with |g:ctrlp_split_window|
Open selected file in the active window if possible.
<c-t>
Open selected file in a new 'tab'
@ -405,10 +416,10 @@ Once inside the prompt:~
Create a new file and its parent directories.
<c-n>
'Next' string in the prompts history
Next string in the prompts history
<c-p>
'Previous' string in the prompts history
Previous string in the prompts history
<c-z>
Mark/unmark a file to be opened with <c-o>.
@ -417,11 +428,11 @@ Once inside the prompt:~
Open files marked by <c-z>.
<F5>
Refresh the match window and purge the cache for the current directory.
Or remove deleted files from MRU list.
- Refresh the match window and purge the cache for the current directory.
- Remove deleted files from MRU list.
<F8>
Clear the MRU list.
<F7>
Clear MRU list.
<esc>,
<c-c>,
@ -478,30 +489,52 @@ f) Type the name of a non-existent file and press <c-y> to create it.
g) Submit ? to open this help file.
===============================================================================
6. Extensions *ctrlp-extensions*
Extensions are optional. To enable an extension, add its name to the variable
g:ctrlp_extensions: >
let g:ctrlp_extensions = ['tag', 'qfx']
<
Available extensions:~
* Tag mode:~
- Shortname: 'tag'
- Command: ':CtrlPTag'
- Search for a tag within a generated central tags file, and jump to the
definition. Use the Vims option |'tags'| to specify the names and the
locations of the tags file(s). Example: `set tags+=tags/help,doc/tags`
* Quickfix mode:~
- Shortname: 'qfx'
- Command: ':CtrlPQuickfix'
- Search for an entry in the current quickfix errors and jump to it. If the
===============================================================================
EXTENDING *ctrlp-extending*
Extending |CtrlP| is very simple. Simply create a .vim file following a short
Extending |CtrlP| is very simple. Simply create a vim file following a short
guidelines, place it in autoload/ctrlp/ and add its name to your .vimrc.
To see how it all works, get the sample.vim from the 'extensions' branch on the
main git repository (https://github.com/kien/ctrlp.vim/tree/extensions), and
place it (along with the parent directories) somewhere in your runtimepath.
Then put this into your .vimrc: >
To see how it works, get the sample.vim from the extensions branch on the main
git repository (https://github.com/kien/ctrlp.vim/tree/extensions), and place
it along with the parent directories somewhere in your runtimepath. Then put
this into your .vimrc: >
let g:ctrlp_extensions = ['sample']
<
A 4th search type will show up the next time you open |CtrlP|.
A new search type will show up the next time you open |CtrlP|.
For more details, check out the comments inside sample.vim.~
===============================================================================
CREDITS *ctrlp-credits*
Developed by Kien Nguyen (github.com/kien), initially 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
clone the majority of their (awesome) interfaces and the way they work.
The was originally written as a module for a would-be larger plugin called
This was originally written as a module for a would-be larger plugin called
AutoDoc.vim which Ive stopped developing because of lost of interest. I really
liked the way Command-T and LustyExplorer deal with users input, so I wrote a
pure Vimscript version of their prompt window, intended to use it for the
@ -525,12 +558,13 @@ Special thanks:~
===============================================================================
CHANGELOG *ctrlp-changelog*
+ New option: |g:ctrlp_follow_symlinks|
+ New features: Tag and Quickfix extensions.
+ New options: |g:ctrlp_lazy_update|,
|g:ctrlp_follow_symlinks|
Before 2011/11/13~
+ 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.
@ -597,4 +631,4 @@ Before 2011/09/12~
First public release: 2011/09/06~
===============================================================================
vim:et:ts=2:sw=2:sts=2
vim:ft=help:et:ts=2:sw=2:sts=2:norl

View File

@ -8,7 +8,7 @@
if ( exists('g:loaded_ctrlp') && g:loaded_ctrlp ) || v:version < 700 || &cp
fini
en
let g:loaded_ctrlp = 1
let [g:loaded_ctrlp, g:ctrlp_lines, g:ctrlp_allfiles] = [1, [], []]
if !exists('g:ctrlp_map') | let g:ctrlp_map = '<c-p>' | en
@ -29,4 +29,12 @@ exe 'nn <silent>' g:ctrlp_map ':<c-u>CtrlP<cr>'
cal ctrlp#mrufiles#init()
let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []]
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())
en
if index(g:ctrlp_extensions, 'quickfix') >= 0
com! CtrlPQuickfix cal ctrlp#init(ctrlp#quickfix#id())
en

View File

@ -12,7 +12,7 @@ Full path fuzzy __file__, __buffer__ and __MRU__ file finder for Vim.
## Basic Usage
* Press `<c-p>` or run `:CtrlP` to invoke CtrlP in find file mode.
* Or use `:CtrlPBuffer` and `:CtrlPMRU` for buffer and MRU mode.
* Or run `:CtrlPBuffer` or `:CtrlPMRU` to invoke CtrlP in buffer or MRU mode.
Once CtrlP is open: