4

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?

Mike Crowe
  • 201
  • 1
  • 6
  • 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. – Manuel Uberti Jan 26 '21 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 '21 at 14:14
  • 1
    See https://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")`](https://oremacs.com/swiper/#file-name-completion). – Basil Jan 26 '21 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 '21 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 '21 at 09:53
  • `ivy-insert-current-full` isn't a complete solution. If OP wanted to change `tree1` to `Tree1`, when they deleted the last `t` ivy would detect the `//`grouping and exit the edit mode. – lithp Mar 09 '22 at 14:04
  • @MikeCrowe Slightly related to that "concatenated onto the end of the original path" problem is if you have typed in initial text into the mini-buffer and then type `C-M-y`. See **Update 2022-09-15 08:59:22** inside my related answer here for how I dealt with that: https://emacs.stackexchange.com/a/70618/15483 – bgoodr Sep 15 '22 at 16:19

1 Answers1

6

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.

Mike Crowe
  • 201
  • 1
  • 6