A few tweaks

* Fix `:CtrlP .` (thanks to @mattn)
* Enhance jump-to-open-buffer: jump to line number as well
* Close #39
This commit is contained in:
Kien N 2011-12-13 21:42:57 +07:00
parent c90a61f36d
commit 9bff726dd6
6 changed files with 99 additions and 24 deletions

View File

@ -1,8 +1,8 @@
" =============================================================================
" File: autoload/ctrlp.vim
" Description: Fuzzy file, buffer and MRU file finder.
" Description: Fuzzy file, buffer, mru and tag finder.
" Author: Kien Nguyen <github.com/kien>
" Version: 1.6.3
" Version: 1.6.4
" =============================================================================
" Static variables {{{1
@ -39,7 +39,6 @@ fu! s:opts()
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1])
endfo
if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en
" Note: wildignore is ignored when using **
let s:glob = s:dotfiles ? '.*\|*' : '*'
let s:maxdepth = min([s:maxdepth, 100])
let g:ctrlp_builtins = 2
@ -642,11 +641,11 @@ fu! s:PrtSwitcher()
endf
fu! s:SetWD(...) "{{{1
let pathmode = s:pathmode
if exists('a:1') && len(a:1) == 1 && !type(a:1)
let pathmode = a:1
elsei exists('a:1') && len(a:1) >= 1 && type(a:1)
if exists('a:1') && len(a:1) | if type(a:1)
cal ctrlp#setdir(a:1) | retu
en
el
let pathmode = a:1
en | en
if !exists('a:2')
if match(s:crfile, '^\<.\+\>://.*') >= 0 || !pathmode | retu | en
if exists('+acd') | let [s:glb_acd, &acd] = [&acd, 0] | en
@ -664,7 +663,7 @@ fu! s:SetWD(...) "{{{1
unl! s:foundroot
endf
" * AcceptSelection() {{{1
fu! ctrlp#acceptfile(mode, matchstr)
fu! ctrlp#acceptfile(mode, matchstr, ...)
let [md, matchstr] = [a:mode, a:matchstr]
" Get the full path
let filpath = s:itemtype ? matchstr : getcwd().s:lash.matchstr
@ -673,20 +672,23 @@ fu! ctrlp#acceptfile(mode, matchstr)
if s:jmptobuf && bufnum > 0 && md == 'e'
let [jmpb, bufwinnr] = [1, bufwinnr(bufnum)]
let buftab = s:jmptobuf > 1 ? s:buftab(bufnum) : [0, 0]
let j2l = a:0 ? a:1 : str2nr(matchstr(s:tail(), '^ +\zs\d\+$'))
en
" Switch to existing buffer or open new one
if exists('jmpb') && buftab[0]
exe 'tabn' buftab[1]
exe buftab[0].'winc w'
if j2l | cal s:j2l(j2l) | en
elsei exists('jmpb') && bufwinnr > 0
exe bufwinnr.'winc w'
if j2l | cal s:j2l(j2l) | en
el
" Determine the command to use
let cmd = md == 't' || s:splitwin == 1 ? 'tabe'
\ : md == 'h' || s:splitwin == 2 ? 'new'
\ : md == 'v' || s:splitwin == 3 ? 'vne' : ctrlp#normcmd('e')
" Open new window/buffer
cal s:openfile(cmd, filpath)
cal call('s:openfile', a:0 ? [cmd, filpath, ' +'.a:1] : [cmd, filpath])
en
endf
@ -1173,9 +1175,9 @@ fu! ctrlp#msg(msg)
echoh Identifier | echon "CtrlP: ".a:msg | echoh None
endf
fu! s:openfile(cmd, filpath)
fu! s:openfile(cmd, filpath, ...)
let cmd = a:cmd == 'e' && &modified ? 'hid e' : a:cmd
let tail = s:tail()
let tail = a:0 ? a:1 : s:tail()
try
exe cmd.tail.' '.ctrlp#fnesc(a:filpath)
cat
@ -1195,6 +1197,11 @@ fu! s:writecache(read_cache, cache_file)
en
endf
fu! s:j2l(nr)
exe a:nr
sil! norm! zOzz
endf
fu! s:regexfilter(str)
let str = a:str
let pats = {

View File

@ -1,6 +1,6 @@
" =============================================================================
" File: autoload/ctrlp/dir.vim
" Description: Directory switcher extension
" Description: Directory extension
" Author: Kien Nguyen <github.com/kien>
" =============================================================================

61
autoload/ctrlp/line.vim Normal file
View File

@ -0,0 +1,61 @@
" =============================================================================
" File: autoload/ctrlp/line.vim
" Description: Line extension - find a line in any buffer.
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" Init {{{1
if exists('g:loaded_ctrlp_line') && g:loaded_ctrlp_line
fini
en
let g:loaded_ctrlp_line = 1
let s:line_var = ['ctrlp#line#init()', 'ctrlp#line#accept', 'lines', 'line']
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:line_var) : [s:line_var]
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Public {{{1
fu! ctrlp#line#init()
let [bufs, lines] = [[], []]
for each in range(1, bufnr('$'))
if getbufvar(each, '&bl')
let bufname = bufname(each)
if strlen(bufname) && bufname != 'ControlP'
cal add(bufs, fnamemodify(bufname, ':p'))
en
en
endfo
cal filter(bufs, 'filereadable(v:val)')
for each in bufs
let from_file = readfile(each)
cal map(from_file, 'tr(v:val, '' '', '' '')')
let [id, len_ff, bufnr] = [1, len(from_file), bufnr(each)]
wh id <= len_ff
let from_file[id-1] .= ' #:'.bufnr.':'.id
let id += 1
endw
cal filter(from_file, 'v:val !~ ''^\s*\t#:\d\+:\d\+$''')
cal extend(lines, from_file)
endfo
sy match CtrlPTabExtra '\zs\t.*\ze$'
hi link CtrlPTabExtra Comment
retu lines
endf
fu! ctrlp#line#accept(mode, str)
let info = get(split(a:str, '\t#:\ze\d\+:\d\+$'), 1, 0)
let bufnr = str2nr(get(split(info, ':'), 0, 0))
let linenr = get(split(info, ':'), 1, 0)
if bufnr
cal ctrlp#acceptfile(a:mode, fnamemodify(bufname(bufnr), ':p'), linenr)
en
endf
fu! ctrlp#line#id()
retu s:id
endf
"}}}
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2

View File

@ -54,8 +54,8 @@ fu! ctrlp#tag#init(tagfiles)
let alltags = ctrlp#utils#readfile(each)
cal extend(g:ctrlp_alltags, alltags)
endfo
sy match CtrlPTagFilename '\zs\t.*\ze$'
hi link CtrlPTagFilename Comment
sy match CtrlPTabExtra '\zs\t.*\ze$'
hi link CtrlPTabExtra Comment
retu g:ctrlp_alltags
endf
@ -64,13 +64,13 @@ fu! ctrlp#tag#accept(mode, str)
let str = matchstr(a:str, '^[^\t]\+\t\+[^\t]\+\ze\t')
let [md, tg] = [a:mode, split(str, '^[^\t]\+\zs\t')[0]]
let fnd = s:findcount(str)
if fnd[0] == 1
let cmd = md == 't' ? 'tabe' : md == 'h' ? 'new'
\ : md == 'v' ? 'vne' : 'ene'
el
let cmd = md == 't' ? 'tab stj' : md == 'h' ? 'stj'
\ : md == 'v' ? 'vert stj' : 'tj'
en
let cmds = {
\ 't': ['tabe', 'tab stj'],
\ 'h': ['new', 'stj'],
\ 'v': ['vne', 'vert stj'],
\ 'e': ['ene', 'tj'],
\ }
let cmd = fnd[0] == 1 ? cmds[md][0] : cmds[md][1]
let cmd = cmd =~ 'tj\|ene' && &modified ? 'hid '.cmd : cmd
try
if fnd[0] == 1

View File

@ -1,4 +1,4 @@
*ctrlp.txt* Fuzzy file, buffer and MRU file finder. v1.6.3
*ctrlp.txt* Fuzzy file, buffer, mru and tag finder. v1.6.4
*CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'*
===============================================================================
# #
@ -151,6 +151,13 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
\ }
<
If you have problem with <bs> moving left instead of deleting a char, add this
to your |vimrc|: >
let g:ctrlp_prompt_mappings = {
\ 'PrtBS()': ['<c-h>'],
\ 'PrtCurLeft()': ['<left>'],
\ }
<
*'g:ctrlp_mruf_max'*
Specify the number of recently opened files you want |CtrlP| to remember: >
@ -445,7 +452,7 @@ Once inside the prompt:~
<c-g>
Exit |CtrlP|. <c-c> can also be used to stop the file scan.
Chose your own mappings with |g:ctrlp_prompt_mappings|.
Choose your own mappings with |g:ctrlp_prompt_mappings|.
When inside the match window (press <tab> to switch):~

View File

@ -1,6 +1,6 @@
" =============================================================================
" File: plugin/ctrlp.vim
" Description: Fuzzy file, buffer and MRU file finder.
" Description: Fuzzy file, buffer, mru and tag finder.
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" GetLatestVimScripts: 3736 1 :AutoInstall: ctrlp.zip