Skip to content

Commit

Permalink
Extend the ability to jump to existing buffers
Browse files Browse the repository at this point in the history
Refs #268
  • Loading branch information
kien committed Sep 2, 2012
1 parent 44347fe commit 309d29d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
11 changes: 7 additions & 4 deletions autoload/ctrlp.vim
Expand Up @@ -61,7 +61,7 @@ let [s:pref, s:opts, s:new_opts] = ['g:ctrlp_', {
\ 'extensions': ['s:extensions', []], \ 'extensions': ['s:extensions', []],
\ 'follow_symlinks': ['s:folsym', 0], \ 'follow_symlinks': ['s:folsym', 0],
\ 'highlight_match': ['s:mathi', [1, 'CtrlPMatch']], \ 'highlight_match': ['s:mathi', [1, 'CtrlPMatch']],
\ 'jump_to_buffer': ['s:jmptobuf', 2], \ 'jump_to_buffer': ['s:jmptobuf', 'Et'],
\ 'lazy_update': ['s:lazy', 0], \ 'lazy_update': ['s:lazy', 0],
\ 'match_func': ['s:matcher', {}], \ 'match_func': ['s:matcher', {}],
\ 'match_window_bottom': ['s:mwbottom', 1], \ 'match_window_bottom': ['s:mwbottom', 1],
Expand Down Expand Up @@ -847,16 +847,19 @@ fu! ctrlp#acceptfile(mode, line, ...)
cal s:PrtExit() cal s:PrtExit()
let [bufnr, tail] = [bufnr('^'.filpath.'$'), s:tail()] let [bufnr, tail] = [bufnr('^'.filpath.'$'), s:tail()]
let j2l = a:0 ? a:1 : str2nr(matchstr(tail, '^ +\D*\zs\d\+\ze\D*')) let j2l = a:0 ? a:1 : str2nr(matchstr(tail, '^ +\D*\zs\d\+\ze\D*'))
if s:jmptobuf && bufnr > 0 && md =~ 'e\|t' if ( s:jmptobuf =~ md || ( s:jmptobuf && md =~ '[et]' ) ) && bufnr > 0
\ && !( md == 'e' && bufnr == bufnr('%') ) \ && !( md == 'e' && bufnr == bufnr('%') )
let [jmpb, bufwinnr] = [1, bufwinnr(bufnr)] let [jmpb, bufwinnr] = [1, bufwinnr(bufnr)]
let buftab = s:jmptobuf > 1 ? s:buftab(bufnr, md) : [0, 0] let buftab = ( s:jmptobuf =~# '[tTVH]' || s:jmptobuf > 1 )
\ ? s:buftab(bufnr, md) : [0, 0]
en en
" Switch to existing buffer or open new one " Switch to existing buffer or open new one
if exists('jmpb') && bufwinnr > 0 && md != 't' if exists('jmpb') && bufwinnr > 0
\ && !( md == 't' && ( s:jmptobuf !~# toupper(md) || buftab[0] ) )
exe bufwinnr.'winc w' exe bufwinnr.'winc w'
if j2l | cal ctrlp#j2l(j2l) | en if j2l | cal ctrlp#j2l(j2l) | en
elsei exists('jmpb') && buftab[0] elsei exists('jmpb') && buftab[0]
\ && !( md =~ '[evh]' && s:jmptobuf !~# toupper(md) )
exe 'tabn' buftab[0] exe 'tabn' buftab[0]
exe buftab[1].'winc w' exe buftab[1].'winc w'
if j2l | cal ctrlp#j2l(j2l) | en if j2l | cal ctrlp#j2l(j2l) | en
Expand Down
19 changes: 12 additions & 7 deletions doc/ctrlp.txt
Expand Up @@ -128,13 +128,16 @@ Set the maximum height of the match window: >
< <


*'g:ctrlp_switch_buffer'* *'g:ctrlp_switch_buffer'*
When opening a file with <cr> or <c-t>, if the file's already opened somewhere When opening a file, if it's already opened in a window somewhere CtrlP will
CtrlP will try to jump to it instead of opening a new instance: > try to jump to it instead of opening a new instance: >
let g:ctrlp_switch_buffer = 2 let g:ctrlp_switch_buffer = 'Et'
< <
1 - only jump to the buffer if it's opened in the current tab. e - jump when <cr> is pressed, but only to windows in the current tab.
2 - jump tab as well if the buffer's opened in another tab. t - jump when <c-t> is pressed, but only to windows in another tab.
0 - disable this feature. v - like e, but jump when <c-v> is pressed.
h - like e, but jump when <c-x> is pressed.
E, T, V, H - like e, t, v and h respectively, but jump to windows anywhere.
0 or <empty-string> - disable this feature.


*'g:ctrlp_reuse_window'* *'g:ctrlp_reuse_window'*
When opening a file with <cr>, CtrlP avoids opening it in windows created by When opening a file with <cr>, CtrlP avoids opening it in windows created by
Expand Down Expand Up @@ -165,7 +168,7 @@ variable: >
c - the directory of the current file. c - the directory of the current file.
r - the nearest ancestor that contains one of these directories or files: r - the nearest ancestor that contains one of these directories or files:
.git .hg .svn .bzr _darcs .git .hg .svn .bzr _darcs
0 or [empty-string] - don't manage working directory. 0 or <empty-string> - don't manage working directory.


Note #1: you can use b:ctrlp_working_path_mode (a |b:var|) to set this option Note #1: you can use b:ctrlp_working_path_mode (a |b:var|) to set this option
on a per buffer basis. on a per buffer basis.
Expand Down Expand Up @@ -1160,6 +1163,8 @@ Special thanks:~
=============================================================================== ===============================================================================
CHANGELOG *ctrlp-changelog* CHANGELOG *ctrlp-changelog*


+ Change |g:ctrlp_switch_buffer|'s and |g:ctrlp_working_path_mode|'s type
(old values still work).
+ New key for |g:ctrlp_user_command| when it's a Dictionary: 'ignore'. + New key for |g:ctrlp_user_command| when it's a Dictionary: 'ignore'.
+ New options: |g:ctrlp_open_func|. + New options: |g:ctrlp_open_func|.
|g:ctrlp_tabpage_position|. |g:ctrlp_tabpage_position|.
Expand Down

0 comments on commit 309d29d

Please sign in to comment.