Smarter OpenMulti() action
This commit is contained in:
parent
c8d02c5902
commit
b7d87e1cfb
@ -255,11 +255,7 @@ endfunc
|
|||||||
func! s:BufOpen(...) "{{{
|
func! s:BufOpen(...) "{{{
|
||||||
if exists('a:2')
|
if exists('a:2')
|
||||||
" Closing
|
" Closing
|
||||||
try
|
try | bun! | catch | clo! | endtry
|
||||||
bun!
|
|
||||||
catch
|
|
||||||
winc c
|
|
||||||
endtry
|
|
||||||
exe s:currwin.'winc w'
|
exe s:currwin.'winc w'
|
||||||
" Restore the changed global options
|
" Restore the changed global options
|
||||||
let &magic = s:CtrlP_magic
|
let &magic = s:CtrlP_magic
|
||||||
@ -427,7 +423,7 @@ func! s:CreateNewFile() "{{{
|
|||||||
let arr = split(str, '[\/]')
|
let arr = split(str, '[\/]')
|
||||||
cal map(arr, 'escape(v:val, "%#")')
|
cal map(arr, 'escape(v:val, "%#")')
|
||||||
let fname = remove(arr, -1)
|
let fname = remove(arr, -1)
|
||||||
winc c
|
clo!
|
||||||
if s:newfop == 1 " In new tab
|
if s:newfop == 1 " In new tab
|
||||||
tabnew
|
tabnew
|
||||||
let cmd = 'e'
|
let cmd = 'e'
|
||||||
@ -490,34 +486,36 @@ func! s:OpenMulti()
|
|||||||
if !has('autocmd') | cal s:BufOpen('ControlP', 'del') | endif
|
if !has('autocmd') | cal s:BufOpen('ControlP', 'del') | endif
|
||||||
exe s:currwin.'winc w'
|
exe s:currwin.'winc w'
|
||||||
" Try not to open in new tab
|
" Try not to open in new tab
|
||||||
let bufs = []
|
let ntab = 0
|
||||||
for winnr in range(1, winnr('$'))
|
let norbufs = s:normbuf()
|
||||||
cal add(bufs, winbufnr(winnr))
|
if empty(norbufs)
|
||||||
endfor
|
let ntab = 1
|
||||||
let ntab = 1
|
else
|
||||||
" Check if the other window only has a blank buffer
|
for each in norbufs
|
||||||
if len(bufs) == 1
|
let bufnr = winbufnr(each)
|
||||||
for each in bufs
|
if !empty(bufname(bufnr)) && !empty(getbufvar(bufnr, '&ft'))
|
||||||
if getbufvar(each, '&bl') && empty(bufname(each))
|
\ && bufname(bufnr) != 'ControlP'
|
||||||
\ && empty(getbufvar(each, '&bt')) && empty(getbufvar(each, '&ft'))
|
let ntab = 1
|
||||||
\ && getbufvar(each, '&ma') && bufname(each) != 'ControlP'
|
|
||||||
" If it does, don't open new tab
|
|
||||||
let ntab = 0
|
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
if !ntab
|
||||||
|
let wnr = min(norbufs)
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
if ntab | tabnew | endif
|
if ntab | tabnew | endif
|
||||||
let ic = 1
|
let ic = 1
|
||||||
|
let wnr = exists('wnr') ? wnr : 1
|
||||||
|
exe wnr.'winc w'
|
||||||
for key in keys(marked)
|
for key in keys(marked)
|
||||||
let filpath = marked[key]
|
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
|
if s:opmul > 1 && s:opmul < ic
|
||||||
winc c
|
clo!
|
||||||
else
|
else
|
||||||
let ic += 1
|
let ic += 1
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
1winc w | winc c
|
|
||||||
ec
|
ec
|
||||||
endfunc
|
endfunc
|
||||||
"}}}
|
"}}}
|
||||||
@ -844,12 +842,20 @@ func! s:AcceptSelection(mode,...) "{{{
|
|||||||
let md = a:mode
|
let md = a:mode
|
||||||
let prt = g:CtrlP_prompt
|
let prt = g:CtrlP_prompt
|
||||||
let str = prt[0] . prt[1] . prt[2]
|
let str = prt[0] . prt[1] . prt[2]
|
||||||
" Walk backward the dir tree
|
if md == 'e' && !s:itemtype
|
||||||
if md == 'e' && !s:itemtype && str == '..'
|
" Walk backward the dir tree
|
||||||
cal s:parentdir(getcwd())
|
if str == '..'
|
||||||
cal s:SetLines(s:itemtype)
|
cal s:parentdir(getcwd())
|
||||||
cal s:PrtClear()
|
cal s:SetLines(s:itemtype)
|
||||||
retu
|
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
|
endif
|
||||||
" Get the full path
|
" Get the full path
|
||||||
let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$')
|
let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$')
|
||||||
@ -859,9 +865,10 @@ func! s:AcceptSelection(mode,...) "{{{
|
|||||||
if exists('a:1') && a:1 | retu filpath | endif
|
if exists('a:1') && a:1 | retu filpath | endif
|
||||||
" Manually remove the prompt and match window
|
" Manually remove the prompt and match window
|
||||||
if !has('autocmd') | cal s:BufOpen('ControlP', 'del') | endif
|
if !has('autocmd') | cal s:BufOpen('ControlP', 'del') | endif
|
||||||
let bufnum = bufnr(filpath)
|
let bufnum = bufnr(filpath)
|
||||||
let bufwinnr = bufwinnr(bufnum)
|
let bufwinnr = bufwinnr(bufnum)
|
||||||
let norbuf = s:normbuf()
|
let norbufs = s:normbuf()
|
||||||
|
let norbuf = empty(norbufs) ? 0 : norbufs[0]
|
||||||
exe s:currwin.'winc w'
|
exe s:currwin.'winc w'
|
||||||
" Check if the file's already opened in a tab
|
" Check if the file's already opened in a tab
|
||||||
for nr in range(1, tabpagenr('$'))
|
for nr in range(1, tabpagenr('$'))
|
||||||
@ -949,6 +956,13 @@ func! s:compword(s1, s2)
|
|||||||
retu wrd1 == wrd2 ? 0 : wrd1 > wrd2 ? 1 : -1
|
retu wrd1 == wrd2 ? 0 : wrd1 > wrd2 ? 1 : -1
|
||||||
endfunc
|
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, ...)
|
func! s:matchlens(str, pat, ...)
|
||||||
if empty(a:pat) || index(['^','$'], a:pat) >= 0
|
if empty(a:pat) || index(['^','$'], a:pat) >= 0
|
||||||
retu {}
|
retu {}
|
||||||
@ -986,7 +1000,11 @@ func! s:wordonly(lens)
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func! s:mixedsort(s1, s2)
|
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
|
endfunc
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
@ -1173,15 +1191,15 @@ endfunc
|
|||||||
|
|
||||||
" Buffers {{{
|
" Buffers {{{
|
||||||
func! s:normbuf()
|
func! s:normbuf()
|
||||||
if &l:bl && empty(&l:bt) && &l:ma | retu winnr() | endif
|
let bufs = []
|
||||||
for each in range(1, winnr('$'))
|
for each in range(1, winnr('$'))
|
||||||
let bufnr = winbufnr(each)
|
let bufnr = winbufnr(each)
|
||||||
if getbufvar(bufnr, '&bl') && empty(getbufvar(bufnr, '&bt'))
|
if getbufvar(bufnr, '&bl') && empty(getbufvar(bufnr, '&bt'))
|
||||||
\ && getbufvar(bufnr, '&ma')
|
\ && getbufvar(bufnr, '&ma')
|
||||||
retu each
|
cal add(bufs, each)
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
retu 0
|
retu bufs
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func! s:setupblank()
|
func! s:setupblank()
|
||||||
|
@ -221,6 +221,11 @@ Use %s in place of the target directory: >
|
|||||||
Examples: >
|
Examples: >
|
||||||
let g:ctrlp_user_command = 'find %s -type f' " MacOSX/Linux
|
let g:ctrlp_user_command = 'find %s -type f' " MacOSX/Linux
|
||||||
let g:ctrlp_user_command = 'dir %s /-n /b /s /a-d' " Windows
|
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.
|
You can also use 'grep', 'findstr' or something else to filter the results.
|
||||||
Examples: >
|
Examples: >
|
||||||
@ -441,6 +446,8 @@ e) Type the name of a non-existed file and press <c-y> to create it.
|
|||||||
e.g. 'parentdir/file.txt' will create a directory named 'parentdir' as well
|
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).
|
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*
|
6. Credits *ctrlp-credits*
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ Once CtrlP is open:
|
|||||||
e.g. `abc:45` will open the file matched the pattern and jump to line 45.
|
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.
|
* Submit two dots `..` as the input string to go backward the directory tree by 1 level.
|
||||||
* Use `<c-y>` to create a new file and its parent dirs.
|
* Use `<c-y>` to create a new file and its parent dirs.
|
||||||
|
* Use <c-z> to mark multiple files and <c-o> to open them.
|
||||||
|
|
||||||
## Basic Options
|
## Basic Options
|
||||||
* Change the mapping to invoke CtrlP:
|
* Change the mapping to invoke CtrlP:
|
||||||
|
Loading…
Reference in New Issue
Block a user