diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 52621e9..09237b3 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -83,7 +83,7 @@ let [s:pref, s:opts, s:new_opts] = ['g:ctrlp_', { \ 'use_caching': ['s:caching', 1], \ 'use_migemo': ['s:migemo', 0], \ 'user_command': ['s:usrcmd', ''], - \ 'working_path_mode': ['s:pathmode', 2], + \ 'working_path_mode': ['s:pathmode', 'rc'], \ }, { \ 'open_multiple_files': 's:opmul', \ 'regexp': 's:regexp', @@ -354,26 +354,25 @@ fu! s:lsCmd() if type(cmd) == 1 retu cmd elsei type(cmd) == 3 && len(cmd) >= 2 && cmd[:1] != ['', ''] - " Find a repo root - cal s:findroot(s:dyncwd, cmd[0], 0, 1) - if !exists('s:vcsroot') - " Try the secondary_command + if s:findroot(s:dyncwd, cmd[0], 0, 1) == [] retu len(cmd) == 3 ? cmd[2] : '' en - unl s:vcsroot let s:vcscmd = s:lash == '\' ? 1 : 0 retu cmd[1] elsei type(cmd) == 4 && has_key(cmd, 'types') - for key in sort(keys(cmd['types']), 's:compval') - cal s:findroot(s:dyncwd, cmd['types'][key][0], 0, 1) - if exists('s:vcsroot') | brea | en + let [markrs, cmdtypes] = [[], values(cmd['types'])] + for pair in cmdtypes + cal add(markrs, pair[0]) endfo - if !exists('s:vcsroot') + let fndroot = s:findroot(s:dyncwd, markrs, 0, 1) + if fndroot == [] retu has_key(cmd, 'fallback') ? cmd['fallback'] : '' en - unl s:vcsroot + for pair in cmdtypes + if pair[0] == fndroot[0] | brea | en + endfo let s:vcscmd = s:lash == '\' ? 1 : 0 - retu cmd['types'][key][1] + retu pair[1] en endf " - Buffers {{{1 @@ -813,30 +812,26 @@ fu! s:PrtSwitcher() unl s:force endf " - SetWD() {{{1 -fu! s:SetWD(...) - let pathmode = s:wpmode +fu! s:SetWD(args) let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()] - if a:0 && strlen(a:1) | if type(a:1) - cal ctrlp#setdir(a:1) | retu - el - let pathmode = a:1 - en | en - if a:0 < 2 - if s:crfile =~ '^.\+://' || !pathmode | retu | en + let pmode = has_key(a:args, 'mode') ? a:args['mode'] : s:wpmode + if has_key(a:args, 'dir') && a:args['dir'] != '' + cal ctrlp#setdir(a:args['dir']) | retu + en + if s:crfile =~ '^.\+://' | retu | en + if pmode =~ 'c' || ( !type(pmode) && pmode ) if exists('+acd') | let [s:glb_acd, &acd] = [&acd, 0] | en cal ctrlp#setdir(s:crfpath) en - if pathmode == 1 | retu | en - let markers = ['.git', '.hg', '.svn', '.bzr', '_darcs'] - if type(s:rmarkers) == 3 && !empty(s:rmarkers) - cal extend(markers, s:rmarkers, 0) - let markers = reverse(filter(reverse(markers), 'count(markers, v:val) == 1')) + if pmode =~ 'r' || pmode == 2 + let markers = ['.git', '.hg', '.svn', '.bzr', '_darcs'] + let spath = pmode =~ 'd' ? s:dyncwd : pmode =~ 'w' ? s:cwd : s:crfpath + if type(s:rmarkers) == 3 && !empty(s:rmarkers) + if s:findroot(spath, s:rmarkers, 0, 0) != [] | retu | en + cal filter(markers, 'index(s:rmarkers, v:val) < 0') + en + cal s:findroot(spath, markers, 0, 0) en - for marker in markers - cal s:findroot(s:dyncwd, marker, 0, 0) - if exists('s:foundroot') | brea | en - endfo - unl! s:foundroot endf " * AcceptSelection() {{{1 fu! ctrlp#acceptfile(mode, line, ...) @@ -883,7 +878,7 @@ fu! s:SpecInputs(str) cal s:PrtClear() retu 1 elsei a:str == s:lash && s:spi - cal s:SetWD(2, 0) + cal s:SetWD({ 'mode': 'rd' }) cal ctrlp#setlines() cal s:PrtClear() retu 1 @@ -1223,7 +1218,8 @@ fu! ctrlp#progress(enum, ...) \ : '%#CtrlPStats# '.a:enum.' %* '.txt.'%=%<%#CtrlPMode2# %{getcwd()} %*' redraws endf -" Paths {{{2 +" *** Paths {{{2 +" Line formatting {{{3 fu! s:formatline(str) let cond = s:ispath && ( s:winw - 4 ) < s:strwidth(a:str) retu '> '.( cond ? s:pathshorten(a:str) : a:str ) @@ -1233,7 +1229,7 @@ fu! s:pathshorten(str) retu matchstr(a:str, '^.\{9}').'...' \ .matchstr(a:str, '.\{'.( s:winw - 16 ).'}$') endf - +" Directory completion {{{3 fu! s:dircompl(be, sd) if a:sd == '' | retu [] | en let [be, sd] = a:be == '' ? [s:dyncwd, a:sd] : [a:be, a:be.s:lash(a:be).a:sd] @@ -1256,7 +1252,7 @@ fu! s:findcommon(items, seed) endfo retu cmn endf - +" Misc {{{3 fu! s:headntail(str) let parts = split(a:str, '[\/]\ze[^\/]\+[\/:]\?$') retu len(parts) == 1 ? ['', parts[0]] : len(parts) == 2 ? parts : [] @@ -1314,7 +1310,7 @@ fu! ctrlp#rmbasedir(items) en retu a:items endf - +" Working directory {{{3 fu! s:getparent(item) let parent = substitute(a:item, '[\/][^\/]\+[\/:]\?$', '', '') if parent == '' || parent !~ '[\/]' @@ -1324,20 +1320,34 @@ fu! s:getparent(item) endf fu! s:findroot(curr, mark, depth, type) - let [depth, notfound] = [a:depth + 1, empty(s:glbpath(a:curr, a:mark, 1))] - if !notfound || depth > s:maxdepth - if notfound | cal ctrlp#setdir(s:cwd) | en - if a:type && depth <= s:maxdepth - let s:vcsroot = a:curr - elsei !a:type && !notfound - cal ctrlp#setdir(a:curr) | let s:foundroot = 1 - en + let [depth, fnd] = [a:depth + 1, 0] + if type(a:mark) == 1 + let fnd = s:glbpath(a:curr, a:mark, 1) != '' + elsei type(a:mark) == 3 + for markr in a:mark + if s:glbpath(a:curr, markr, 1) != '' | let fnd = 1 | brea | en + endfo + en + if fnd + if !a:type | cal ctrlp#setdir(a:curr) | en + retu [exists('markr') ? markr : a:mark, a:curr] + elsei depth > s:maxdepth + cal ctrlp#setdir(s:cwd) el let parent = s:getparent(a:curr) - if parent != a:curr | cal s:findroot(parent, a:mark, depth, a:type) | en + if parent != a:curr + retu s:findroot(parent, a:mark, depth, a:type) + en en + retu [] endf +fu! ctrlp#setdir(path, ...) + let cmd = a:0 ? a:1 : 'lc!' + sil! exe cmd ctrlp#fnesc(a:path) + let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()] +endf +" Fallbacks {{{3 fu! s:glbpath(...) let cond = v:version > 702 || ( v:version == 702 && has('patch051') ) retu call('globpath', cond ? a:000 : a:000[:1]) @@ -1347,12 +1357,6 @@ fu! ctrlp#fnesc(path) retu exists('*fnameescape') ? fnameescape(a:path) : escape(a:path, " %#*?|<\"\n") endf -fu! ctrlp#setdir(path, ...) - let cmd = a:0 ? a:1 : 'lc!' - sil! exe cmd ctrlp#fnesc(a:path) - let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()] -endf - fu! ctrlp#setlcdir() if exists('*haslocaldir') cal ctrlp#setdir(getcwd(), haslocaldir() ? 'lc!' : 'cd!') @@ -1912,7 +1916,7 @@ fu! ctrlp#init(type, ...) let [s:matches, s:init] = [1, 1] cal ctrlp#reset() noa cal s:Open() - cal s:SetWD(a:0 ? a:1 : '') + cal s:SetWD(a:0 ? a:1 : {}) cal s:MapKeys() cal ctrlp#syntax() cal ctrlp#setlines(s:settype(a:type)) diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index 8ecc9c7..90f2043 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -160,14 +160,18 @@ Where to put the new tab page when opening one: > *'g:ctrlp_working_path_mode'* When starting up, CtrlP sets its local working directory according to this variable: > - let g:ctrlp_working_path_mode = 2 + let g:ctrlp_working_path_mode = 'rc' < - 1 - the directory of the current file. - 2 - the nearest ancestor that contains one of these directories or files: + c - the directory of the current file. + r - the nearest ancestor that contains one of these directories or files: .git .hg .svn .bzr _darcs - 0 - don't manage working directory. -Note: you can use b:ctrlp_working_path_mode (a |b:var|) to set this option on a -per buffer basis. + {empty-string} - don't manage working directory. + +Note #1: you can use b:ctrlp_working_path_mode (a |b:var|) to set this option +on a per buffer basis. + +Note #2: with both 'r' and 'c' in the option, when a root isn't found, use the +directory of the current file. *'g:ctrlp_root_markers'* Use this to set your own root markers in addition to the default ones (.git, @@ -200,7 +204,10 @@ Set the directory to store the cache files: > Set this to 0 if you don't want CtrlP to scan for dotfiles and dotdirs: > let g:ctrlp_dotfiles = 1 < -You can use |'wildignore'| to exclude anything from the search. + + *'ctrlp-wildignore'* +You can use Vim's |'wildignore'| to exclude files and directories from the +results. Examples: > " Excluding version control directories set wildignore+=*/.git/*,*/.hg/*,*/.svn/* " Linux/MacOSX @@ -226,7 +233,7 @@ Examples: > \ 'link': 'SOME_BAD_SYMBOLIC_LINKS', \ } < -Note: ignoring only works when |globpath()| is used to scan for files. +Note: ignoring only applies when |globpath()| is used to scan for files. *'g:ctrlp_max_files'* The maximum number of files to scan, set to 0 for no limit: > @@ -307,6 +314,7 @@ For the number: - If given, it'll be used as the maximum number of windows or tabs to create when opening the files (the rest will be opened as hidden buffers). - If not given, will open all files, each in a new window or new tab. + For the letters: t - each file in a new tab. h - each file in a new horizontal split. @@ -475,17 +483,19 @@ Structure of the functions: > " | + 'h' : user pressed (default) " | + 'v' : user pressed (default) " | + 't' : user pressed (default) - " | + 'x' : user used the dialog (default) and chose - " | "e[x]ternal". + " | + 'x' : user used the console dialog (default) and + " | chose "e[x]ternal". " | " +- a:line : The selected line. endfunction < -Linux example: open HTML files in the default web browser when is pressed -and in Vim otherwise > +Note: does not apply when opening multiple files with and . + +Example: open HTML files in the default web browser when is pressed and +in Vim otherwise > function! HTMLOpenFunc(action, line) - if a:action == 't' && fnamemodify(a:line, ':e') =~? '^html\?$' + if a:action =~ '^[tx]$' && fnamemodify(a:line, ':e') =~? '^html\?$' " Get the filename let filename = fnameescape(fnamemodify(a:line, ':p')) @@ -498,7 +508,7 @@ and in Vim otherwise > elseif a:action == 'x' && fnamemodify(a:line, ':e') !~? '^html\?$' - " Not a HTML file, simulate pressing again + " Not a HTML file, simulate pressing again and wait for new input call feedkeys("\") else @@ -511,7 +521,6 @@ and in Vim otherwise > let g:ctrlp_open_func = { 'files': 'HTMLOpenFunc' } < -Note: this option does not apply when opening multiple files with , . *'g:ctrlp_status_func'* Use this to customize the statuslines for the CtrlP window: > @@ -630,8 +639,8 @@ COMMANDS *ctrlp-commands* *:CtrlPRoot* :CtrlPRoot - This acts like |:CtrlP| with |g:ctrlp_working_path_mode| = 2 (ignores the - variable's current value). + This acts like |:CtrlP| with |g:ctrlp_working_path_mode| = 'rc' and ignores + the variable's current value. *:CtrlPClearCache* :CtrlPClearCache @@ -778,7 +787,7 @@ Pasting:~ Paste the clipboard content into the prompt. - Open a text dialog to paste , , the content of the search + Open a console dialog to paste , , the content of the search register, the last visual selection, the clipboard or any register into the prompt. @@ -790,8 +799,7 @@ When inside the match window (press to switch):~ a-z 0-9 ~^-=;`',.+!@#$%&_(){}[] - Cycle through the lines with the first letter (of paths or filenames) that - matches that key. + Cycle through the lines which have the matching first character. =============================================================================== INPUT FORMATS *ctrlp-input-formats* diff --git a/plugin/ctrlp.vim b/plugin/ctrlp.vim index f717583..f7d1b13 100644 --- a/plugin/ctrlp.vim +++ b/plugin/ctrlp.vim @@ -17,10 +17,10 @@ let [g:ctrlp_lines, g:ctrlp_allfiles, g:ctrlp_alltags, g:ctrlp_alldirs, if !exists('g:ctrlp_map') | let g:ctrlp_map = '' | en if !exists('g:ctrlp_cmd') | let g:ctrlp_cmd = 'CtrlP' | en -com! -n=? -com=dir CtrlP cal ctrlp#init(0, ) +com! -n=? -com=dir CtrlP cal ctrlp#init(0, { 'dir': }) +com! -n=? -com=dir CtrlPMRUFiles cal ctrlp#init(2, { 'dir': }) com! -bar CtrlPBuffer cal ctrlp#init(1) -com! -bar CtrlPMRUFiles cal ctrlp#init(2) com! -bar CtrlPLastMode cal ctrlp#init(-1) com! -bar CtrlPClearCache cal ctrlp#clr() @@ -31,9 +31,9 @@ com! -bar ClearCtrlPCache cal ctrlp#clr() com! -bar ClearAllCtrlPCaches cal ctrlp#clra() com! -bar ResetCtrlP cal ctrlp#reset() -com! -bar CtrlPCurWD cal ctrlp#init(0, 0) -com! -bar CtrlPCurFile cal ctrlp#init(0, 1) -com! -bar CtrlPRoot cal ctrlp#init(0, 2) +com! -bar CtrlPCurWD cal ctrlp#init(0, { 'mode': '' }) +com! -bar CtrlPCurFile cal ctrlp#init(0, { 'mode': 'c' }) +com! -bar CtrlPRoot cal ctrlp#init(0, { 'mode': 'rc' }) if g:ctrlp_map != '' && !hasmapto(':'.g:ctrlp_cmd.'', 'n') exe 'nn ' g:ctrlp_map ':'.g:ctrlp_cmd.'' @@ -41,20 +41,26 @@ en cal ctrlp#mrufiles#init() -com! -bar CtrlPTag cal ctrlp#init(ctrlp#tag#id()) -com! -bar CtrlPQuickfix cal ctrlp#init(ctrlp#quickfix#id()) +com! -bar CtrlPTag cal ctrlp#init(ctrlp#tag#id()) +com! -bar CtrlPQuickfix cal ctrlp#init(ctrlp#quickfix#id()) + com! -n=? -com=dir CtrlPDir - \ cal ctrlp#init(ctrlp#dir#id(), ) + \ cal ctrlp#init(ctrlp#dir#id(), { 'dir': }) + com! -n=? -com=buffer CtrlPBufTag \ cal ctrlp#init(ctrlp#buffertag#cmd(0, )) -com! -bar CtrlPBufTagAll cal ctrlp#init(ctrlp#buffertag#cmd(1)) -com! -bar CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id()) -com! -bar CtrlPUndo cal ctrlp#init(ctrlp#undo#id()) -com! -bar CtrlPLine cal ctrlp#init(ctrlp#line#id()) + +com! -bar CtrlPBufTagAll cal ctrlp#init(ctrlp#buffertag#cmd(1)) +com! -bar CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id()) +com! -bar CtrlPUndo cal ctrlp#init(ctrlp#undo#id()) +com! -bar CtrlPLine cal ctrlp#init(ctrlp#line#id()) + com! -n=? -com=buffer CtrlPChange \ cal ctrlp#init(ctrlp#changes#cmd(0, )) + com! -bar CtrlPChangeAll cal ctrlp#init(ctrlp#changes#cmd(1)) com! -bar CtrlPMixed cal ctrlp#init(ctrlp#mixed#id()) com! -bar CtrlPBookmarkDir cal ctrlp#init(ctrlp#bookmarkdir#id()) + com! -n=? -com=dir CtrlPBookmarkDirAdd \ cal ctrlp#call('ctrlp#bookmarkdir#add', ) diff --git a/readme.md b/readme.md index ba456ca..90d6e6f 100644 --- a/readme.md +++ b/readme.md @@ -46,12 +46,12 @@ Use `:difft` when opening multiple files to run `:difft` on the first 4 files. * When invoked, unless a starting directory is specified, CtrlP will set its local working directory according to this variable: ```vim - let g:ctrlp_working_path_mode = 2 + let g:ctrlp_working_path_mode = 'rc' ``` - 0 - don't manage working directory. - 1 - the directory of the current file. - 2 - the nearest ancestor that contains one of these directories or files: + `{empty-string}` - don't manage working directory. + `c` - the directory of the current file. + `r` - the nearest ancestor that contains one of these directories or files: `.git` `.hg` `.svn` `.bzr` `_darcs` Define additional root markers with the `g:ctrlp_root_markers` option.