diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 9b5f04a..e9cc493 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -62,6 +62,8 @@ fu! s:opts() \ 'PrtSelectMove("k")': ['', ''], \ 'PrtSelectMove("t")': [''], \ 'PrtSelectMove("b")': [''], + \ 'PrtSelectMove("u")': [''], + \ 'PrtSelectMove("d")': [''], \ 'PrtHistory(-1)': [''], \ 'PrtHistory(1)': [''], \ 'AcceptSelection("e")': ['', '', '<2-LeftMouse>'], @@ -291,7 +293,7 @@ fu! s:MatchIt(items, pat, limit, mfunc) retu newitems endf -fu! s:MatchedItems(items, pats, limit, bfn) +fu! s:MatchedItems(items, pats, 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 || ( exists('s:height') && s:height > 20 ) @@ -300,7 +302,7 @@ fu! s:MatchedItems(items, pats, limit, bfn) cal map(pats, 'substitute(v:val, "\\\~", "\\\\\\~", "g")') if !s:regexp | cal map(pats, 'escape(v:val, ".")') | en let [type, ipt, mfunc] = [s:type(1), s:ispathitem(), 'match'] - if s:byfname && ipt && a:bfn + if s:byfname && ipt let mfunc = 's:matchfname' elsei s:itemtype > 2 let types = { 'tabs': 's:matchtabs', 'tabe': 's:matchtabe' } @@ -328,7 +330,7 @@ fu! s:SplitPattern(str, ...) "{{{1 let str = s:migemo(str) en let s:savestr = str - if s:regexp || match(str, '\\\(zs\|ze\|<\|>\)\|[*|]') >= 0 + if s:regexp || match(str, '\\\(<\|>\)\|[*|]') >= 0 let array = [s:regexfilter(str)] el let array = split(str, '\zs') @@ -354,7 +356,7 @@ fu! s:SplitPattern(str, ...) "{{{1 retu newpats endf " * BuildPrompt() {{{1 -fu! s:Render(lines, pat, bfn) +fu! s:Render(lines, pat) let lines = a:lines " Setup the match window let s:height = min([len(lines), s:mxheight]) @@ -388,7 +390,7 @@ fu! s:Render(lines, pat, bfn) en " Highlighting if s:dohighlight() - cal s:highlight(a:pat, s:mathi[1] == '' ? 'Identifier' : s:mathi[1], a:bfn) + cal s:highlight(a:pat, s:mathi[1] == '' ? 'Identifier' : s:mathi[1]) en endf @@ -404,13 +406,9 @@ fu! s:Update(str) if notail == oldstr && !empty(notail) && !exists('s:force') retu en - let bfn = s:byfname && notail != '' && match(notail, '\v/|\\:@!') < 0 - if s:byfname && s:regexp && match(notail, '\\:\@!') >= 0 - let bfn = s:byfname - en let lines = exists('g:ctrlp_nolimit') && empty(notail) ? copy(g:ctrlp_lines) - \ : s:MatchedItems(g:ctrlp_lines, copy(pats), s:mxheight, bfn) - cal s:Render(lines, pats[-1], bfn) + \ : s:MatchedItems(g:ctrlp_lines, copy(pats), s:mxheight) + cal s:Render(lines, pats[-1]) endf fu! s:ForceUpdate() @@ -541,8 +539,9 @@ fu! s:PrtCurEnd() endf fu! s:PrtSelectMove(dir) - let torb = { 't': 'gg', 'b': 'G' } - exe 'keepj norm!' ( a:dir =~ '^[tb]$' ? torb[a:dir] : a:dir ) + let wht = winheight(0) + let dirs = {'t': 'gg','b': 'G','j': 'j','k': 'k','u': wht.'k','d': wht.'j'} + exe 'keepj norm!' dirs[a:dir] if !exists('g:ctrlp_nolimit') | let s:cline = line('.') | en if line('$') > winheight(0) | cal s:BuildPrompt(0, s:Focus()) | en endf @@ -906,8 +905,9 @@ endf fu! s:comparent(s1, s2) " By same parent dir - if match(s:crfpath, escape(getcwd(), '.^$*\')) >= 0 - let [as1, as2] = [fnamemodify(a:s1, ':p'), fnamemodify(a:s2, ':p')] + let cwd = getcwd() + if match(s:crfpath, escape(cwd, '.^$*\')) >= 0 + let [as1, as2] = [cwd.s:lash().a:s1, cwd.s:lash().a:s2] let [loc1, loc2] = [s:getparent(as1), s:getparent(as2)] if loc1 == s:crfpath && loc2 != s:crfpath | retu -1 | en if loc2 == s:crfpath && loc1 != s:crfpath | retu 1 | en @@ -1131,7 +1131,7 @@ fu! s:syntax() en endf -fu! s:highlight(pat, grp, bfn) +fu! s:highlight(pat, grp) cal clearmatches() if !empty(a:pat) && s:ispathitem() let pat = substitute(a:pat, '\~', '\\~', 'g') @@ -1139,7 +1139,7 @@ fu! s:highlight(pat, grp, bfn) \ ? substitute(pat, '\\\@ \\zs', 'g') \ : escape(pat, '.') " Match only filename - if s:byfname && a:bfn + if s:byfname let pat = substitute(pat, '\[\^\(.\{-}\)\]\\{-}', '[^\\/\1]\\{-}', 'g') let pat = substitute(pat, '$', '\\ze[^\\/]*$', 'g') en diff --git a/autoload/ctrlp/rtscript.vim b/autoload/ctrlp/rtscript.vim index a8cec52..15fca51 100644 --- a/autoload/ctrlp/rtscript.vim +++ b/autoload/ctrlp/rtscript.vim @@ -12,7 +12,7 @@ let [g:loaded_ctrlp_rtscript, g:ctrlp_newrts] = [1, 0] let s:rtscript_var = { \ 'init': 'ctrlp#rtscript#init()', - \ 'accept': 'ctrlp#rtscript#accept', + \ 'accept': 'ctrlp#acceptfile', \ 'lname': 'runtime scripts', \ 'sname': 'rts', \ 'type': 'path', @@ -24,18 +24,23 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) " Public {{{1 fu! ctrlp#rtscript#init() - if g:ctrlp_newrts || !exists('g:ctrlp_rtscache') + if g:ctrlp_newrts + \ || !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[0] == &rtp ) sil! cal ctrlp#progress('Indexing...') let entries = split(globpath(&rtp, '**/*.*'), "\n") cal filter(entries, 'index(entries, v:val, v:key + 1) < 0') - cal map(entries, 'fnamemodify(v:val, '':.'')') - let [g:ctrlp_rtscache, g:ctrlp_newrts] = [ctrlp#dirnfile(entries)[1], 0] + let [entries, echoed] = [ctrlp#dirnfile(entries)[1], 1] + el + let [entries, results] = g:ctrlp_rtscache[2:3] en - retu g:ctrlp_rtscache -endf - -fu! ctrlp#rtscript#accept(mode, str) - cal ctrlp#acceptfile(a:mode, a:str) + let cwd = getcwd() + if g:ctrlp_newrts + \ || !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[:1] == [&rtp, cwd] ) + if !exists('echoed') | sil! cal ctrlp#progress('Processing...') | en + let results = map(copy(entries), 'fnamemodify(v:val, '':.'')') + en + let [g:ctrlp_rtscache, g:ctrlp_newrts] = [[&rtp, cwd, entries, results], 0] + retu results endf fu! ctrlp#rtscript#id() diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index 98989c8..7e8ab1e 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -28,7 +28,7 @@ Written in pure Vimscript for MacVim and Vim version 7.0+. Has full support for Vim’s |regexp| as search pattern, built-in MRU files monitoring, project’s root finder, and more. -To enable optional extensions (tag, quickfix, dir...), see |ctrlp-extensions|. +To enable optional extensions (tag, dir, rtscript...), see |ctrlp-extensions|. =============================================================================== 2. Options *ctrlp-options* @@ -77,8 +77,8 @@ Set the maximum height of the match window: > < *'g:ctrlp_jump_to_buffer'* -When opening a file, if it's already opened somewhere |CtrlP| will try to jump -to it instead of opening a new window or new tab: > +When opening a file with or , if the file's already opened somewhere +|CtrlP| will try to jump to it instead of opening a new instance: > let g:ctrlp_jump_to_buffer = 2 < 1 - only jump to the buffer if it’s opened in the current tab. @@ -86,8 +86,10 @@ to it instead of opening a new window or new tab: > 0 - disable this feature. *'g:ctrlp_working_path_mode'* -When starting up the prompt, temporarily set the working directory (i.e. the -|current-directory|) to: +When starting up, |CtrlP| sets its local working directory according to this +variable: > + let g:ctrlp_working_path_mode = 2 +< 1 - the parent directory of the current file. 2 - the nearest ancestor that contains one of these directories/files: .git/ @@ -96,9 +98,6 @@ When starting up the prompt, temporarily set the working directory (i.e. the _darcs/ root.dir 0 - don’t manage working directory. -> - let g:ctrlp_working_path_mode = 2 -< *'g:ctrlp_root_markers'* Use this to set your own root markers in addition to the default ones. Your @@ -106,7 +105,7 @@ markers will take precedence: > let g:ctrlp_root_markers = [''] < These markers (builtins and yours) will serve as identifiers for the '/' and -'\' special inputs (section 5.e) +'\' special inputs (section 5.e). *'g:ctrlp_use_caching'* Set this to 0 to disable per-session caching. When disabled, caching will still @@ -116,7 +115,7 @@ be enabled for directories that have more than 4000 files: > Note: you can quickly purge the cache by pressing while inside |CtrlP|. *'g:ctrlp_clear_cache_on_exit'* -Set this to 0 to enable cross-sessions caching by not clearing the cache files +Set this to 0 to enable cross-session caching by not deleting the cache files upon exiting Vim: > let g:ctrlp_clear_cache_on_exit = 1 < @@ -165,8 +164,9 @@ only need to keep the lines that you’ve changed the values (inside []): > \ } < Note: In some terminals, it’s not possible to remap without also changing -. So if pressing moves the cursor to the left instead of deleting a -char for you, add this to your |vimrc| to change the default mapping: > + (|key-codes|). So if pressing moves the cursor to the left instead of +deleting a char for you, add this to your |vimrc| to change the default +mapping: > let g:ctrlp_prompt_mappings = { \ 'PrtBS()': ['', '', ''], \ 'PrtCurLeft()': ['', ''], @@ -217,7 +217,8 @@ Set this to 0 if you don’t want |CtrlP| to search for dotfiles and dotdirs: > let g:ctrlp_dotfiles = 1 < You can use |'wildignore'| to exclude anything from the search. -e.g. exclude version control directories: > +Examples: > + " Excluding version control directories set wildignore+=*/.git/*,*/.hg/*,*/.svn/* " Linux/MacOSX set wildignore+=.git\*,.hg\*,.svn\* " Windows < @@ -225,7 +226,7 @@ Note #1: the `*/` in front of each directory glob is required. Note #2: |wildignore| influences the result of |expand()|, |globpath()| and |glob()| which many plugins use to find stuff on the system (e.g. fugitive.vim -looks for .git/, some other plugins look for external exe tools on Windows). +looks for .git/, some other plugins look for external .exe tools on Windows). So be a little mindful of what you put in your |wildignore|. *'g:ctrlp_custom_ignore'* @@ -260,8 +261,8 @@ The maximum depth of a directory tree to recurse into: > Note: the larger these values, the more memory Vim uses. *'g:ctrlp_user_command'* -Specify an external tool to use for listing files instead of Vim’s globpath(). -Use %s in place of the target directory: > +Specify an external tool to use for listing files instead of using Vim’s +|globpath()|. Use %s in place of the target directory: > let g:ctrlp_user_command = '' < Examples: > @@ -332,7 +333,7 @@ Pressing or will then prompt for a keypress. The key can be: h - open in horizontal split(s) v - open in vertical split(s) r - open in current window (for only) - , - cancel and go back to |CtrlP| + , - cancel and go back to the prompt. Any other key - use the behavior specified with |g:ctrlp_open_new_file| and |g:ctrlp_open_multi|. @@ -401,10 +402,11 @@ See https://gist.github.com/1610859 for a working example. :ClearCtrlPCache Flush the cache for the current working directory. The same as pressing inside |CtrlP|. + You can also enable/disable caching with the option |g:ctrlp_use_caching|. *:ClearAllCtrlPCaches* :ClearAllCtrlPCaches - Delete all the cache files saved in |ctrlp_cache_dir|. + Delete all the cache files saved in |g:ctrlp_cache_dir|. *:ResetCtrlP* :ResetCtrlP @@ -438,7 +440,7 @@ Once inside the prompt:~ See also |input-formats| (guide) and |g:ctrlp_regexp_search| (option). - Toggle between full path search and filename only search. + Toggle between full-path search and filename only search. (note: in filename mode, the prompt’s base is '>d>' instead of '>>>') , 'forward' @@ -529,14 +531,18 @@ Once inside the prompt:~ Clear MRU list. + + Insert the word under the cursor (in the active buffer) into the prompt. + , , - Exit |CtrlP|. can also be used to stop the scan. + Exit |CtrlP|. + can also be used to stop the scan if it’s taking too long. Choose your own mappings with |g:ctrlp_prompt_mappings|. -When inside the match window (press to switch):~ +When inside the match window (press to switch):~ a-z 0-9 @@ -643,7 +649,7 @@ Available extensions:~ * Runtime script mode:~ - Name: 'rtscript' - Command: ':CtrlPRTS' - - Search for files (vimscripts, docs...) in runtimepath. + - Search for files (vimscripts, docs, snippets...) in runtimepath. ------------------------------------------------------------------------------- Buffer Tag mode options:~