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 "{{{
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

View File

@ -171,19 +171,22 @@ only need to keep the lines that youve changed the values (inside []): >
Once inside the prompt:
<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.
(note: in full |regexp| mode, the prompts base is 'r>>' instead of '>>>')
See also |input-formats|.
<c-d>
Toggle between full path search and file name only search.
(note: in file name mode, the prompts base is '>d>' instead of '>>>')
Toggle between full path search and filename only search.
(note: in filename mode, the prompts base is '>d>' instead of '>>>')
<c-f>
Toggle between searching files and searching buffers.
<tab>
Toggle the focus between the match window and the prompt.
<c-n>,
<c-j>,
<down>
@ -227,9 +230,6 @@ Once inside the prompt:
<c-s>
Open selected file in a 'horizontal' split
<tab>
Toggle the focus between the match window and the prompt.
<esc>,
<c-c>,
<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'
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 '$', itll
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|.
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*

View File

@ -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

View File

@ -1,49 +1,53 @@
Full path fuzzy file finder with an intuitive interface. Written in pure
Vimscript. Has full support for Vims regexp as search pattern, and more.
## About
* 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 file name mode, match window focused][2]
## Basic Usage
* 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
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
line in the selected file.
e.g. `abc:45` to open the file matched the pattern `abc` and jump to
line 45.
* Press `<c-f>` to switch to find buffer mode. Or run `:CtrlPBuffer`.
e.g. `abc:45` to open the file matched the pattern and jump to line 45.
* Press `<c-f>` 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 = '<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.
2 - the nearest ancestor that contains one of these directories/files:
2 - the nearest ancestor that contains one of these directories or files:
```
.git/
.hg/
.bzr/
_darcs/
root.dir
.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
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