add find buffers
This commit is contained in:
parent
b6f15390b8
commit
c51b7ecbfc
@ -111,39 +111,23 @@ func! s:GetDataFile(file)
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func! s:CacheDir()
|
func! s:CacheDir()
|
||||||
let cache_dir = exists('*mkdir') ? s:cache_dir.s:lash().'.ctrlp_cache' : s:cache_dir
|
retu exists('*mkdir') ? s:cache_dir.s:lash().'.ctrlp_cache' : s:cache_dir
|
||||||
retu cache_dir
|
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func! s:CacheFile()
|
func! s:CacheFile()
|
||||||
let cache_dir = s:CacheDir()
|
retu s:CacheDir().s:lash().substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').'.txt'
|
||||||
let cache_file = substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').'.txt'
|
|
||||||
retu cache_dir.s:lash().cache_file
|
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func! s:WriteCache(lines)
|
func! s:WriteCache(lines)
|
||||||
let cache_dir = s:CacheDir()
|
let cache_dir = s:CacheDir()
|
||||||
" create directory if not existed
|
" create directory if not existed
|
||||||
if exists('*mkdir') && !isdirectory(cache_dir)
|
if exists('*mkdir') && !isdirectory(cache_dir)
|
||||||
try
|
sil! cal mkdir(cache_dir)
|
||||||
cal mkdir(cache_dir)
|
|
||||||
catch
|
|
||||||
echoh Error
|
|
||||||
ec 'Can''t create caching directory'
|
|
||||||
echoh None
|
|
||||||
endtry
|
|
||||||
endif
|
endif
|
||||||
" write cache
|
" write cache
|
||||||
if isdirectory(cache_dir)
|
if isdirectory(cache_dir)
|
||||||
try
|
sil! cal writefile(a:lines, s:CacheFile())
|
||||||
cal writefile(a:lines, s:CacheFile())
|
|
||||||
catch
|
|
||||||
echoh Error
|
|
||||||
ec 'Can''t write cache file'
|
|
||||||
echoh None
|
|
||||||
finally
|
|
||||||
let g:ctrlp_newcache = 0
|
let g:ctrlp_newcache = 0
|
||||||
endtry
|
|
||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@ -203,6 +187,20 @@ func! s:ListAllFiles(path) "{{{
|
|||||||
retu allfiles
|
retu allfiles
|
||||||
endfunc "}}}
|
endfunc "}}}
|
||||||
|
|
||||||
|
func! s:ListAllBuffers() "{{{
|
||||||
|
let nbufs = bufnr('$')
|
||||||
|
let allbufs = []
|
||||||
|
for each in range(1, nbufs)
|
||||||
|
if getbufvar(each, '&bl')
|
||||||
|
let bufname = bufname(each)
|
||||||
|
if strlen(bufname) && getbufvar(each, '&ma') && bufname != 'ControlP'
|
||||||
|
cal add(allbufs, fnamemodify(bufname, ':p'))
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
retu allbufs
|
||||||
|
endfunc "}}}
|
||||||
|
|
||||||
func! s:SplitPattern(str,...) "{{{
|
func! s:SplitPattern(str,...) "{{{
|
||||||
" Split into a list, ignoring spaces
|
" Split into a list, ignoring spaces
|
||||||
if s:igspace
|
if s:igspace
|
||||||
@ -532,6 +530,7 @@ func! s:MapKeys(...)
|
|||||||
for each in range(32,126)
|
for each in range(32,126)
|
||||||
sil! exe "nn \<buffer> \<silent> \<char-".each."> :cal \<SID>".func."(\"".escape(nr2char(each), '"|\')."\"".sjbyfname.")\<cr>"
|
sil! exe "nn \<buffer> \<silent> \<char-".each."> :cal \<SID>".func."(\"".escape(nr2char(each), '"|\')."\"".sjbyfname.")\<cr>"
|
||||||
endfor
|
endfor
|
||||||
|
if exists('a:2') | retu | endif
|
||||||
" Special keystrokes
|
" Special keystrokes
|
||||||
if exists('a:1') && a:1 == 0
|
if exists('a:1') && a:1 == 0
|
||||||
sil! cal s:MapSpecs('unmap')
|
sil! cal s:MapSpecs('unmap')
|
||||||
@ -555,6 +554,7 @@ func! s:MapSpecs(...)
|
|||||||
\ 'ToggleFocus()': ['<tab>'],
|
\ 'ToggleFocus()': ['<tab>'],
|
||||||
\ 'ToggleRegex()': ['<c-r>'],
|
\ 'ToggleRegex()': ['<c-r>'],
|
||||||
\ 'ToggleByFname()': ['<c-d>'],
|
\ 'ToggleByFname()': ['<c-d>'],
|
||||||
|
\ 'ToggleType()': ['<c-f>'],
|
||||||
\ 'PrtCurStart()': ['<c-a>'],
|
\ 'PrtCurStart()': ['<c-a>'],
|
||||||
\ 'PrtCurEnd()': ['<c-e>'],
|
\ 'PrtCurEnd()': ['<c-e>'],
|
||||||
\ 'PrtCurLeft()': ['<c-h>', '<left>'],
|
\ 'PrtCurLeft()': ['<c-h>', '<left>'],
|
||||||
@ -598,7 +598,7 @@ func! s:ToggleFocus()
|
|||||||
endfunc
|
endfunc
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
"Todo: Cycle through matches. /high
|
"Mightdo: Cycle through matches. /high
|
||||||
func! s:SelectJump(char,...) "{{{
|
func! s:SelectJump(char,...) "{{{
|
||||||
let lines = map(b:matched, 'substitute(v:val, "^> ", "", "g")')
|
let lines = map(b:matched, 'substitute(v:val, "^> ", "", "g")')
|
||||||
if exists('a:1')
|
if exists('a:1')
|
||||||
@ -617,6 +617,13 @@ endfunc "}}}
|
|||||||
|
|
||||||
func! s:ToggleByFname() "{{{
|
func! s:ToggleByFname() "{{{
|
||||||
let s:byfname = s:byfname ? 0 : 1
|
let s:byfname = s:byfname ? 0 : 1
|
||||||
|
cal s:MapKeys(s:Focus(), 1)
|
||||||
|
cal s:BuildPrompt(s:Focus())
|
||||||
|
endfunc "}}}
|
||||||
|
|
||||||
|
func! s:ToggleType() "{{{
|
||||||
|
let s:itemtype = s:itemtype ? 0 : 1
|
||||||
|
cal s:SetLines(s:itemtype)
|
||||||
cal s:BuildPrompt(s:Focus())
|
cal s:BuildPrompt(s:Focus())
|
||||||
endfunc "}}}
|
endfunc "}}}
|
||||||
|
|
||||||
@ -673,7 +680,8 @@ endfunc
|
|||||||
func! s:AcceptSelection(mode) "{{{
|
func! s:AcceptSelection(mode) "{{{
|
||||||
let md = a:mode
|
let md = a:mode
|
||||||
let line = getline('.')
|
let line = getline('.')
|
||||||
let filepath = getcwd().s:lash().matchstr(line, '^> \zs.\+\ze\t*$')
|
let matchstr = matchstr(line, '^> \zs.\+\ze\t*$')
|
||||||
|
let filepath = s:itemtype ? matchstr : getcwd().s:lash().matchstr
|
||||||
let filename = split(filepath, s:lash())[-1]
|
let filename = split(filepath, s:lash())[-1]
|
||||||
" Remove the prompt and match window
|
" Remove the prompt and match window
|
||||||
sil! cal s:BufOpen('ControlP', 'del')
|
sil! cal s:BufOpen('ControlP', 'del')
|
||||||
@ -711,8 +719,7 @@ func! s:compare(s1, s2)
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func! s:matchsubstr(item, pat)
|
func! s:matchsubstr(item, pat)
|
||||||
let tail = split(a:item, '[\/]\ze[^\/]\+$')[-1]
|
retu match(split(a:item, '[\/]\ze[^\/]\+$')[-1], a:pat)
|
||||||
retu match(tail, a:pat)
|
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func! s:matchlists(item, lst)
|
func! s:matchlists(item, lst)
|
||||||
@ -734,16 +741,23 @@ func! s:Syntax()
|
|||||||
endfunc
|
endfunc
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
func! ctrlp#init() "{{{
|
" Initialization {{{
|
||||||
|
func! s:SetLines(type)
|
||||||
|
let s:itemtype = a:type
|
||||||
|
let s:lines = s:itemtype ? s:ListAllBuffers() : s:ListAllFiles(getcwd())
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func! ctrlp#init(type)
|
||||||
cal ctrlp#SetWorkingPath()
|
cal ctrlp#SetWorkingPath()
|
||||||
let s:lines = s:ListAllFiles(getcwd())
|
cal s:SetLines(a:type)
|
||||||
cal s:BufOpen('ControlP')
|
cal s:BufOpen('ControlP')
|
||||||
cal s:SetupBlank('ctrlp')
|
cal s:SetupBlank('ctrlp')
|
||||||
cal s:MapKeys()
|
cal s:MapKeys()
|
||||||
cal s:Renderer(s:lines)
|
cal s:Renderer(s:lines)
|
||||||
cal s:BuildPrompt()
|
cal s:BuildPrompt()
|
||||||
cal s:Syntax()
|
cal s:Syntax()
|
||||||
endfunc "}}}
|
endfunc
|
||||||
|
"}}}
|
||||||
|
|
||||||
aug CtrlPAug "{{{
|
aug CtrlPAug "{{{
|
||||||
au!
|
au!
|
||||||
|
@ -107,13 +107,13 @@ Set the parent directory for the '.ctrlp_cache' directory: >
|
|||||||
<
|
<
|
||||||
|
|
||||||
*'g:ctrlp_use_caching'*
|
*'g:ctrlp_use_caching'*
|
||||||
Set this to 1 to always enable caching. Caching is also temporarily enabled if
|
Set this to 1 to always enable caching (flat files). Caching’s also temporarily
|
||||||
the working directory has more than 4000 files: >
|
enabled if the working directory has more than 4000 files: >
|
||||||
let g:ctrlp_use_caching = 0
|
let g:ctrlp_use_caching = 0
|
||||||
<
|
<
|
||||||
|
|
||||||
*'g:ctrlp_by_filename'*
|
*'g:ctrlp_by_filename'*
|
||||||
Set this to 1 to set search by-file-name as the default: >
|
Set this to 1 to set search by file-name (not full path) as the default: >
|
||||||
let g:ctrlp_by_filename = 0
|
let g:ctrlp_by_filename = 0
|
||||||
<
|
<
|
||||||
|
|
||||||
@ -134,6 +134,7 @@ only need to keep the lines that you’ve changed the values (inside []): >
|
|||||||
\ 'ToggleFocus()': ['<tab>'],
|
\ 'ToggleFocus()': ['<tab>'],
|
||||||
\ 'ToggleRegex()': ['<c-r>'],
|
\ 'ToggleRegex()': ['<c-r>'],
|
||||||
\ 'ToggleByFname()': ['<c-d>'],
|
\ 'ToggleByFname()': ['<c-d>'],
|
||||||
|
\ 'ToggleType()': ['<c-f>'],
|
||||||
\ 'PrtCurStart()': ['<c-a>'],
|
\ 'PrtCurStart()': ['<c-a>'],
|
||||||
\ 'PrtCurEnd()': ['<c-e>'],
|
\ 'PrtCurEnd()': ['<c-e>'],
|
||||||
\ 'PrtCurLeft()': ['<c-h>', '<left>'],
|
\ 'PrtCurLeft()': ['<c-h>', '<left>'],
|
||||||
@ -147,7 +148,10 @@ only need to keep the lines that you’ve changed the values (inside []): >
|
|||||||
|
|
||||||
*:CtrlP*
|
*:CtrlP*
|
||||||
:CtrlP
|
:CtrlP
|
||||||
Open the |CtrlP| prompt.
|
Open the |CtrlP| prompt in find file mode.
|
||||||
|
*:CtrlPBuffer*
|
||||||
|
:CtrlPBuffer
|
||||||
|
Open the |CtrlP| prompt in find buffer mode.
|
||||||
|
|
||||||
*:ClearCtrlPCache*
|
*:ClearCtrlPCache*
|
||||||
:ClearCtrlPCache
|
:ClearCtrlPCache
|
||||||
@ -177,6 +181,9 @@ Once inside the prompt:
|
|||||||
Toggle between full path search and file name only search.
|
Toggle between full path search and file name only search.
|
||||||
(note: in file name mode, the prompt’s base is '>d>' instead of '>>>')
|
(note: in file name mode, the prompt’s base is '>d>' instead of '>>>')
|
||||||
|
|
||||||
|
<c-f>
|
||||||
|
Toggle between searching files and searching buffers.
|
||||||
|
|
||||||
<c-n>,
|
<c-n>,
|
||||||
<c-j>,
|
<c-j>,
|
||||||
<down>
|
<down>
|
||||||
@ -262,7 +269,6 @@ wrote a pure Vimscript version of their prompt window, intended to use it for
|
|||||||
the aforementioned plugin.
|
the aforementioned plugin.
|
||||||
|
|
||||||
Git repository: https://github.com/kien/ctrlp.vim
|
Git repository: https://github.com/kien/ctrlp.vim
|
||||||
Mercurial repository: https://bitbucket.org/kien/ctrlp.vim
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
vim:nofen:et:ts=2:sw=2:sts=2
|
vim:nofen:et:ts=2:sw=2:sts=2
|
||||||
|
@ -14,7 +14,8 @@ if !exists('g:ctrlp_map')
|
|||||||
let g:ctrlp_map = '<c-p>'
|
let g:ctrlp_map = '<c-p>'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
com! CtrlP cal ctrlp#init()
|
com! CtrlP cal ctrlp#init(0)
|
||||||
|
com! CtrlPBuffer cal ctrlp#init(1)
|
||||||
com! ClearCtrlPCache cal ctrlp#clearcache()
|
com! ClearCtrlPCache cal ctrlp#clearcache()
|
||||||
com! ClearAllCtrlPCaches cal ctrlp#clearallcaches()
|
com! ClearAllCtrlPCaches cal ctrlp#clearallcaches()
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ back to full path search.
|
|||||||
line in the selected file.
|
line in the selected file.
|
||||||
e.g. `abc:45` to open the file matched the pattern `abc` and jump to
|
e.g. `abc:45` to open the file matched the pattern `abc` and jump to
|
||||||
line 45.
|
line 45.
|
||||||
|
* Press `<c-f>` to switch to find buffer mode. Or run `:CtrlPBuffer`.
|
||||||
|
|
||||||
## Basic Options
|
## Basic Options
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user