1

I work on projects with deep directory structures and have several copies in different top-level directories. I sometimes find myself wanting to open the corresponding file in one of the other directories.

For example, I might have ~/tree1/a/deep/directory/structure/file.txt open and want to open ~/tree2/a/deep/directory/structure/file.txt. When I press C-x C-f counsel-find-file I'm unable to move my cursor back to the 1 to change it to a 2 - I need to use backspace to delete each path component which I'll need to re-enter (with completion to help me) afterwards. This is a pain for long path names.

Something I used previously (perhaps ido or helm, but I can't seem to find it now) let me press C-x C-f again whilst in the minibuffer to go back to stock find-file, which was sufficient to solve this problem.

I've read the ivy documentation, but I've been unable to find a way to edit the start of the filename with counsel-find-file. Is there something I've missed?

5
  • You can try setting enable-recursive-minibuffers to t, but IIRC another C-x C-f will start afresh, without picking up the path you've already written. Jan 26 at 11:07
  • In that case I'd be better off running stock find-file instead in these cases only. Unfortunately even that doesn't work - I seem to end up with counsel-find-file even when I explicitly type M-x find-file. :(
    – Mike Crowe
    Jan 26 at 14:14
  • 1
    See github.com/abo-abo/swiper/issues/883 and friends. The workaround provided is C-M-y (ivy-insert-current-full), which yanks the current directory for editing. See (info "(ivy) File Name Completion").
    – Basil
    Jan 26 at 19:51
  • 1
    @MikeCrowe If you invoke M-x find-file RET, and it looks like counsel-find-file, then it's probably because you've enabled ivy-mode, which enables Ivy-style file name completion even without using counsel-find-file.
    – Basil
    Jan 26 at 19:52
  • It looks like ivy-insert-current-full works, even it the appearance is a bit confusing with the editable path concatenated onto the end of the original path until I hit tab to complete. Thanks!
    – Mike Crowe
    Jan 31 at 9:53
2

Press C-M-y (ivy-insert-current-full) to yank the current directory on to the end of the current path. This can then be edited as usual and then hitting tab goes back to normal ivy completion.

Thanks to Basil for providing this in the comments to the question.

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.