Skip to content

Loading…

Tab drilling #513

Open
wants to merge 4 commits into from

4 participants

@jceb

This patch adds additional abilities to the tab key to expand directories based on the currently selected entry.
1. If the user didn't type anything, tab now expands the directory name of the selected entry. Before it didn't do anything
2. If the user typed something, tab now expands the directory one after the other while maintaining any other expansion that happened before

@kien
Owner

This looks great. But how does it interact with CtrlP's existing tab-completion? Also, since they are closely resemble, is merging them feasible?

@axelson

@kien how does CtrlP's existing tab-completion work? I don't see it listed in the documentation anywhere.

@kien
Owner

@axelson see :h ctrlp-autocompletion. You need to type something first.

@d11wtq d11wtq referenced this pull request in ctrlpvim/ctrlp.vim
Open

Tab drilling #7

@d11wtq

Moved to: ctrlpvim#7

@axelson

@kien thanks! I didn't realize that auto completion was only for directories and not for files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 11, 2014
  1. @jceb
  2. @jceb

    catch empty directories

    jceb committed
  3. @jceb

    further refine expansion

    jceb committed
Commits on Jan 18, 2014
  1. @jceb
Showing with 41 additions and 0 deletions.
  1. +41 −0 autoload/ctrlp.vim
View
41 autoload/ctrlp.vim
@@ -712,6 +712,17 @@ fu! s:PrtExpandDir()
let str = fnamemodify(s:fnesc(spc, 'g'), mdr).nmd
en
en
+ let str_tmp = str
+ if str == ''
+ let dir = s:headfirstntail(s:fnesc(ctrlp#getcline(), 'g'))
+ if len(dir) == 2 && dir[0] != '' && isdirectory(dir[0])
+ cal ctrlp#setdir(dir[0])
+ cal ctrlp#switchtype(0)
+ cal ctrlp#recordhist()
+ cal s:PrtClear()
+ return
+ en
+ en
if str == '' | retu | en
unl! s:hstgot
let s:act_add = 1
@@ -725,6 +736,29 @@ fu! s:PrtExpandDir()
elsei len(dirs) > 1
let str .= s:findcommon(dirs, str)
en
+ if str_tmp == str
+ let slash = s:lash()
+ let dir = s:headfirstntail(s:fnesc(ctrlp#getcline(), 'g'))
+ if len(dir) == 2 && dir[0] != '' && isdirectory(dir[0])
+ let exp = 1
+ while exp
+ if str[:len(dir[0])] != dir[0]
+ let exp = 0
+ en
+ let tmp = s:headfirstntail(dir[1])
+ if len(tmp) == 2 && dir[0] != ''
+ let dir = [dir[0].slash.tmp[0], tmp[1]]
+ el
+ break
+ en
+ endw
+ cal ctrlp#setdir(dir[0])
+ cal ctrlp#switchtype(0)
+ cal ctrlp#recordhist()
+ cal s:PrtClear()
+ return
+ en
+ en
let s:prompt[0] = exists('hasat') ? hasat[0].str : str
cal s:BuildPrompt(1)
unl s:act_add
@@ -1493,6 +1527,13 @@ fu! s:headntail(str)
retu len(parts) == 1 ? ['', parts[0]] : len(parts) == 2 ? parts : []
endf
+fu! s:headfirstntail(str)
+ " seems to be a bug in vim
+ " let parts = split(a:str, '^[^\/]\+\zs[\/]')
+ let parts = matchlist(a:str, '^\([^\/]\+\)\zs[\/]\(.*\)$')[1:2]
+ retu len(parts) == 1 ? ['', parts[0]] : len(parts) == 2 ? parts : []
+endf
+
fu! s:lash(...)
retu ( a:0 ? a:1 : s:dyncwd ) !~ '[\/]$' ? s:lash : ''
endf
Something went wrong with that request. Please try again.