diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 4fe1686..d5fde3a 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -8,10 +8,10 @@ let s:save_cpo = &cpo "{{{ set cpo&vim "}}} -if v:version < '702' "{{{ - echoh Error - ec 'CtrlP requires Vim 7.2+' - echoh None +if v:version < '700' "{{{ + func! ctrlp#init(...) + echoh Error | ec 'CtrlP requires Vim 7.0+' | echoh None + endfunc fini endif "}}} @@ -104,10 +104,7 @@ endif " Caching {{{ func! s:GetDataFile(file) - if filereadable(a:file) - let lines = readfile(a:file) - retu lines - endif + if filereadable(a:file) | retu readfile(a:file) | endif endfunc func! s:CacheDir() @@ -140,18 +137,12 @@ func! ctrlp#clearallcaches() if isdirectory(cache_dir) && match(cache_dir, '.ctrlp_cache') >= 0 let cache_files = split(globpath(cache_dir, '*.txt'), '\n') try - for each in cache_files - cal delete(each) - endfor + for each in cache_files | cal delete(each) | endfor catch - echoh Error - ec 'Can''t delete cache files' - echoh None + echoh Error | ec 'Can''t delete cache files' | echoh None endtry else - echoh Error - ec 'Caching directory not found. Nothing to delete.' - echoh None + echoh Error | ec 'Caching directory not found. Nothing to delete.' | echoh None endif cal ctrlp#clearcache() endfunc @@ -173,15 +164,11 @@ func! s:ListAllFiles(path) "{{{ else let allfiles = s:GetDataFile(cache_file) endif - if len(allfiles) <= 3000 - cal sort(allfiles, 's:compare') - endif + if len(allfiles) <= 3000 | cal sort(allfiles, 's:compare') | endif " write cache if ( g:ctrlp_newcache || !filereadable(cache_file) ) && s:caching \ || 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) endif retu allfiles @@ -224,11 +211,7 @@ func! s:SplitPattern(str,...) "{{{ let array = split(str, '\zs') endif " Build the new pattern - if !empty(array) - let nitem = array[0] - else - let nitem = '' - endif + let nitem = !empty(array) ? array[0] : '' let newpats = [nitem] if len(array) > 1 for i in range(1, len(array) - 1) @@ -247,9 +230,7 @@ func! s:GetMatchedItems(items, pats, limit) "{{{ let limit = a:limit " if pattern contains line number if match(pats[-1], ':\d*$') >= 0 - if exists('s:line') - unl s:line - endif + if exists('s:line') | unl s:line | endif let s:line = substitute(pats[-1], '.*\ze:\d*$', '', 'g') cal remove(pats, -1) endif @@ -269,18 +250,12 @@ func! s:GetMatchedItems(items, pats, limit) "{{{ " loop through the items for item in items if s:byfname - if s:matchsubstr(item, each) >= 0 - cal add(newitems, item) - endif + if s:matchsubstr(item, each) >= 0 | cal add(newitems, item) | endif else - if match(item, each) >= 0 - cal add(newitems, item) - endif + if match(item, each) >= 0 | cal add(newitems, item) | endif endif " stop if reached the limit - if a:limit > 0 && len(newitems) == limit - break - endif + if a:limit > 0 && len(newitems) == limit | break | endif endfor endif endfor @@ -412,9 +387,8 @@ endfunc "}}} func! s:UpdateMatches(pat) "{{{ " Delete the buffer's content sil! %d _ - let limit = s:mxheight let newpat = s:SplitPattern(a:pat) - let lines = s:GetMatchedItems(s:lines, newpat, limit) + let lines = s:GetMatchedItems(s:lines, newpat, s:mxheight) cal s:Renderer(lines) cal s:Highlight(newpat) endfunc "}}} @@ -598,7 +572,7 @@ func! s:ToggleFocus() endfunc "}}} -"Mightdo: Cycle through matches. /high +"Mightdo: Cycle through matches. /medium func! s:SelectJump(char,...) "{{{ let lines = map(b:matched, 'substitute(v:val, "^> ", "", "g")') if exists('a:1') @@ -679,8 +653,7 @@ endfunc func! s:AcceptSelection(mode) "{{{ let md = a:mode - let line = getline('.') - let matchstr = matchstr(line, '^> \zs.\+\ze\t*$') + let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$') let filepath = s:itemtype ? matchstr : getcwd().s:lash().matchstr let filename = split(filepath, s:lash())[-1] " Remove the prompt and match window diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index c47f176..cf23653 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -171,19 +171,22 @@ only need to keep the lines that you’ve changed the values (inside []): > Once inside the prompt: *'ctrlp-fullregexp'* - Toggle between the smart |regexp|/string mode (section 5.c) and full + Toggle between the smart |regexp|/string mode (section 5.b) and full |regexp| mode. (note: in full |regexp| mode, the prompt’s base is 'r>>' instead of '>>>') See also |input-formats|. - Toggle between full path search and file name only search. - (note: in file name mode, the prompt’s base is '>d>' instead of '>>>') + Toggle between full path search and filename only search. + (note: in filename mode, the prompt’s base is '>d>' instead of '>>>') Toggle between searching files and searching buffers. + + Toggle the focus between the match window and the prompt. + , , @@ -227,9 +230,6 @@ Once inside the prompt: Open selected file in a 'horizontal' split - - Toggle the focus between the match window and the prompt. - , , @@ -245,16 +245,16 @@ Formats for inputting in the prompt: a) Simple string. e.g. 'abc' is understood internally as 'a.*b.*c' -b) Strings end with a colon ':' followed by an arbitrary number will be read - as a line number to jump to after opening the file. - e.g. 'abc:45' will open the selected file and jump to line 45. - -c) Vim |regexp|. If the input string contains '*', '^', '$', '+' or '$', it’ll +b) Vim |regexp|. If the input string contains '*', '^', '$', '+' or '$', it’ll be treated as a Vim’s |regexp| |pattern| without any modification. e.g. 'abc\d*efg' will be read as 'abc\d*efg'. See also |ctrlp-fullregexp|. +c) Strings end with a colon ':' followed by an arbitrary number will be read + as a line number to jump to after opening the file. + e.g. 'abc:45' will open the selected file and jump to line 45. + =============================================================================== 6. Credits *ctrlp-credits* diff --git a/plugin/ctrlp.vim b/plugin/ctrlp.vim index d4d51f2..0093849 100644 --- a/plugin/ctrlp.vim +++ b/plugin/ctrlp.vim @@ -5,7 +5,8 @@ " License: MIT " ============================================================ -if exists('g:loaded_ctrlp') && g:loaded_ctrlp +if ( exists('g:loaded_ctrlp') && g:loaded_ctrlp ) + \ || v:version < '700' fini endif let g:loaded_ctrlp = 1 diff --git a/readme.md b/readme.md index daf09f7..26488a7 100644 --- a/readme.md +++ b/readme.md @@ -1,49 +1,53 @@ -Full path fuzzy file finder with an intuitive interface. Written in pure -Vimscript. Has full support for Vim’s regexp as search pattern, and more. +## About +* Full path fuzzy file finder with an intuitive interface. +* Has full support for Vim’s regexp as search pattern, and more. +* Written in pure Vimscript for MacVim and Vim 7.0+. ![ctrlp][1] -![ctrlp file name mode, match window focused][2] ## Basic Usage - * Press `` or run `:CtrlP` to invoke CtrlP. +* Ever remember only a file’s name but not where it is? Press `` while +CtrlP is open to switch to filename only search. Press `` again to switch +back to full path search. * Use `*` `?` `^` `+` or `|` in the prompt to submit the string as a Vim’s regexp pattern. Or press `` to switch to full regexp mode. -* Ever remember only the file name but not where it is? Press `` while in -the prompt to switch to file name only search. Press `` again to switch -back to full path search. * End the input string with a colon `:` followed by a number to jump to that -line in the selected file. - e.g. `abc:45` to open the file matched the pattern `abc` and jump to - line 45. -* Press `` to switch to find buffer mode. Or run `:CtrlPBuffer`. +line in the selected file. +e.g. `abc:45` to open the file matched the pattern and jump to line 45. +* Press `` to toggle find buffer mode/find file mode while CtrlP is open. +Run `:CtrlPBuffer` to start CtrlP in find buffer mode. + +_Screenshot: filename only mode with the match window focused._ +![ctrlp filename mode, match window focused][2] ## Basic Options - -* Change the mapping to invoke CtrlP with: +* Change the mapping to invoke CtrlP: ```vim let g:ctrlp_map = '' ``` -* When starting up the prompt, automatically set the working directory to: - 1 - the parent directory of the current file. - 2 - the nearest ancestor that contains one of these directories/files: - .git/ - .hg/ - .bzr/ - _darcs/ - root.dir - .vimprojects - 0 - don’t manage working directory. +* When starting up CtrlP, it automatically sets the working directory to: ```vim let g:ctrlp_working_path_mode = 1 ``` + 1 - the parent directory of the current file. + 2 - the nearest ancestor that contains one of these directories or files: + ``` + .git/ + .hg/ + .bzr/ + _darcs/ + root.dir + .vimprojects + ``` + 0 - don’t manage working directory. * You can also use the set-working-directory functionality outside of CtrlP by -adding the following line to your vimrc; the parameter is the same (1, 2 and 0): +adding the following line to your vimrc; the parameter is the same (1, 2 or 0): ```vim au BufEnter * cal ctrlp#SetWorkingPath(2) ``` -Check the docs for more mappings and options. +Check the docs for more mappings, commands and options. [1]: http://designslicer.com/vim/images/ctrlp1.png [2]: http://designslicer.com/vim/images/ctrlp2.png