Comments
-
anonymous
I also place my vote for a feature like this. Or if by using :CommandT then after when writing .. it searches from the $HOME directory or the top root volume.
-
Greg Hurrell
Yeah true, although I wouldn't actually encourage people to use it to search their entire $HOME directory or anything bigger than that. The philosophy is more "project-centric", with the goal being fast navigation within a well-structured set of files which you know well. Once you start getting into the really high numbers of files the "fuzzy" matching strategy starts to become less and less usable because you simply get an unmanageably large number of matches.
-
Michael Henry
I'd be interested in this feature as well, since I tend to keep Vim's working directory fixed at the top of my project, but I often find it useful to browse another directory tree outside the current project. With the ability to specify the root of the tree to search, I can more easily browse down another project tree without having to ":cd ../elsewhere" and then "cd ../backhere". Combined with Vim's command-line history, I could imagine typing ":Com<Up>" to scroll through some recent launches of Command-t, which would help me keep my focus on the current project but be able to quickly pull up files from a related project.
-
Greg Hurrell
It's a reasonable enough request, but I haven't had the time to implement it just yet seeing as it's not something I imagine myself using very much.
But I have an idea of how to implement it, so it shouldn't be too hard. The basic idea is the following:
The way it currently works is to check the
:pwd
every time you bring it up, and if it's changed since the last time you showed the prompt then it scans/re-scans the current directory.The difference, then, would be do pass in 1 of 4 things:
-
usually
:pwd
, which would be standard when no optional path is passed in -
when a path starting with
/
is passed in, use that -
when a path starting with
~/
is passed in, expand the~
and pass that in -
when anything else is passed, just append it to whatever
:pwd
is (ie. this would work for paths likefoo/bar
,./foo
and../../bar
)
The only minor detail is to gracefully handle the case where a user types in an invalid path.
Ah, and when the user actually makes a selection, would have to translate the path accordingly too. The convenient thing about the current set-up is that all paths are expressed relative to the
:pwd
, so that means if:pwd
is~/foo
and the user choosesbar/baz
, then you just tell VIM to openbar/baz
and it works because that's relative to the:pwd
.Under the new system, you'd have to convert things to an absolute or relative path and use that; eg:
- when no param, no translation
- when param, append chosen path to starting directory
-
usually
-
Greg Hurrell
Ok, here's the change I'm considering applying:
diff --git a/plugin/command-t.vim b/plugin/command-t.vim index 3e5a1f7..0ec9983 100644 --- a/plugin/command-t.vim +++ b/plugin/command-t.vim @@ -27,8 +27,8 @@ if exists("g:command_t_loaded") endif let g:command_t_loaded = 1 -command CommandT :call <SID>CommandTShow() -command CommandTFlush :call <SID>CommandTFlush() +command -nargs=? -complete=dir CommandT call <SID>CommandTShow(<q-args>) +command CommandTFlush call <SID>CommandTFlush() silent! nmap <unique> <silent> <Leader>t :CommandT<CR> @@ -39,7 +39,7 @@ function s:CommandTRubyWarning() echohl none endfunction -function s:CommandTShow() +function s:CommandTShow(arg) if has('ruby') ruby $command_t.show else diff --git a/ruby/command-t/controller.rb b/ruby/command-t/controller.rb index c004eae..6fe76cd 100644 --- a/ruby/command-t/controller.rb +++ b/ruby/command-t/controller.rb @@ -34,7 +34,9 @@ module CommandT end def show - @finder.path = VIM::pwd + # optional parameter will be desired starting directory, or "" + @path = File.expand_path(VIM::evaluate('a:arg'), VIM::pwd) + @finder.path = @path @initial_window = $curwin @initial_buffer = $curbuf @match_window = MatchWindow.new \ @@ -179,6 +181,7 @@ module CommandT def open_selection selection, options = {} command = options[:command] || default_open_command + selection = File.expand_path selection, @path selection = sanitize_path_string selection VIM::command "silent #{command} #{selection}" end
Turned out to be simpler than I thought it would.
Seems to work in my brief testing run. The only case which it doesn't seem to handle correctly is:
:CommandT /
(First character gets chopped off.)
But it does handle cases like:
:CommandT /private/etc :CommandT ~ :CommandT ~/Library :CommandT ruby :CommandT ruby/ :CommandT ./ruby :CommandT .. :CommandT ../src
-
Greg Hurrell
And here's the fix for the
/
case:diff --git a/ruby/command-t/scanner.rb b/ruby/command-t/scanner.rb index fa613a2..a48d070 100644 --- a/ruby/command-t/scanner.rb +++ b/ruby/command-t/scanner.rb @@ -40,7 +40,7 @@ module CommandT @paths = [] @depth = 0 @files = 0 - @prefix_len = @path.length + @prefix_len = @path.chomp('/').length add_paths_for_directory @path, @paths rescue FileLimitExceeded end
Will test these privately for a while and push them out for inclusion in the next release.
-
Greg Hurrell
Ok, I've now tested this on Windows too and I've added in graceful handling of bad (non-existent) path arguments, so I'm going to push out a 0.6 release shortly. Will mark this as closed.
-
Greg Hurrell
Status changed:
- From: new
- To: closed
-
Michael Henry
Wincent,
Thanks - it's working nicely :-)
Michael Henry
Add a comment
Comments are now closed for this issue.