New feature: search most recently opened files

This commit is contained in:
Kien N 2011-09-07 21:41:43 +07:00
parent e50970f80e
commit fbcfec256e
6 changed files with 348 additions and 99 deletions

View File

@ -83,7 +83,6 @@ if !exists('g:ctrlp_cache_dir')
let s:cache_dir = $HOME let s:cache_dir = $HOME
else else
let s:cache_dir = g:ctrlp_cache_dir let s:cache_dir = g:ctrlp_cache_dir
unl g:ctrlp_cache_dir
endif endif
if !exists('g:ctrlp_newcache') if !exists('g:ctrlp_newcache')
@ -96,42 +95,25 @@ else
let s:byfname = g:ctrlp_by_filename let s:byfname = g:ctrlp_by_filename
unl g:ctrlp_by_filename unl g:ctrlp_by_filename
endif endif
if !exists('g:ctrlp_prompt_mappings')
let s:urprtmaps = 0
else
let s:urprtmaps = g:ctrlp_prompt_mappings
unl g:ctrlp_prompt_mappings
endif
"}}} "}}}
" Caching {{{ " Clear caches {{{
func! s:GetDataFile(file)
if filereadable(a:file) | retu readfile(a:file) | endif
endfunc
func! s:CacheDir()
retu exists('*mkdir') ? s:cache_dir.s:lash().'.ctrlp_cache' : s:cache_dir
endfunc
func! s:CacheFile()
retu s:CacheDir().s:lash().substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').'.txt'
endfunc
func! s:WriteCache(lines)
let cache_dir = s:CacheDir()
" create directory if not existed
if exists('*mkdir') && !isdirectory(cache_dir)
sil! cal mkdir(cache_dir)
endif
" write cache
if isdirectory(cache_dir)
sil! cal writefile(a:lines, s:CacheFile())
let g:ctrlp_newcache = 0
endif
endfunc
func! ctrlp#clearcache() func! ctrlp#clearcache()
let g:ctrlp_newcache = 1 let g:ctrlp_newcache = 1
endfunc endfunc
func! ctrlp#clearallcaches() func! ctrlp#clearallcaches()
let cache_dir = s:CacheDir() let cache_dir = ctrlp#utils#cachedir()
if isdirectory(cache_dir) && match(cache_dir, '.ctrlp_cache') >= 0 if isdirectory(cache_dir) && match(cache_dir, '.ctrlp_cache') >= 0
let cache_files = split(globpath(cache_dir, '*.txt'), '\n') let cache_files = split(globpath(cache_dir, '*.txt'), '\n')
cal filter(cache_files, '!isdirectory(v:val)')
try try
for each in cache_files | cal delete(each) | endfor for each in cache_files | cal delete(each) | endfor
catch catch
@ -145,27 +127,27 @@ endfunc
"}}} "}}}
func! s:ListAllFiles(path) "{{{ func! s:ListAllFiles(path) "{{{
let cache_file = s:CacheFile() let cache_file = ctrlp#utils#cachefile()
if g:ctrlp_newcache || !filereadable(cache_file) || s:caching == 0 if g:ctrlp_newcache || !filereadable(cache_file) || s:caching == 0
let allfiles = split(globpath(a:path, '**'), '\n') let allfiles = split(globpath(a:path, '**'), '\n')
cal filter(allfiles, '!isdirectory(v:val)') cal filter(allfiles, '!isdirectory(v:val)')
" filter all entries matched wildignore's patterns (in addition to globpath's) " filter all entries matched wildignore's patterns (in addition to globpath's)
if exists('+wig') && !empty(&wig) if exists('+wig') && !empty(&wig)
let ignores = map(split(&wig, ','), 'substitute(v:val, "\\W\\+", ".*", "g")') let ignores = map(split(&wig, ','), 'substitute(v:val, "\\W\\+", ".*", "g")')
cal filter(allfiles, 's:matchlists(v:val, "'.string(ignores).'")') cal filter(allfiles, 's:matchlists(v:val, string(ignores))')
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(allfiles, 'substitute(v:val, "'.path.'", "", "g")') cal map(allfiles, 'substitute(v:val, path, "", "g")')
else else
let allfiles = s:GetDataFile(cache_file) let allfiles = ctrlp#utils#readfile(cache_file)
endif endif
if len(allfiles) <= 3000 | cal sort(allfiles, 's:compare') | endif if len(allfiles) <= 3000 | cal sort(allfiles, 's:compare') | endif
" write cache " write cache
if ( g:ctrlp_newcache || !filereadable(cache_file) ) && s:caching if ( g:ctrlp_newcache || !filereadable(cache_file) ) && s:caching
\ || len(allfiles) > 4000 \ || len(allfiles) > 4000
if len(allfiles) > 4000 | let s:caching = 1 | endif if len(allfiles) > 4000 | let s:caching = 1 | endif
cal s:WriteCache(allfiles) cal ctrlp#utils#writecache(allfiles)
endif endif
retu allfiles retu allfiles
endfunc "}}} endfunc "}}}
@ -240,7 +222,7 @@ func! s:GetMatchedItems(items, pats, limit) "{{{
let items = newitems let items = newitems
endif endif
if empty(items) if empty(items)
retu newitems retu exists('newitems') ? newitems : []
else else
let newitems = [] let newitems = []
" loop through the items " loop through the items
@ -259,7 +241,7 @@ func! s:GetMatchedItems(items, pats, limit) "{{{
endfunc "}}} endfunc "}}}
func! s:SetupBlank(name) "{{{ func! s:SetupBlank(name) "{{{
exe 'setl ft='.a:name cal s:item2buf()
setl bt=nofile setl bt=nofile
setl bh=delete setl bh=delete
setl noswf setl noswf
@ -372,7 +354,7 @@ func! s:Renderer(lines) "{{{
else else
" If empty " If empty
setl nocul setl nocul
cal setline('1', '== NO MATCHES ==') cal setline('1', ' == NO MATCHES ==')
endif endif
" Remember selected line " Remember selected line
if exists('g:CtrlP_cline') if exists('g:CtrlP_cline')
@ -386,7 +368,7 @@ func! s:UpdateMatches(pat) "{{{
let newpat = s:SplitPattern(a:pat) let newpat = s:SplitPattern(a:pat)
let lines = s:GetMatchedItems(s:lines, newpat, s:mxheight) let lines = s:GetMatchedItems(s:lines, newpat, s:mxheight)
cal s:Renderer(lines) cal s:Renderer(lines)
cal s:Highlight(newpat) "cal s:Highlight(newpat)
endfunc "}}} endfunc "}}}
func! s:BuildPrompt(...) "{{{ func! s:BuildPrompt(...) "{{{
@ -398,10 +380,11 @@ func! s:BuildPrompt(...) "{{{
let start = escape(g:CtrlP_prompt[0], estr) let start = escape(g:CtrlP_prompt[0], estr)
let mid = escape(g:CtrlP_prompt[1], estr) let mid = escape(g:CtrlP_prompt[1], estr)
let end = escape(g:CtrlP_prompt[2], estr) let end = escape(g:CtrlP_prompt[2], estr)
cal s:UpdateMatches(start.mid.end)
" Toggling " Toggling
if !exists('a:1') || a:1 if !exists('a:1') || ( exists('a:1') && a:1 )
let hiactive = 'Normal' let hiactive = 'Normal'
elseif exists('a:1') || a:1 == 0 elseif exists('a:1') || ( exists('a:1') && a:1 == 0 )
let hiactive = 'Comment' let hiactive = 'Comment'
let base = substitute(base, '>', '-', 'g') let base = substitute(base, '>', '-', 'g')
endif endif
@ -417,7 +400,6 @@ func! s:BuildPrompt(...) "{{{
if empty(mid) && ( !exists('a:1') || ( exists('a:1') && a:1 ) ) if empty(mid) && ( !exists('a:1') || ( exists('a:1') && a:1 ) )
exe 'echohl' hibase '| echon "'.cur.'" | echohl None' exe 'echohl' hibase '| echon "'.cur.'" | echohl None'
endif endif
sil! cal s:UpdateMatches(start.mid.end)
endfunc "}}} endfunc "}}}
"Mightdo: PrtSelectJump() cycles through matches. /medium "Mightdo: PrtSelectJump() cycles through matches. /medium
@ -510,14 +492,14 @@ func! s:MapKeys(...)
let func = !exists('a:1') || ( exists('a:1') && a:1 ) ? 'PrtAdd' : 'PrtSelectJump' let func = !exists('a:1') || ( exists('a:1') && a:1 ) ? 'PrtAdd' : 'PrtSelectJump'
let sjbyfname = s:byfname && func == 'PrtSelectJump' ? ', 1' : '' let sjbyfname = s:byfname && func == 'PrtSelectJump' ? ', 1' : ''
for each in range(32,126) for each in range(32,126)
sil! exe "nn \<buffer> \<silent> \<char-".each."> :cal \<SID>".func."(\"".escape(nr2char(each), '"|\')."\"".sjbyfname.")\<cr>" exe "nn \<buffer> \<silent> \<char-".each."> :cal \<SID>".func."(\"".escape(nr2char(each), '"|\')."\"".sjbyfname.")\<cr>"
endfor endfor
if exists('a:2') | retu | endif if exists('a:2') | retu | endif
" Special keystrokes " Special keystrokes
if exists('a:1') && a:1 == 0 if exists('a:1') && a:1 == 0
sil! cal s:MapSpecs('unmap') cal s:MapSpecs('unmap')
else else
sil! cal s:MapSpecs() cal s:MapSpecs()
endif endif
endfunc endfunc
@ -536,16 +518,31 @@ func! s:MapSpecs(...)
\ 'ToggleFocus()': ['<tab>'], \ 'ToggleFocus()': ['<tab>'],
\ 'ToggleRegex()': ['<c-r>'], \ 'ToggleRegex()': ['<c-r>'],
\ 'ToggleByFname()': ['<c-d>'], \ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType()': ['<c-f>'], \ 'ToggleType(1)': ['<c-f>', '<c-up'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'Type(0)': ['<m-1>'],
\ 'Type(1)': ['<m-2>'],
\ 'Type(2)': ['<m-3>'],
\ 'PrtCurStart()': ['<c-a>'], \ 'PrtCurStart()': ['<c-a>'],
\ 'PrtCurEnd()': ['<c-e>'], \ 'PrtCurEnd()': ['<c-e>'],
\ 'PrtCurLeft()': ['<c-h>', '<left>'], \ 'PrtCurLeft()': ['<c-h>', '<left>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'], \ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'BufOpen("ControlP", "del")': ['<esc>', '<c-c>', '<c-g>'], \ 'BufOpen("ControlP", "del")': ['<esc>', '<c-c>'],
\ } \ }
if exists('g:ctrlp_prompt_mappings') && type(g:ctrlp_prompt_mappings) == 4 if type(s:urprtmaps) == 4
sil! cal extend(prtmaps, g:ctrlp_prompt_mappings) 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 == 0
cal remove(prtmaps, each)
endif
endfor
if exists('a:1') && a:1 == 'unmap' if exists('a:1') && a:1 == 'unmap'
let prtunmaps = [ let prtunmaps = [
\ 'PrtBS()', \ 'PrtBS()',
@ -558,11 +555,11 @@ func! s:MapSpecs(...)
\ 'PrtCurRight()', \ 'PrtCurRight()',
\ ] \ ]
for each in prtunmaps | for kp in prtmaps[each] for each in prtunmaps | for kp in prtmaps[each]
sil! exe 'nn <buffer> <silent>' kp '<Nop>' exe 'nn <buffer> <silent>' kp '<Nop>'
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]
sil! exe 'nn <buffer> <silent>' kp ':cal <SID>'.each.'<cr>' exe 'nn <buffer> <silent>' kp ':cal <SID>'.each.'<cr>'
endfor | endfor endfor | endfor
endif endif
endfunc endfunc
@ -591,8 +588,16 @@ func! s:ToggleByFname() "{{{
cal s:BuildPrompt(s:Focus()) cal s:BuildPrompt(s:Focus())
endfunc "}}} endfunc "}}}
func! s:ToggleType() "{{{ func! s:ToggleType(dir) "{{{
let s:itemtype = s:itemtype ? 0 : 1 let len = 1 + g:ctrlp_mru_files
let s:itemtype = s:walker(len, s:itemtype, a:dir)
cal s:Type(s:itemtype)
endfunc "}}}
func! s:Type(type) "{{{
let s:itemtype = a:type
cal s:item2buf()
cal s:syntax()
cal s:SetLines(s:itemtype) cal s:SetLines(s:itemtype)
cal s:BuildPrompt(s:Focus()) cal s:BuildPrompt(s:Focus())
endfunc "}}} endfunc "}}}
@ -609,11 +614,11 @@ endfunc "}}}
" ctrlp#SetWorkingPath(...) {{{ " ctrlp#SetWorkingPath(...) {{{
func! s:FindRoot(curr, mark) func! s:FindRoot(curr, mark)
if !empty(globpath(a:curr, a:mark)) if !empty(globpath(a:curr, a:mark))
sil! exe 'chdir' a:curr exe 'chdir' a:curr
else else
let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]*$', '', '') let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]*$', '', '')
if parent != a:curr if parent != a:curr
sil! cal s:FindRoot(parent, a:mark) cal s:FindRoot(parent, a:mark)
endif endif
endif endif
endfunc endfunc
@ -630,7 +635,7 @@ func! ctrlp#SetWorkingPath(...)
if exists('+acd') if exists('+acd')
se noacd se noacd
endif endif
sil! exe 'chdir' fnameescape(expand('%:p:h')) exe 'chdir' fnameescape(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',
@ -643,10 +648,10 @@ func! ctrlp#SetWorkingPath(...)
if exists('g:ctrlp_root_markers') if exists('g:ctrlp_root_markers')
\ && type(g:ctrlp_root_markers) == 3 \ && type(g:ctrlp_root_markers) == 3
\ && !empty(g:ctrlp_root_markers) \ && !empty(g:ctrlp_root_markers)
sil! cal extend(markers, g:ctrlp_root_markers, 0) cal extend(markers, g:ctrlp_root_markers, 0)
endif endif
for marker in markers for marker in markers
sil! cal s:FindRoot(getcwd(), marker) cal s:FindRoot(getcwd(), marker)
if getcwd() != expand('%:p:h') | break | endif if getcwd() != expand('%:p:h') | break | endif
endfor endfor
endfunc endfunc
@ -655,11 +660,11 @@ endfunc
func! s:AcceptSelection(mode) "{{{ func! s:AcceptSelection(mode) "{{{
let md = a:mode let md = a:mode
let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$') let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$')
let filepath = s:itemtype ? matchstr : getcwd().s:lash().matchstr let filepath = s:itemtype ? matchstr : getcwd().ctrlp#utils#lash().matchstr
let filename = split(filepath, s:lash())[-1] let filename = split(filepath, ctrlp#utils#lash())[-1]
" Remove the prompt and match window " Remove the prompt and match window
sil! cal s:BufOpen('ControlP', 'del') cal s:BufOpen('ControlP', 'del')
" Setup a new window for the selected entry " Do an action on 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'
@ -692,6 +697,35 @@ func! s:compare(s1, s2)
retu str1 == str2 ? 0 : str1 > str2 ? 1 : -1 retu str1 == str2 ? 0 : str1 > str2 ? 1 : -1
endfunc endfunc
func! s:walker(max, pos, dir)
if a:dir == 1
if a:pos < a:max
let pos = a:pos + 1
elseif a:pos == a:max
let pos = 0
endif
elseif a:dir == -1
if a:pos > 0
let pos = a:pos - 1
elseif a:pos == 0
let pos = a:max
endif
endif
if g:ctrlp_mru_files == 0 && pos == 2
let pos = a:pos == 1 ? 3 : 1
endif
retu pos
endfunc
func! s:item2buf()
let item2buf = {
\ 0: '_Files',
\ 1: '_Buffers',
\ 2: '_Recent_Files',
\ }
exe 'setf' item2buf[s:itemtype]
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
@ -703,35 +737,43 @@ func! s:matchlists(item, lst)
retu 1 retu 1
endfunc endfunc
func! s:lash() func! s:syntax()
retu &ssl || !exists('+ssl') ? '/' : '\' syn match CtrlPNoEntries '^ == NO MATCHES ==$'
endfunc syn match CtrlPNoEntries '^ == DISABLED ==$'
func! s:Syntax()
syn match CtrlPNoEntries '^== NO MATCHES ==$'
syn match CtrlPLineMarker '^>' syn match CtrlPLineMarker '^>'
hi link CtrlPNoEntries Error hi link CtrlPNoEntries Error
hi CtrlPLineMarker guifg=bg hi CtrlPLineMarker guifg=bg
endfunc endfunc
"}}} "}}}
" Initialization {{{ func! s:SetLines(type) "{{{
func! s:SetLines(type)
let s:itemtype = a:type let s:itemtype = a:type
let s:lines = s:itemtype ? s:ListAllBuffers() : s:ListAllFiles(getcwd()) if s:itemtype == 0
endfunc let s:lines = s:ListAllFiles(getcwd())
elseif s:itemtype == 1
let s:lines = s:ListAllBuffers()
elseif s:itemtype >= 2
let s:lines = s:hooks(s:itemtype)
endif
endfunc "}}}
func! ctrlp#init(type) func! s:hooks(type) "{{{
cal ctrlp#SetWorkingPath() let types = {
cal s:SetLines(a:type) \ '2': 'ctrlp#mrufiles#list(-1)'
cal s:BufOpen('ControlP') \ }
cal s:SetupBlank('ctrlp') retu eval(types[a:type])
cal s:MapKeys() endfunc "}}}
cal s:Renderer(s:lines)
func! ctrlp#init(type) "{{{
sil! cal ctrlp#SetWorkingPath()
sil! cal s:SetLines(a:type)
sil! cal s:BufOpen('ControlP')
sil! cal s:SetupBlank(s:itemtype)
sil! cal s:MapKeys()
sil! cal s:Renderer(s:lines)
cal s:BuildPrompt() cal s:BuildPrompt()
cal s:Syntax() sil! cal s:syntax()
endfunc endfunc "}}}
"}}}
aug CtrlPAug "{{{ aug CtrlPAug "{{{
au! au!

View File

@ -0,0 +1,72 @@
" =============================================================================
" File: autoload/ctrlp/mrufiles.vim
" Description: Most Recently Used Files extension
" Author: Kien Nguyen <github.com/kien>
" License: MIT
" =============================================================================
if v:version < '700' "{{{
fini
endif "}}}
" Option variables {{{
if !exists('g:ctrlp_mruf_max')
let s:max = 50
else
let s:max = g:ctrlp_mruf_max
unl g:ctrlp_mruf_max
endif
if !exists('g:ctrlp_mruf_include')
let s:include = ''
else
let s:include = g:ctrlp_mruf_include
unl g:ctrlp_mruf_include
endif
if !exists('g:ctrlp_mruf_exclude')
let s:exclude = ''
else
let s:exclude = g:ctrlp_mruf_exclude
unl g:ctrlp_mruf_exclude
endif
"}}}
func! ctrlp#mrufiles#list(bufnr) "{{{
if s:locked | retu | endif
" get the list
let cache_dir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru'
let cache_file = cache_dir.ctrlp#utils#lash().'cache.txt'
let mrufiles = ctrlp#utils#readfile(cache_file)
" return the list
if a:bufnr == -1 | retu mrufiles | endif
" filter it
let filename = fnamemodify(bufname(a:bufnr + 0), ':p')
if empty(filename) || !empty(&bt)
\ || ( !empty(s:include) && filename !~# s:include )
\ || ( !empty(s:exclude) && filename =~# s:exclude )
\ || ( index(mrufiles, filename) == -1 && !filereadable(filename) )
retu
endif
" remove old matched entry
cal filter(mrufiles, 'v:val !=# filename')
" insert new one
cal insert(mrufiles, filename)
" remove oldest entry
if len(mrufiles) > s:max
cal remove(mrufiles, s:max, -1)
endif
cal ctrlp#utils#writecache(mrufiles, cache_dir, cache_file)
endfunc "}}}
func! ctrlp#mrufiles#init() "{{{
let s:locked = 0
aug CtrlPMRUF
au!
au BufReadPost,BufNewFile,BufWritePost * cal ctrlp#mrufiles#list(expand('<abuf>'))
au QuickFixCmdPre *vimgrep* let s:locked = 1
au QuickFixCmdPost *vimgrep* let s:locked = 0
aug END
endfunc "}}}
" vim:fen:fdl=0:ts=2:sw=2:sts=2

72
autoload/ctrlp/utils.vim Normal file
View File

@ -0,0 +1,72 @@
" =============================================================================
" File: autoload/ctrlp/utils.vim
" Description: Utility functions
" Author: Kien Nguyen <github.com/kien>
" License: MIT
" =============================================================================
if v:version < '700' "{{{
fini
endif "}}}
" Option variables {{{
if !exists('g:ctrlp_cache_dir')
let s:cache_dir = $HOME
else
let s:cache_dir = g:ctrlp_cache_dir
endif
"}}}
" Files and Directories functions {{{
func! ctrlp#utils#cachedir()
retu exists('*mkdir') ? s:cache_dir.ctrlp#utils#lash().'.ctrlp_cache' : s:cache_dir
endfunc
func! ctrlp#utils#cachefile()
retu ctrlp#utils#cachedir().ctrlp#utils#lash().substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').'.txt'
endfunc
func! ctrlp#utils#readfile(file)
if filereadable(a:file)
let data = readfile(a:file)
if empty(data) || type(data) != 3
unl data
let data = []
endif
retu data
else
retu []
endif
endfunc
func! ctrlp#utils#mkdir(dir)
if exists('*mkdir') && !isdirectory(a:dir)
sil! cal mkdir(a:dir)
endif
endfunc
func! ctrlp#utils#writecache(lines,...)
let cache_dir = ctrlp#utils#cachedir()
let cache_file = exists('a:2') ? a:2 : ctrlp#utils#cachefile()
cal ctrlp#utils#mkdir(cache_dir)
if exists('a:1')
let cache_dir = a:1
cal ctrlp#utils#mkdir(cache_dir)
endif
" write cache
if isdirectory(cache_dir)
sil! cal writefile(a:lines, cache_file)
if !exists('a:1') || !exists('a:2')
let g:ctrlp_newcache = 0
endif
endif
endfunc
"}}}
" Generic functions {{{
func! ctrlp#utils#lash()
retu &ssl || !exists('+ssl') ? '/' : '\'
endfunc
"}}}
" vim:fen:fdl=0:ts=2:sw=2:sts=2

View File

@ -1,4 +1,4 @@
*ctrlp.txt* Full path fuzzy file and buffer finder for Vim. *ctrlp.txt* Full path fuzzy files, buffers and mru files finder for Vim.
*CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'* *CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'*
=============================================================================== ===============================================================================
# # # #
@ -23,9 +23,9 @@ CONTENTS *ctrlp-contents*
=============================================================================== ===============================================================================
1. Intro *ctrlp-intro* 1. Intro *ctrlp-intro*
Full path fuzzy file and buffer finder with an intuitive interface. Written in Full path fuzzy files, buffers and mru files finder with an intuitive
pure Vimscript for MacVim and Vim 7.0+. Has full support for Vims |regexp| as interface. Written in pure Vimscript for MacVim and Vim version 7.0+. Has full
search pattern, and more. support for Vims |regexp| as search pattern, and more.
See also |ctrlp-input-formats| and |ctrlp-fullregexp|. See also |ctrlp-input-formats| and |ctrlp-fullregexp|.
@ -93,7 +93,7 @@ to your |.vimrc|; the parameter is the same (1, 2 and 0): >
< <
*'g:ctrlp_root_markers'* *'g:ctrlp_root_markers'*
Use this to set your own root markers for the SetWorkingPath() function, in Use this to set your own root markers for the |SetWorkingPath()| function, in
addition to the default ones: > addition to the default ones: >
let g:ctrlp_root_markers = [''] let g:ctrlp_root_markers = ['']
< <
@ -141,7 +141,8 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'ToggleFocus()': ['<tab>'], \ 'ToggleFocus()': ['<tab>'],
\ 'ToggleRegex()': ['<c-r>'], \ 'ToggleRegex()': ['<c-r>'],
\ 'ToggleByFname()': ['<c-d>'], \ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType()': ['<c-f>'], \ 'ToggleType(1)': ['<c-f>', '<c-up'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'PrtCurStart()': ['<c-a>'], \ 'PrtCurStart()': ['<c-a>'],
\ 'PrtCurEnd()': ['<c-e>'], \ 'PrtCurEnd()': ['<c-e>'],
\ 'PrtCurLeft()': ['<c-h>', '<left>'], \ 'PrtCurLeft()': ['<c-h>', '<left>'],
@ -150,15 +151,48 @@ only need to keep the lines that youve changed the values (inside []): >
\ } \ }
< <
*'g:ctrlp_mru_files'*
Set this to 0 to completely disable the Most Recently Used files feature: >
let g:ctrlp_mru_files = 1
<
*'g:ctrlp_mruf_max'*
Specify the number of recently opened files you want |CtrlP| to remember: >
let g:ctrlp_mruf_max = 50
<
*'g:ctrlp_mruf_exclude'*
Files you dont want |CtrlP| to remember; use |regexp| to specify the patterns:
>
let g:ctrlp_mruf_exclude = ''
<
Examples: >
let g:ctrlp_mruf_exclude = '/tmp/.*\|/temp/.*' " MacOSX/Linux
let g:ctrlp_mruf_exclude = '^C:\\dev\\tmp\\.*' " Windows
<
*'g:ctrlp_mruf_include'*
And if you want |CtrlP| to only remember some files, specify them here: >
let g:ctrlp_mruf_include = ''
<
Example: >
let g:ctrlp_mruf_exclude = '\.py$\|\.rb$'
<
=============================================================================== ===============================================================================
3. Commands *ctrlp-commands* 3. Commands *ctrlp-commands*
*:CtrlP* *:CtrlP*
:CtrlP :CtrlP
Open the |CtrlP| prompt in find file mode. Open the |CtrlP| prompt in find files mode.
*:CtrlPBuffer* *:CtrlPBuffer*
:CtrlPBuffer :CtrlPBuffer
Open the |CtrlP| prompt in find buffer mode. Open the |CtrlP| prompt in find buffers mode.
*:CtrlPMRUFiles*
:CtrlPMRUFiles
Open the |CtrlP| prompt in find Most-Recently-Used files mode.
*:ClearCtrlPCache* *:ClearCtrlPCache*
:ClearCtrlPCache :ClearCtrlPCache
@ -188,8 +222,16 @@ Once inside the prompt:
Toggle between full path search and filename only search. Toggle between full path search and filename only search.
(note: in filename mode, the prompts base is '>d>' instead of '>>>') (note: in filename mode, the prompts base is '>d>' instead of '>>>')
<c-f> <c-f>, 'forward'
Toggle between searching files and searching buffers. <c-up>
Toggle between searching files and searching buffers. Or switch to the
'next' search type in the sequence; currently files, buffers and most
recently used files (MRU Files) are available.
<c-b>, 'backward'
<c-down>
Toggle between searching files and searching buffers. Or switch to the
'previous' search type in the sequence.
<tab> <tab>
Toggle the focus between the match window and the prompt. Toggle the focus between the match window and the prompt.
@ -278,5 +320,18 @@ aforementioned plugin.
Git repository: https://github.com/kien/ctrlp.vim Git repository: https://github.com/kien/ctrlp.vim
Mercurial repository: https://bitbucket.org/kien/ctrlp.vim Mercurial repository: https://bitbucket.org/kien/ctrlp.vim
===============================================================================
CHANGELOG
*ctrlp-update-1*
Update #1~
+ New mapping: <c-b>.
+ Extended the behavior of <c-f>.
+ New options: |g:ctrlp_mru_files|,
|g:ctrlp_mruf_max|,
|g:ctrlp_mruf_exclude|,
|g:ctrlp_mruf_include|
+ New command: |:CtrlPMRUFiles|
=============================================================================== ===============================================================================
vim:nofen:et:ts=2:sw=2:sts=2 vim:nofen:et:ts=2:sw=2:sts=2

View File

@ -10,13 +10,15 @@ if ( exists('g:loaded_ctrlp') && g:loaded_ctrlp ) || v:version < '700' || &cp
endif endif
let g:loaded_ctrlp = 1 let g:loaded_ctrlp = 1
if !exists('g:ctrlp_map') if !exists('g:ctrlp_map') | let g:ctrlp_map = '<c-p>' | endif
let g:ctrlp_map = '<c-p>' if !exists('g:ctrlp_mru_files') | let g:ctrlp_mru_files = 1 | endif
endif
com! CtrlP cal ctrlp#init(0) com! CtrlP cal ctrlp#init(0)
com! CtrlPBuffer cal ctrlp#init(1) com! CtrlPBuffer cal ctrlp#init(1)
com! CtrlPMRUFiles cal ctrlp#init(2)
com! ClearCtrlPCache cal ctrlp#clearcache() com! ClearCtrlPCache cal ctrlp#clearcache()
com! ClearAllCtrlPCaches cal ctrlp#clearallcaches() com! ClearAllCtrlPCaches cal ctrlp#clearallcaches()
exe 'nn <silent>' g:ctrlp_map ':<c-u>CtrlP<cr>' exe 'nn <silent>' g:ctrlp_map ':<c-u>CtrlP<cr>'
if g:ctrlp_mru_files | cal ctrlp#mrufiles#init() | endif

View File

@ -1,14 +1,15 @@
# ctrlp.vim # ctrlp.vim
Full path fuzzy file and buffer finder for Vim. Full path fuzzy files, buffers and MRU files finder for Vim.
* Written in pure Vimscript for MacVim and Vim 7.0+. * Written in pure Vimscript for MacVim and Vim 7.0+.
* Has full support for Vims regexp as search pattern, and more. * Has full support for Vims regexp as search pattern, and more.
* Also: find files in most recently opened files (i.e. MRU files).
![ctrlp][1] ![ctrlp][1]
## Basic Usage ## Basic Usage
* Press `<c-p>` or run `:CtrlP` to invoke CtrlP. * Press `<c-p>` or run `:CtrlP` to invoke CtrlP.
* Press `<c-f>` while CtrlP is open to toggle between find buffer mode and find file mode. * Press `<c-f>` while CtrlP is open to toggle between find files, find buffers, and find MRU files modes.
* Ever remember only a files name but not where it is? Press `<c-d>` while CtrlP is open to switch to filename only search. * Ever remember only a files name but not where it is? Press `<c-d>` while CtrlP is open to switch to filename only search.
* Use `*` `?` `^` `+` or `|` in the prompt to submit the string as a Vims regexp pattern. * Use `*` `?` `^` `+` or `|` in the prompt to submit the string as a Vims regexp pattern.
* Or press `<c-r>` while CtrlP is open to switch to full regexp search mode. * Or press `<c-r>` while CtrlP is open to switch to full regexp search mode.
@ -25,8 +26,7 @@ _Screenshot: filename only mode with the match window focused._
let g:ctrlp_map = '<c-p>' let g:ctrlp_map = '<c-p>'
``` ```
* When starting up CtrlP, it automatically sets the working directory according * When CtrlP is invoke, it automatically sets the working directory according to this variable:
to this variable:
```vim ```vim
let g:ctrlp_working_path_mode = 1 let g:ctrlp_working_path_mode = 1
@ -34,7 +34,7 @@ to this variable:
0 - dont manage working directory. 0 - dont manage working directory.
1 - the parent directory of the current file. 1 - the parent directory of the current file.
2 - the nearest ancestor that contains one of these directories or files: 2 - the nearest ancestor that contains one of these directories or files:
.git/ .git/
.hg/ .hg/
@ -51,6 +51,12 @@ The parameter is the same (0, 1 or 2):
au BufEnter * cal ctrlp#SetWorkingPath(2) au BufEnter * cal ctrlp#SetWorkingPath(2)
``` ```
* Enable/Disable Most Recently Used files monitoring and its functionalities:
```vim
let g:ctrlp_mru_files = 1
```
_Check [the docs][3] for more mappings, commands and options._ _Check [the docs][3] for more mappings, commands and options._
[1]: http://i.imgur.com/lQScr.png [1]: http://i.imgur.com/lQScr.png