Comments
-
Greg Hurrell
The right way to do this is to use
:cd path/to/project/root
when you start working in your project.If for some reason you ever want to "scope" Command-T to a particular subdirectory, you can do so by explicitly bringing up Command-T with
:CommandT path/to/subdirectory
, but a better habit to get into is just to include some characters from the upper levels of the path in your search query:eg. from the top of a project root to open the model at
app/models/book.rb
you might just typemb
(or justbook
), and to open the controller atapp/controllers/books_controller.rb
you could type eitherbookcon
orconbook
. For the specs you could typesmb
(forspec/models/book_spec.rb
) andscbc
(forspec/controllers/books_controller_spec.rb
).Those are just examples and the actual quantity of characters you'll have to enter to narrow down your search depends on the number of files in your project, but hopefully you get the idea.
-
anonymous
The first thing I do is :cd path/to/project/root
then I type <leader>-t to bring up command-t and select a file from path/to/project/root/app/models/
the next time I type <leader>-t I am stuck in path/to/project/root/app/models rather than in path/to/project/root
here are the keystrokes exactly after launching vim:
:cd Sites/foo (enter project directory)
<leader>-t (bring up command-t)
book.rb (bring up the book.rb file)
<leader>-t (bring up command-t)
bookcon (trying to find the controller, but command-t only shows me the model file since that's the file I am editing in the forefront)
explicitly bringing up Command-T with :CommandT ~/Sites/foo does work but that's a lot of keystrokes compared to just <leader>-t
Here's a screenshot: http://imgur.com/2wKxs In it you'll see that selecting <leader>-t has scoped only to other controllers. So we have a disconnect here because I definitely can't follow your example without adding a cd.. in between
-
Greg Hurrell
Sounds like you've got
'autochdir'
turned on. It defaults to 'off', so you must have turned it on yourself.See
:h 'autochdir'
for more info. -
Greg Hurrell
Status changed:
- From: new
- To: closed
-
anonymous
It wasn't autochdir but I did have a line in my vimrc that was the culprit. Thanks so much for helping me solve it; donation on the way!
-
Greg Hurrell
Yeah, only earlier today I saw someone recommending this kind of thing:
" Auto change the directory to the current file I'm working on autocmd BufEnter * lcd %:p:h
Which I don't think is a very good idea at all. Things like this are a much better alternative for the kind of problem he's trying to tackle:
" edit file, starting in same directory as current file map <leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
Thanks for the donation.
Add a comment
Comments are now closed for this issue.