diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 57f8232..7f28267 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -3,7 +3,7 @@ " Description: Full path fuzzy file, buffer and MRU file finder for Vim. " Author: Kien Nguyen " License: MIT -" Version: 1.5.1 +" Version: 1.5.2 " ============================================================================= if v:version < '700' "{{{ @@ -14,6 +14,7 @@ endif "}}} func! s:opts() let opts = { \ 'g:ctrlp_match_window_reversed' : ['s:mwreverse', 1], + \ 'g:ctrlp_match_window_bottom' : ['s:mwbottom', 1], \ 'g:ctrlp_split_window' : ['s:splitwin', 0], \ 'g:ctrlp_working_path_mode' : ['s:pathmode', 1], \ 'g:ctrlp_root_markers' : ['s:rmarkers', []], @@ -61,9 +62,7 @@ cal s:opts() let s:lash = ctrlp#utils#lash() " Limiters -let s:compare_lim = 3000 -let s:nocache_lim = 4000 -let s:mltipats_lim = 2000 +let [s:compare_lim, s:nocache_lim, s:mltipats_lim] = [3000, 4000, 2000] "}}} " * Clear caches {{{ @@ -112,11 +111,13 @@ func! s:GlobPath(dirs, allfiles, depth) endfunc func! s:UserCommand(path, lscmd) + let path = a:path if exists('+ssl') && &ssl let ssl = &ssl let &ssl = 0 + let path = substitute(path, '/', '\', 'g') endif - let g:ctrlp_allfiles = split(system(printf(a:lscmd, shellescape(a:path))), '\n') + let g:ctrlp_allfiles = split(system(printf(a:lscmd, shellescape(path))), '\n') if exists('+ssl') && exists('ssl') let &ssl = ssl cal map(g:ctrlp_allfiles, 'substitute(v:val, "\\", "/", "g")') @@ -216,9 +217,7 @@ endfunc "}}} " * GetMatchedItems {{{ func! s:MatchIt(items, pat, limit) - let items = a:items - let pat = a:pat - let limit = a:limit + let [items, pat, limit] = [a:items, a:pat, a:limit] let newitems = [] for item in items if s:byfname @@ -233,9 +232,7 @@ func! s:MatchIt(items, pat, limit) endfunc func! s:GetMatchedItems(items, pats, limit) - let items = a:items - let pats = a:pats - let limit = a:limit + let [items, pats, limit] = [a:items, a:pats, a:limit] " If items is longer than s:mltipats_lim, use only the last pattern if len(items) >= s:mltipats_lim let pats = [pats[-1]] @@ -293,9 +290,10 @@ func! s:BufOpen(...) "{{{ cal s:recordhist(prt[0] . prt[1] . prt[2]) ec else - let s:currwin = winnr() " Open new buffer - sil! exe 'bo 1new' a:1 + let pos = s:mwbottom ? 'bo' : 'to' + sil! exe pos '1new' a:1 + let s:currwin = s:mwbottom ? winnr('#') : winnr('#') + 1 abc let s:winnr = bufwinnr('%') let s:bufnr = bufnr('%') @@ -431,7 +429,7 @@ func! s:CreateNewFile() "{{{ let arr = split(str, '[\/]') cal map(arr, 'escape(v:val, "%#")') let fname = remove(arr, -1) - clo! + exe s:currwin.'winc w' if s:newfop == 1 " In new tab tabnew let cmd = 'e' @@ -489,17 +487,15 @@ func! s:OpenMulti() retu endif let marked = deepcopy(s:marked) - let prt = g:CtrlP_prompt - let str = prt[0] . prt[1] . prt[2] if !has('autocmd') | cal s:BufOpen('ControlP', 'del') | endif exe s:currwin.'winc w' " Try not to open in new tab let ntab = 0 - let norbufs = s:normbuf() - if empty(norbufs) + let norwins = s:normbuf() + if empty(norwins) let ntab = 1 else - for each in norbufs + for each in norwins let bufnr = winbufnr(each) if !empty(bufname(bufnr)) && !empty(getbufvar(bufnr, '&ft')) \ && bufname(bufnr) != 'ControlP' @@ -507,7 +503,7 @@ func! s:OpenMulti() endif endfor if !ntab - let wnr = min(norbufs) + let wnr = min(norwins) endif endif if ntab | tabnew | endif @@ -653,7 +649,7 @@ func! s:PrtClearCache() endfunc func! s:PrtExit() - if has('autocmd') && s:currwin + if has('autocmd') exe s:currwin.'winc w' else cal s:BufOpen('ControlP', 'del') @@ -810,9 +806,7 @@ func! s:FindRoot(curr, mark, depth, ...) endif else let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '') - if parent != a:curr - cal s:FindRoot(parent, a:mark, depth, a:1) - endif + if parent != a:curr | cal s:FindRoot(parent, a:mark, depth, a:1) | endif endif endfunc @@ -836,10 +830,10 @@ func! ctrlp#SetWorkingPath(...) if s:pathmode == 1 || l:pathmode == 1 | retu | endif let markers = [ \ 'root.dir', - \ '.vimprojects', \ '.git/', - \ '_darcs/', \ '.hg/', + \ '.vimprojects', + \ '_darcs/', \ '.bzr/', \ ] if exists('s:rmarkers') && type(s:rmarkers) == 3 && !empty(s:rmarkers) @@ -857,8 +851,8 @@ func! s:AcceptSelection(mode,...) "{{{ let prt = g:CtrlP_prompt let str = prt[0] . prt[1] . prt[2] if md == 'e' && !s:itemtype - " Walk backward the dir tree if str == '..' + " Walk backward the dir tree cal s:parentdir(getcwd()) cal s:SetLines(s:itemtype) cal s:PrtClear() @@ -879,11 +873,11 @@ 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 + exe s:currwin.'winc w' let bufnum = bufnr(filpath) let bufwinnr = bufwinnr(bufnum) - let norbufs = s:normbuf() - let norbuf = empty(norbufs) ? 0 : norbufs[0] - exe s:currwin.'winc w' + let norwins = s:normbuf() + let norwin = empty(norwins) ? 0 : norwins[0] " Check if the file's already opened in a tab for nr in range(1, tabpagenr('$')) " Get a list of the buffers in the nr tab @@ -927,11 +921,11 @@ func! s:AcceptSelection(mode,...) "{{{ elseif md == 'e' || !s:splitwin " In current window let cmd = 'e' " If there's at least 1 normal buffer - if norbuf + if norwin " But not the current one if !&l:bl || !empty(&l:bt) || !&l:ma " Go to the first normal one - exe norbuf.'winc w' + exe norwin.'winc w' endif else " No normal buffers @@ -951,8 +945,7 @@ endfunc "}}} " Sorting {{{ func! s:complen(s1, s2) " By length - let len1 = strlen(a:s1) - let len2 = strlen(a:s2) + let [len1, len2] = [strlen(a:s1), strlen(a:s2)] retu len1 == len2 ? 0 : len1 > len2 ? 1 : -1 endfunc @@ -972,8 +965,7 @@ endfunc func! s:comptime(s1, s2) " By last modified time - let time1 = getftime(a:s1) - let time2 = getftime(a:s2) + let [time1, time2] = [getftime(a:s1), getftime(a:s2)] retu time1 == time2 ? 0 : time1 < time2 ? 1 : -1 endfunc @@ -1049,8 +1041,7 @@ func! s:statusline(...) endfunc func! s:progress(len) - let cnt = '%#Function# '.a:len.' %*' - let dir = ' %=%<%#LineNr# '.getcwd().' %*' + let [cnt, dir] = ['%#Function# '.a:len.' %*', ' %=%<%#LineNr# '.getcwd().' %*'] let &l:stl = cnt.dir redr endfunc @@ -1205,15 +1196,15 @@ endfunc " Buffers {{{ func! s:normbuf() - let bufs = [] + let winnrs = [] for each in range(1, winnr('$')) let bufnr = winbufnr(each) if getbufvar(bufnr, '&bl') && empty(getbufvar(bufnr, '&bt')) \ && getbufvar(bufnr, '&ma') - cal add(bufs, each) + cal add(winnrs, each) endif endfor - retu bufs + retu winnrs endfunc func! s:setupblank() @@ -1327,8 +1318,7 @@ endfunc func! ctrlp#init(type, ...) if exists('s:init') | retu | endif - let s:matches = 1 - let s:init = 1 + let [s:matches, s:init] = [1, 1] let a1 = exists('a:1') ? a:1 : '' cal ctrlp#SetWorkingPath(a1) cal s:BufOpen('ControlP') diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index 54455e9..160612a 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -1,4 +1,4 @@ -*ctrlp.txt* Full path fuzzy file, buffer and MRU file finder. v1.5.1 +*ctrlp.txt* Full path fuzzy file, buffer and MRU file finder. v1.5.2 *CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'* =============================================================================== # # @@ -55,6 +55,11 @@ Set this to 1 to set full |regexp| search as the default mode: > let g:ctrlp_regexp_search = 0 < + *'g:ctrlp_match_window_bottom'* +Set this to 0 to show the match window at the top of the screen: > + let g:ctrlp_match_window_bottom = 1 +< + *'g:ctrlp_match_window_reversed'* Reverse the sort order of the matched files in the match window. The default setting is from bottom to top: > diff --git a/plugin/ctrlp.vim b/plugin/ctrlp.vim index d6b672a..504ecd8 100644 --- a/plugin/ctrlp.vim +++ b/plugin/ctrlp.vim @@ -31,5 +31,4 @@ exe 'nn ' g:ctrlp_map ':CtrlP' if g:ctrlp_mru_files | cal ctrlp#mrufiles#init() | endif -let g:ctrlp_lines = [] -let g:ctrlp_allfiles = [] +let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []] diff --git a/readme.md b/readme.md index d0baf4d..2734c11 100644 --- a/readme.md +++ b/readme.md @@ -21,7 +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. +* Use `` to mark/unmark files and `` to open them. ## Basic Options * Change the mapping to invoke CtrlP: @@ -69,6 +69,13 @@ e.g. Just have something like this in your vimrc: set wildignore+=.git\*,.hg\*,.svn\* " for Windows ``` +* Use a custom file listing command with: + + ```vim + let g:ctrlp_user_command = 'find %s -type f' " MacOSX/Linux + let g:ctrlp_user_command = 'dir %s /-n /b /s /a-d' " Windows + ``` + _Check [the docs][2] for more mappings, commands and options._ [1]: http://i.imgur.com/3rtLt.png