≡

wincent.dev

  • Products
  • Blog
  • Wiki
  • Issues
You are viewing an historical archive of past issues. Please report new issues to the appropriate project issue tracker on GitHub.
Home » Issues » Feature request #1699

Feature request #1699: make the first directory where command-t is launched the product root

Kind feature request
Product Command-T
When Created 2010-09-23T02:27:43Z, updated 2010-09-25T16:54:59Z
Status closed
Reporter anonymous
Tags no tags

Description

Right now if I'm in a project directory and I use command-t to find a model it works great. If I'm viewing that model file and launch command-t to find the controller that goes with it, I'm out of luck. I first have to issue a cd .. command to vim to get back into my app directory.

Ideally, there's a way to set the project root similarly to textmate. I can't think of an elegant way to do this except perhaps having the root default to the directory where command-t is first issued and then flush that setting only by quitting vim or running :CommandTFlush

Comments

  1. Greg Hurrell 2010-09-23T06:00:54Z

    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 type mb (or just book), and to open the controller at app/controllers/books_controller.rb you could type either bookcon or conbook. For the specs you could type smb (for spec/models/book_spec.rb) and scbc (for spec/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.

  2. anonymous 2010-09-24T21:39:25Z

    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

  3. Greg Hurrell 2010-09-24T21:46:49Z

    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.

  4. Greg Hurrell 2010-09-24T21:47:14Z

    Status changed:

    • From: new
    • To: closed
  5. anonymous 2010-09-25T16:42:41Z

    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!

  6. Greg Hurrell 2010-09-25T16:54:59Z

    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.

  • contact
  • legal

Menu

  • Blog
  • Wiki
  • Issues
  • Snippets