diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index e023eff0..740f2976 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -255,11 +255,7 @@ endfunc func! s:BufOpen(...) "{{{ if exists('a:2') " Closing - try - bun! - catch - winc c - endtry + try | bun! | catch | clo! | endtry exe s:currwin.'winc w' " Restore the changed global options let &magic = s:CtrlP_magic @@ -427,7 +423,7 @@ func! s:CreateNewFile() "{{{ let arr = split(str, '[\/]') cal map(arr, 'escape(v:val, "%#")') let fname = remove(arr, -1) - winc c + clo! if s:newfop == 1 " In new tab tabnew let cmd = 'e' @@ -490,34 +486,36 @@ func! s:OpenMulti() if !has('autocmd') | cal s:BufOpen('ControlP', 'del') | endif exe s:currwin.'winc w' " Try not to open in new tab - let bufs = [] - for winnr in range(1, winnr('$')) - cal add(bufs, winbufnr(winnr)) - endfor - let ntab = 1 - " Check if the other window only has a blank buffer - if len(bufs) == 1 - for each in bufs - if getbufvar(each, '&bl') && empty(bufname(each)) - \ && empty(getbufvar(each, '&bt')) && empty(getbufvar(each, '&ft')) - \ && getbufvar(each, '&ma') && bufname(each) != 'ControlP' - " If it does, don't open new tab - let ntab = 0 + let ntab = 0 + let norbufs = s:normbuf() + if empty(norbufs) + let ntab = 1 + else + for each in norbufs + let bufnr = winbufnr(each) + if !empty(bufname(bufnr)) && !empty(getbufvar(bufnr, '&ft')) + \ && bufname(bufnr) != 'ControlP' + let ntab = 1 endif endfor + if !ntab + let wnr = min(norbufs) + endif endif if ntab | tabnew | endif let ic = 1 + let wnr = exists('wnr') ? wnr : 1 + exe wnr.'winc w' for key in keys(marked) let filpath = marked[key] - sil! exe 'bo vne' filpath + let cmd = ic == 1 ? 'e ' : 'vne ' + sil! exe cmd.filpath if s:opmul > 1 && s:opmul < ic - winc c + clo! else let ic += 1 endif endfor - 1winc w | winc c ec endfunc "}}} @@ -844,12 +842,20 @@ func! s:AcceptSelection(mode,...) "{{{ let md = a:mode let prt = g:CtrlP_prompt let str = prt[0] . prt[1] . prt[2] - " Walk backward the dir tree - if md == 'e' && !s:itemtype && str == '..' - cal s:parentdir(getcwd()) - cal s:SetLines(s:itemtype) - cal s:PrtClear() - retu + if md == 'e' && !s:itemtype + " Walk backward the dir tree + if str == '..' + cal s:parentdir(getcwd()) + cal s:SetLines(s:itemtype) + cal s:PrtClear() + retu + elseif str == '?' + " Use ? for help + exe s:currwin.'winc w' + let hlpwin = &columns > 159 ? '| vert res 80' : '' + exe 'bo vert h ctrlp-mappings' hlpwin '| norm! 0' + retu + endif endif " Get the full path let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$') @@ -859,9 +865,10 @@ func! s:AcceptSelection(mode,...) "{{{ if exists('a:1') && a:1 | retu filpath | endif " Manually remove the prompt and match window if !has('autocmd') | cal s:BufOpen('ControlP', 'del') | endif - let bufnum = bufnr(filpath) + let bufnum = bufnr(filpath) let bufwinnr = bufwinnr(bufnum) - let norbuf = s:normbuf() + let norbufs = s:normbuf() + let norbuf = empty(norbufs) ? 0 : norbufs[0] exe s:currwin.'winc w' " Check if the file's already opened in a tab for nr in range(1, tabpagenr('$')) @@ -949,6 +956,13 @@ func! s:compword(s1, s2) retu wrd1 == wrd2 ? 0 : wrd1 > wrd2 ? 1 : -1 endfunc +func! s:comptime(s1, s2) + " By last modified time + let time1 = getftime(a:s1) + let time2 = getftime(a:s2) + retu time1 == time2 ? 0 : time1 < time2 ? 1 : -1 +endfunc + func! s:matchlens(str, pat, ...) if empty(a:pat) || index(['^','$'], a:pat) >= 0 retu {} @@ -986,7 +1000,11 @@ func! s:wordonly(lens) endfunc func! s:mixedsort(s1, s2) - retu 3 * s:compmatlen(a:s1, a:s2) + 2 * s:complen(a:s1, a:s2) + s:compword(a:s1, a:s2) + let cmatlen = s:compmatlen(a:s1, a:s2) + let ctime = s:comptime(a:s1, a:s2) + let clen = s:complen(a:s1, a:s2) + let cword = s:compword(a:s1, a:s2) + retu 3 * cmatlen + 3 * ctime + 2 * clen + cword endfunc "}}} @@ -1173,15 +1191,15 @@ endfunc " Buffers {{{ func! s:normbuf() - if &l:bl && empty(&l:bt) && &l:ma | retu winnr() | endif + let bufs = [] for each in range(1, winnr('$')) let bufnr = winbufnr(each) if getbufvar(bufnr, '&bl') && empty(getbufvar(bufnr, '&bt')) \ && getbufvar(bufnr, '&ma') - retu each + cal add(bufs, each) endif endfor - retu 0 + retu bufs endfunc func! s:setupblank() diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index 5a489748..79e5b8b8 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -221,6 +221,11 @@ Use %s in place of the target directory: > Examples: > let g:ctrlp_user_command = 'find %s -type f' " MacOSX/Linux let g:ctrlp_user_command = 'dir %s /-n /b /s /a-d' " Windows + + " Use version control commands. Remember to set |g:ctrlp_working_path_mode| + " to 2 and |g:ctrlp_root_markers| to ['.git/'] or ['.hg/'] + let g:ctrlp_user_command = 'cd %s && git ls-files' + let g:ctrlp_user_command = 'hg --cwd %s locate -I .' < You can also use 'grep', 'findstr' or something else to filter the results. Examples: > @@ -441,6 +446,8 @@ e) Type the name of a non-existed file and press to create it. e.g. 'parentdir/file.txt' will create a directory named 'parentdir' as well as 'file.txt'. Use '\' in place of '/' on Windows (if |'ssl'| is not set). +f) Submit ? to open this help file. + =============================================================================== 6. Credits *ctrlp-credits* diff --git a/readme.md b/readme.md index e134d11c..4ee1443e 100644 --- a/readme.md +++ b/readme.md @@ -21,6 +21,7 @@ Once CtrlP is open: e.g. `abc:45` will open the file matched the pattern and jump to line 45. * Submit two dots `..` as the input string to go backward the directory tree by 1 level. * Use `` to create a new file and its parent dirs. +* Use to mark multiple files and to open them. ## Basic Options * Change the mapping to invoke CtrlP: