Say I have a project directory called "project". In the directory there are two directories "mini1" and "mini2". Suppose my active buffer is deep within a subdirectory in "mini1". Is there a way to make a C-f like binding where the pre-existing directory text is /project/mini2/ and not the deeply nested directory under mini1 that I'm in?

  • 2
    I'm a fan of projectile for working with projects. Might be worth a look.
    – Ryan
    Jan 9 '20 at 1:01
  • You can check out Ivy—you hit C-x f and then if you hit DEL 2 / you should have mini2/ selected just how the autocomplete works. Jan 9 '20 at 2:55
  • And, of course, you can always make a macro/function to do that for a specific directory. Jan 9 '20 at 2:55
  • The question is too vague. How do you expect to communicate the desired target directory to your command?
    – Drew
    Jan 9 '20 at 17:14

Use find-directory-in-project-by-selected from https://github.com/technomancy/find-file-in-project

I also wrote a prototype in pure Lisp. It does not use any third party command line program or package,

(require 'find-lisp)
(require 'dired)
(require 'ido)

(defun my-open-dir-in-project ()
  "Open directory in project."
  (let* ((root (locate-dominating-file default-directory ".git"))
         (input-regex (read-string "Input regex (or press ENTER): "))
         (ignored-regex ".*/\\.git\\|.*/\\.svn\\|.*/\\.bzr")
         (find-lisp-regexp (if (string= input-regex "") ".*" input-regex))
         (cands (find-lisp-find-files-internal

    (when cands
      (setq cands
            (delq nil
                  (mapcar `(lambda (c)
                             (unless (string-match-p ,ignored-regex c) c))

      (setq selected (and cands
                          ;; `ido-completing-read' could be replaced with `ivy-read'
                          (ido-completing-read (format "directories %s: " root)
    (when selected
      (switch-to-buffer (dired selected)))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.