some small changes

This commit is contained in:
Kien N 2011-09-05 21:59:18 +07:00
parent bb8a2e19e4
commit 4ca1ab9e37
4 changed files with 60 additions and 82 deletions

View File

@ -8,10 +8,10 @@
let s:save_cpo = &cpo "{{{ let s:save_cpo = &cpo "{{{
set cpo&vim "}}} set cpo&vim "}}}
if v:version < '702' "{{{ if v:version < '700' "{{{
echoh Error func! ctrlp#init(...)
ec 'CtrlP requires Vim 7.2+' echoh Error | ec 'CtrlP requires Vim 7.0+' | echoh None
echoh None endfunc
fini fini
endif "}}} endif "}}}
@ -104,10 +104,7 @@ endif
" Caching {{{ " Caching {{{
func! s:GetDataFile(file) func! s:GetDataFile(file)
if filereadable(a:file) if filereadable(a:file) | retu readfile(a:file) | endif
let lines = readfile(a:file)
retu lines
endif
endfunc endfunc
func! s:CacheDir() func! s:CacheDir()
@ -140,18 +137,12 @@ func! ctrlp#clearallcaches()
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')
try try
for each in cache_files for each in cache_files | cal delete(each) | endfor
cal delete(each)
endfor
catch catch
echoh Error echoh Error | ec 'Can''t delete cache files' | echoh None
ec 'Can''t delete cache files'
echoh None
endtry endtry
else else
echoh Error echoh Error | ec 'Caching directory not found. Nothing to delete.' | echoh None
ec 'Caching directory not found. Nothing to delete.'
echoh None
endif endif
cal ctrlp#clearcache() cal ctrlp#clearcache()
endfunc endfunc
@ -173,15 +164,11 @@ func! s:ListAllFiles(path) "{{{
else else
let allfiles = s:GetDataFile(cache_file) let allfiles = s:GetDataFile(cache_file)
endif endif
if len(allfiles) <= 3000 if len(allfiles) <= 3000 | cal sort(allfiles, 's:compare') | endif
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 if len(allfiles) > 4000 | let s:caching = 1 | endif
let s:caching = 1
endif
cal s:WriteCache(allfiles) cal s:WriteCache(allfiles)
endif endif
retu allfiles retu allfiles
@ -224,11 +211,7 @@ func! s:SplitPattern(str,...) "{{{
let array = split(str, '\zs') let array = split(str, '\zs')
endif endif
" Build the new pattern " Build the new pattern
if !empty(array) let nitem = !empty(array) ? array[0] : ''
let nitem = array[0]
else
let nitem = ''
endif
let newpats = [nitem] let newpats = [nitem]
if len(array) > 1 if len(array) > 1
for i in range(1, 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 let limit = a:limit
" if pattern contains line number " if pattern contains line number
if match(pats[-1], ':\d*$') >= 0 if match(pats[-1], ':\d*$') >= 0
if exists('s:line') if exists('s:line') | unl s:line | endif
unl s:line
endif
let s:line = substitute(pats[-1], '.*\ze:\d*$', '', 'g') let s:line = substitute(pats[-1], '.*\ze:\d*$', '', 'g')
cal remove(pats, -1) cal remove(pats, -1)
endif endif
@ -269,18 +250,12 @@ func! s:GetMatchedItems(items, pats, limit) "{{{
" loop through the items " loop through the items
for item in items for item in items
if s:byfname if s:byfname
if s:matchsubstr(item, each) >= 0 if s:matchsubstr(item, each) >= 0 | cal add(newitems, item) | endif
cal add(newitems, item)
endif
else else
if match(item, each) >= 0 if match(item, each) >= 0 | cal add(newitems, item) | endif
cal add(newitems, item)
endif
endif endif
" stop if reached the limit " stop if reached the limit
if a:limit > 0 && len(newitems) == limit if a:limit > 0 && len(newitems) == limit | break | endif
break
endif
endfor endfor
endif endif
endfor endfor
@ -412,9 +387,8 @@ endfunc "}}}
func! s:UpdateMatches(pat) "{{{ func! s:UpdateMatches(pat) "{{{
" Delete the buffer's content " Delete the buffer's content
sil! %d _ sil! %d _
let limit = s:mxheight
let newpat = s:SplitPattern(a:pat) 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:Renderer(lines)
cal s:Highlight(newpat) cal s:Highlight(newpat)
endfunc "}}} endfunc "}}}
@ -598,7 +572,7 @@ func! s:ToggleFocus()
endfunc endfunc
"}}} "}}}
"Mightdo: Cycle through matches. /high "Mightdo: Cycle through matches. /medium
func! s:SelectJump(char,...) "{{{ func! s:SelectJump(char,...) "{{{
let lines = map(b:matched, 'substitute(v:val, "^> ", "", "g")') let lines = map(b:matched, 'substitute(v:val, "^> ", "", "g")')
if exists('a:1') if exists('a:1')
@ -679,8 +653,7 @@ endfunc
func! s:AcceptSelection(mode) "{{{ func! s:AcceptSelection(mode) "{{{
let md = a:mode let md = a:mode
let line = getline('.') let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$')
let matchstr = matchstr(line, '^> \zs.\+\ze\t*$')
let filepath = s:itemtype ? matchstr : getcwd().s:lash().matchstr let filepath = s:itemtype ? matchstr : getcwd().s:lash().matchstr
let filename = split(filepath, s:lash())[-1] let filename = split(filepath, s:lash())[-1]
" Remove the prompt and match window " Remove the prompt and match window

View File

@ -171,7 +171,7 @@ only need to keep the lines that youve changed the values (inside []): >
Once inside the prompt: Once inside the prompt:
<c-r> *'ctrlp-fullregexp'* <c-r> *'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. |regexp| mode.
(note: in full |regexp| mode, the prompts base is 'r>>' instead of '>>>') (note: in full |regexp| mode, the prompts base is 'r>>' instead of '>>>')
@ -184,6 +184,9 @@ Once inside the prompt:
<c-f> <c-f>
Toggle between searching files and searching buffers. Toggle between searching files and searching buffers.
<tab>
Toggle the focus between the match window and the prompt.
<c-n>, <c-n>,
<c-j>, <c-j>,
<down> <down>
@ -227,9 +230,6 @@ Once inside the prompt:
<c-s> <c-s>
Open selected file in a 'horizontal' split Open selected file in a 'horizontal' split
<tab>
Toggle the focus between the match window and the prompt.
<esc>, <esc>,
<c-c>, <c-c>,
<c-g> <c-g>
@ -245,16 +245,16 @@ Formats for inputting in the prompt:
a) Simple string. e.g. 'abc' is understood internally as 'a.*b.*c' 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 b) Vim |regexp|. If the input string contains '*', '^', '$', '+' or '$', itll
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 '$', itll
be treated as a Vims |regexp| |pattern| without any modification. be treated as a Vims |regexp| |pattern| without any modification.
e.g. 'abc\d*efg' will be read as 'abc\d*efg'. e.g. 'abc\d*efg' will be read as 'abc\d*efg'.
See also |ctrlp-fullregexp|. 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* 6. Credits *ctrlp-credits*

View File

@ -5,7 +5,8 @@
" License: MIT " License: MIT
" ============================================================ " ============================================================
if exists('g:loaded_ctrlp') && g:loaded_ctrlp if ( exists('g:loaded_ctrlp') && g:loaded_ctrlp )
\ || v:version < '700'
fini fini
endif endif
let g:loaded_ctrlp = 1 let g:loaded_ctrlp = 1

View File

@ -1,49 +1,53 @@
Full path fuzzy file finder with an intuitive interface. Written in pure ## About
Vimscript. Has full support for Vims regexp as search pattern, and more. * Full path fuzzy file finder with an intuitive interface.
* Has full support for Vims regexp as search pattern, and more.
* Written in pure Vimscript for MacVim and Vim 7.0+.
![ctrlp][1] ![ctrlp][1]
![ctrlp file name mode, match window focused][2]
## Basic Usage ## Basic Usage
* Press `<c-p>` or run `:CtrlP` to invoke CtrlP. * Press `<c-p>` or run `:CtrlP` to invoke CtrlP.
* Ever remember only a files name but not where it is? Press `<c-d>` while
CtrlP is open to switch to filename only search. Press `<c-d>` again to switch
back to full path search.
* Use `*` `?` `^` `+` or `|` in the prompt to submit the string as a Vims * Use `*` `?` `^` `+` or `|` in the prompt to submit the string as a Vims
regexp pattern. Or press `<c-r>` to switch to full regexp mode. regexp pattern. Or press `<c-r>` to switch to full regexp mode.
* Ever remember only the file name but not where it is? Press `<c-d>` while in
the prompt to switch to file name only search. Press `<c-d>` again to switch
back to full path search.
* End the input string with a colon `:` followed by a number to jump to that * End the input string with a colon `:` followed by a number to jump to that
line in the selected file. line in the selected file.
e.g. `abc:45` to open the file matched the pattern `abc` and jump to e.g. `abc:45` to open the file matched the pattern and jump to line 45.
line 45. * Press `<c-f>` to toggle find buffer mode/find file mode while CtrlP is open.
* Press `<c-f>` to switch to find buffer mode. Or run `:CtrlPBuffer`. 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 ## Basic Options
* Change the mapping to invoke CtrlP:
* Change the mapping to invoke CtrlP with:
```vim ```vim
let g:ctrlp_map = '<c-p>' let g:ctrlp_map = '<c-p>'
``` ```
* When starting up the prompt, automatically set the working directory to: * 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. 1 - the parent directory of the current file.
2 - the nearest ancestor that contains one of these directories/files: 2 - the nearest ancestor that contains one of these directories or files:
```
.git/ .git/
.hg/ .hg/
.bzr/ .bzr/
_darcs/ _darcs/
root.dir root.dir
.vimprojects .vimprojects
0 - dont manage working directory.
```vim
let g:ctrlp_working_path_mode = 1
``` ```
0 - dont manage working directory.
* You can also use the set-working-directory functionality outside of CtrlP by * 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 ```vim
au BufEnter * cal ctrlp#SetWorkingPath(2) 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 [1]: http://designslicer.com/vim/images/ctrlp1.png
[2]: http://designslicer.com/vim/images/ctrlp2.png [2]: http://designslicer.com/vim/images/ctrlp2.png