Preserve neighboring windows' height
* Save the window heights and restore them later, prevent ctrlp from nudging the bottom (or top) windows when it opens. * Escape whitespaces in path. Close #26.
This commit is contained in:
parent
087c64efcd
commit
2f4d281eed
@ -2,7 +2,7 @@
|
|||||||
" File: autoload/ctrlp.vim
|
" File: autoload/ctrlp.vim
|
||||||
" Description: Full path fuzzy file, buffer and MRU file finder for Vim
|
" Description: Full path fuzzy file, buffer and MRU file finder for Vim
|
||||||
" Author: Kien Nguyen <github.com/kien>
|
" Author: Kien Nguyen <github.com/kien>
|
||||||
" Version: 1.5.8
|
" Version: 1.5.9
|
||||||
" =============================================================================
|
" =============================================================================
|
||||||
|
|
||||||
" Static variables {{{
|
" Static variables {{{
|
||||||
@ -61,6 +61,7 @@ let [s:compare_lim, s:nocache_lim, s:mltipats_lim] = [3000, 4000, 2000]
|
|||||||
"}}}
|
"}}}
|
||||||
" * Open & Close {{{
|
" * Open & Close {{{
|
||||||
fu! s:Open()
|
fu! s:Open()
|
||||||
|
let s:winres = winrestcmd()
|
||||||
sil! exe s:mwbottom ? 'bo' : 'to' '1new ControlP'
|
sil! exe s:mwbottom ? 'bo' : 'to' '1new ControlP'
|
||||||
let s:currwin = s:mwbottom ? winnr('#') : winnr('#') + 1
|
let s:currwin = s:mwbottom ? winnr('#') : winnr('#') + 1
|
||||||
let [s:winnr, s:bufnr, s:prompt] = [bufwinnr('%'), bufnr('%'), ['', '', '']]
|
let [s:winnr, s:bufnr, s:prompt] = [bufwinnr('%'), bufnr('%'), ['', '', '']]
|
||||||
@ -86,11 +87,10 @@ fu! s:Close()
|
|||||||
endfo
|
endfo
|
||||||
if exists('s:glb_acd') | let &acd = s:glb_acd | en
|
if exists('s:glb_acd') | let &acd = s:glb_acd | en
|
||||||
let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []]
|
let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []]
|
||||||
if exists('s:cwd')
|
sil! exe 'chd!' s:cwd
|
||||||
exe 'chd!' s:cwd
|
exe s:winres
|
||||||
unl s:cwd
|
unl! s:focus s:hisidx s:hstgot s:marked s:winnr s:statypes s:cline s:cwd
|
||||||
en
|
\ s:init s:savestr s:winres
|
||||||
unl! s:focus s:hisidx s:hstgot s:marked s:winnr s:init s:savestr s:cline s:statypes
|
|
||||||
cal s:recordhist(join(s:prompt, ''))
|
cal s:recordhist(join(s:prompt, ''))
|
||||||
ec
|
ec
|
||||||
endf
|
endf
|
||||||
@ -223,17 +223,7 @@ fu! s:MatchedItems(items, pats, limit)
|
|||||||
endf
|
endf
|
||||||
"}}}
|
"}}}
|
||||||
fu! s:SplitPattern(str,...) "{{{
|
fu! s:SplitPattern(str,...) "{{{
|
||||||
" Restore the number of backslashes
|
let str = s:sanstail(a:str)
|
||||||
let str = substitute(a:str, '\\\\', '\', 'g')
|
|
||||||
" Clear the tail var
|
|
||||||
unl! s:optail
|
|
||||||
" If pattern contains :str$
|
|
||||||
if match(str, ':\([^:]\|\\:\)*$') >= 0
|
|
||||||
" Set the tail var
|
|
||||||
let s:optail = matchstr(str, ':\zs\([^:]\|\\:\)*$')
|
|
||||||
" Remove the tail
|
|
||||||
let str = substitute(str, ':\([^:]\|\\:\)*$', '', 'g')
|
|
||||||
en
|
|
||||||
let s:savestr = str
|
let s:savestr = str
|
||||||
if s:regexp || match(str, '\\\(zs\|ze\|<\|>\)\|[*|]') >= 0
|
if s:regexp || match(str, '\\\(zs\|ze\|<\|>\)\|[*|]') >= 0
|
||||||
let array = [s:regexfilter(str)]
|
let array = [s:regexfilter(str)]
|
||||||
@ -624,19 +614,11 @@ fu! ctrlp#acceptfile(mode, matchstr)
|
|||||||
" Get the full path
|
" Get the full path
|
||||||
let filpath = s:itemtype ? matchstr : getcwd().s:lash.matchstr
|
let filpath = s:itemtype ? matchstr : getcwd().s:lash.matchstr
|
||||||
cal s:PrtExit()
|
cal s:PrtExit()
|
||||||
let [bufnum, norwins] = [bufnr(filpath), s:normbuf()]
|
let bufnum = bufnr(filpath)
|
||||||
let norwin = empty(norwins) ? 0 : norwins[0]
|
|
||||||
if s:jmptobuf && bufnum > 0 && md == 'e'
|
if s:jmptobuf && bufnum > 0 && md == 'e'
|
||||||
let [jmpb, bufwinnr] = [1, bufwinnr(bufnum)]
|
let [jmpb, bufwinnr] = [1, bufwinnr(bufnum)]
|
||||||
let buftab = s:jmptobuf > 1 ? s:buftab(bufnum) : [0, 0]
|
let buftab = s:jmptobuf > 1 ? s:buftab(bufnum) : [0, 0]
|
||||||
en
|
en
|
||||||
" Get the tail
|
|
||||||
let tail = ''
|
|
||||||
if exists('s:optail') && !empty('s:optail')
|
|
||||||
let tailpref = match(s:optail, '^\s*+') < 0 ? ' +' : ' '
|
|
||||||
let tail = tailpref.s:optail
|
|
||||||
en
|
|
||||||
let filpath = escape(filpath, '%#')
|
|
||||||
" Switch to existing buffer or open new one
|
" Switch to existing buffer or open new one
|
||||||
if exists('jmpb') && buftab[0]
|
if exists('jmpb') && buftab[0]
|
||||||
exe 'norm!' buftab[1].'gt'
|
exe 'norm!' buftab[1].'gt'
|
||||||
@ -653,24 +635,10 @@ fu! ctrlp#acceptfile(mode, matchstr)
|
|||||||
elsei md == 'v' || s:splitwin == 3
|
elsei md == 'v' || s:splitwin == 3
|
||||||
let cmd = 'vne'
|
let cmd = 'vne'
|
||||||
el
|
el
|
||||||
let cmd = 'e'
|
let cmd = s:normcmd('e')
|
||||||
" If there's at least 1 normal buffer
|
|
||||||
if norwin
|
|
||||||
" But not the current one
|
|
||||||
if !&l:bl || !empty(&l:bt) || !&l:ma
|
|
||||||
" Go to the first normal one
|
|
||||||
exe norwin.'winc w'
|
|
||||||
en
|
|
||||||
el
|
|
||||||
" No normal buffers
|
|
||||||
let cmd = 'vne'
|
|
||||||
en
|
|
||||||
en
|
en
|
||||||
" Open new window/buffer
|
" Open new window/buffer
|
||||||
cal s:openfile(cmd.tail.' '.filpath)
|
cal s:openfile(cmd, filpath)
|
||||||
en
|
|
||||||
if !empty('tail')
|
|
||||||
sil! norm! zOzz
|
|
||||||
en
|
en
|
||||||
endf
|
endf
|
||||||
|
|
||||||
@ -703,15 +671,9 @@ endf
|
|||||||
fu! s:CreateNewFile() "{{{
|
fu! s:CreateNewFile() "{{{
|
||||||
let str = join(s:prompt, '')
|
let str = join(s:prompt, '')
|
||||||
if empty(str) | retu | en
|
if empty(str) | retu | en
|
||||||
|
let str = s:sanstail(str)
|
||||||
let arr = split(str, '[\/]')
|
let arr = split(str, '[\/]')
|
||||||
let fname = remove(arr, -1)
|
let fname = remove(arr, -1)
|
||||||
if s:newfop <= 1
|
|
||||||
let cmd = 'e'
|
|
||||||
elsei s:newfop == 2
|
|
||||||
let cmd = 'new'
|
|
||||||
elsei s:newfop == 3
|
|
||||||
let cmd = 'vne'
|
|
||||||
en
|
|
||||||
if len(arr) | if isdirectory(s:createparentdirs(arr))
|
if len(arr) | if isdirectory(s:createparentdirs(arr))
|
||||||
let optyp = str
|
let optyp = str
|
||||||
en | el
|
en | el
|
||||||
@ -720,8 +682,17 @@ fu! s:CreateNewFile() "{{{
|
|||||||
if exists('optyp')
|
if exists('optyp')
|
||||||
cal s:insertcache(str)
|
cal s:insertcache(str)
|
||||||
cal s:PrtExit()
|
cal s:PrtExit()
|
||||||
if s:newfop == 1 | tabnew | en
|
if s:newfop == 1
|
||||||
cal s:openfile(cmd.' '.escape(getcwd().s:lash.optyp, '%#'))
|
tabnew
|
||||||
|
let cmd = 'e'
|
||||||
|
elsei s:newfop == 2
|
||||||
|
let cmd = 'new'
|
||||||
|
elsei s:newfop == 3
|
||||||
|
let cmd = 'vne'
|
||||||
|
el
|
||||||
|
let cmd = s:normcmd('e')
|
||||||
|
en
|
||||||
|
cal s:openfile(cmd, getcwd().s:lash.optyp)
|
||||||
en
|
en
|
||||||
endf "}}}
|
endf "}}}
|
||||||
" * OpenMulti() {{{
|
" * OpenMulti() {{{
|
||||||
@ -761,7 +732,7 @@ fu! s:OpenMulti()
|
|||||||
en
|
en
|
||||||
let mkd = s:marked
|
let mkd = s:marked
|
||||||
cal s:PrtExit()
|
cal s:PrtExit()
|
||||||
" Try not to open in new tab
|
" Try not to open a new tab
|
||||||
let [ntab, norwins] = [0, s:normbuf()]
|
let [ntab, norwins] = [0, s:normbuf()]
|
||||||
if empty(norwins) | let ntab = 1 | el
|
if empty(norwins) | let ntab = 1 | el
|
||||||
for each in norwins
|
for each in norwins
|
||||||
@ -777,9 +748,8 @@ fu! s:OpenMulti()
|
|||||||
let [ic, wnr] = [1, exists('wnr') ? wnr : 1]
|
let [ic, wnr] = [1, exists('wnr') ? wnr : 1]
|
||||||
exe wnr.'winc w'
|
exe wnr.'winc w'
|
||||||
for key in keys(mkd)
|
for key in keys(mkd)
|
||||||
let filpath = escape(mkd[key], '%#')
|
let cmd = ic == 1 ? 'e' : 'vne'
|
||||||
let cmd = ic == 1 ? 'e ' : 'vne '
|
cal s:openfile(cmd, mkd[key])
|
||||||
sil! exe cmd.filpath
|
|
||||||
if s:opmul > 1 && s:opmul < ic | clo!
|
if s:opmul > 1 && s:opmul < ic | clo!
|
||||||
el | let ic += 1 | en
|
el | let ic += 1 | en
|
||||||
endfo
|
endfo
|
||||||
@ -815,7 +785,7 @@ fu! s:comptime(s1, s2)
|
|||||||
endf
|
endf
|
||||||
|
|
||||||
fu! s:matchlens(str, pat, ...)
|
fu! s:matchlens(str, pat, ...)
|
||||||
if empty(a:pat) || index(['^','$'], a:pat) >= 0 | retu {} | en
|
if empty(a:pat) || a:pat =~ '^\|$' | retu {} | en
|
||||||
let st = exists('a:1') ? a:1 : 0
|
let st = exists('a:1') ? a:1 : 0
|
||||||
let lens = exists('a:2') ? a:2 : {}
|
let lens = exists('a:2') ? a:2 : {}
|
||||||
let nr = exists('a:3') ? a:3 : 0
|
let nr = exists('a:3') ? a:3 : 0
|
||||||
@ -1059,6 +1029,21 @@ fu! s:normbuf()
|
|||||||
retu winnrs
|
retu winnrs
|
||||||
endf
|
endf
|
||||||
|
|
||||||
|
fu! s:normcmd(cmd)
|
||||||
|
let norwins = s:normbuf()
|
||||||
|
let norwin = empty(norwins) ? 0 : norwins[0]
|
||||||
|
" If there's at least 1 normal buffer
|
||||||
|
if norwin
|
||||||
|
" But not the current one
|
||||||
|
if index(norwins, winnr()) < 0
|
||||||
|
exe norwin.'winc w'
|
||||||
|
en
|
||||||
|
retu a:cmd
|
||||||
|
el
|
||||||
|
retu 'bo vne'
|
||||||
|
en
|
||||||
|
endf
|
||||||
|
|
||||||
fu! s:setupblank()
|
fu! s:setupblank()
|
||||||
setl noswf nobl nonu nowrap nolist nospell cul nocuc wfh fdc=0 tw=0 bt=nofile bh=unload
|
setl noswf nobl nonu nowrap nolist nospell cul nocuc wfh fdc=0 tw=0 bt=nofile bh=unload
|
||||||
if v:version >= 703
|
if v:version >= 703
|
||||||
@ -1078,7 +1063,43 @@ fu! s:checkbuf()
|
|||||||
en
|
en
|
||||||
endf
|
endf
|
||||||
"}}}
|
"}}}
|
||||||
|
" Arguments {{{
|
||||||
|
fu! s:tail()
|
||||||
|
if exists('s:optail') && !empty('s:optail')
|
||||||
|
let tailpref = match(s:optail, '^\s*+') < 0 ? ' +' : ' '
|
||||||
|
retu tailpref.s:optail
|
||||||
|
en
|
||||||
|
retu ''
|
||||||
|
endf
|
||||||
|
|
||||||
|
fu! s:sanstail(str)
|
||||||
|
" Restore the number of backslashes
|
||||||
|
let str = substitute(a:str, '\\\\', '\', 'g')
|
||||||
|
unl! s:optail
|
||||||
|
if match(str, ':\([^:]\|\\:\)*$') >= 0
|
||||||
|
let s:optail = matchstr(str, ':\zs\([^:]\|\\:\)*$')
|
||||||
|
retu substitute(str, ':\([^:]\|\\:\)*$', '', 'g')
|
||||||
|
el
|
||||||
|
retu str
|
||||||
|
en
|
||||||
|
endf
|
||||||
|
"}}}
|
||||||
" Misc {{{
|
" Misc {{{
|
||||||
|
fu! s:openfile(cmd, filpath)
|
||||||
|
let cmd = a:cmd == 'e' && &modified ? 'new' : a:cmd
|
||||||
|
try
|
||||||
|
exe cmd.s:tail().' '.escape(a:filpath, '%# ')
|
||||||
|
cat
|
||||||
|
echoh Identifier
|
||||||
|
echon "CtrlP: Operation can't be completed. Make sure filename is valid."
|
||||||
|
echoh None
|
||||||
|
fina
|
||||||
|
if !empty(s:tail())
|
||||||
|
sil! norm! zOzz
|
||||||
|
en
|
||||||
|
endt
|
||||||
|
endf
|
||||||
|
|
||||||
fu! s:writecache(read_cache, cache_file)
|
fu! s:writecache(read_cache, cache_file)
|
||||||
if !a:read_cache && ( ( g:ctrlp_newcache || !filereadable(a:cache_file) )
|
if !a:read_cache && ( ( g:ctrlp_newcache || !filereadable(a:cache_file) )
|
||||||
\ && s:caching || len(g:ctrlp_allfiles) > s:nocache_lim )
|
\ && s:caching || len(g:ctrlp_allfiles) > s:nocache_lim )
|
||||||
@ -1105,18 +1126,6 @@ fu! ctrlp#exit()
|
|||||||
cal s:PrtExit()
|
cal s:PrtExit()
|
||||||
endf
|
endf
|
||||||
|
|
||||||
fu! s:openfile(cmd)
|
|
||||||
try
|
|
||||||
exe a:cmd
|
|
||||||
cat /^Vim\%((\a\+)\)\=:E37/
|
|
||||||
exe substitute(a:cmd, '^e ', 'new ', '')
|
|
||||||
cat
|
|
||||||
echoh Identifier
|
|
||||||
echon "CtrlP: Operation can't be completed. Make sure filename is valid."
|
|
||||||
echoh None
|
|
||||||
endt
|
|
||||||
endf
|
|
||||||
|
|
||||||
fu! s:walker(max, pos, dir)
|
fu! s:walker(max, pos, dir)
|
||||||
retu a:dir > 0 ? a:pos < a:max ? a:pos + 1 : 0 : a:pos > 0 ? a:pos - 1 : a:max
|
retu a:dir > 0 ? a:pos < a:max ? a:pos + 1 : 0 : a:pos > 0 ? a:pos - 1 : a:max
|
||||||
endf
|
endf
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
*ctrlp.txt* Full path fuzzy file, buffer and MRU file finder. v1.5.8
|
*ctrlp.txt* Full path fuzzy file, buffer and MRU file finder. v1.5.9
|
||||||
*CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'*
|
*CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'*
|
||||||
===============================================================================
|
===============================================================================
|
||||||
# #
|
# #
|
||||||
@ -494,8 +494,13 @@ Mercurial repository: https://bitbucket.org/kien/ctrlp.vim
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
THANKS *ctrlp-thanks*
|
THANKS *ctrlp-thanks*
|
||||||
|
|
||||||
Thanks to everyone that has submitted ideas, bug reports, helped debugging or
|
Thanks to everyone that has submitted ideas, bug reports or helped debugging on
|
||||||
came up with solutions on gibhub, bitbucket, and through email.
|
gibhub, bitbucket, and through email.
|
||||||
|
|
||||||
|
Special thanks:
|
||||||
|
|
||||||
|
* Woojong Koh <github.com/wjkoh>
|
||||||
|
Forked and suggested the support for VCS listing commands.
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
CHANGELOG *ctrlp-changelog*
|
CHANGELOG *ctrlp-changelog*
|
||||||
|
@ -5,13 +5,13 @@ Full path fuzzy __file__, __buffer__ and __MRU__ file finder for Vim.
|
|||||||
* Full support for Vim’s regexp as search pattern.
|
* Full support for Vim’s regexp as search pattern.
|
||||||
* Built-in Most Recently Used (MRU) files monitoring.
|
* Built-in Most Recently Used (MRU) files monitoring.
|
||||||
* Built-in project’s root finder.
|
* Built-in project’s root finder.
|
||||||
* CtrlP is [extensible][3].
|
* [Extensible][3].
|
||||||
|
|
||||||
![ctrlp][1]
|
![ctrlp][1]
|
||||||
|
|
||||||
## Basic Usage
|
## Basic Usage
|
||||||
* Press `<c-p>` or run `:CtrlP` to invoke CtrlP in find file mode.
|
* Press `<c-p>` or run `:CtrlP` to invoke CtrlP in find file mode.
|
||||||
* Use `:CtrlPBuffer` and `:CtrlPMRU` for buffer and MRU mode.
|
* Or use `:CtrlPBuffer` and `:CtrlPMRU` for buffer and MRU mode.
|
||||||
|
|
||||||
Once CtrlP is open:
|
Once CtrlP is open:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user