2

Is it possible to disable ivy-mode for file prompts?

In a past I used find-file to copy current file name or path to file.

dired-do-rename also is broken by Ivy: no default completion for current file + editing key binding extremely altered / navigation disabled...

3
  • That sounds like two questions, and the second sounds a bit like a bug report for Ivy. Also: what do you mean by using find-file to copy the current file name, and how does Ivy prevent doing that?
    – Drew
    Commented Nov 12, 2018 at 0:40
  • find-file is useful for copying file name of current buffer. On UP key default completion brings current buffer file name. Then you can select it.
    – gavenkoa
    Commented Nov 12, 2018 at 0:43
  • OK, please consider adding that description to the question, to make this clear.
    – Drew
    Commented Nov 12, 2018 at 0:47

2 Answers 2

2

Ivy-mode changes the value of completing-read-function. This function is used internally by read-file-name-default which is used for file name completion. The function used for file name completion can be changed using the variable read-file-name-function. By dynamically binding completing-read-function back to the default before calling read-file-name-default you will get what you want:

(setq read-file-name-function
  (lambda (&rest args)
    (let ((completing-read-function #'completing-read-default))
      (apply #'read-file-name-default args))))

Note that if you use counsel-mode, you have to undo the rebinding it does for find-file:

(define-key counsel-mode-map [remap find-file] nil)
1

Ivy supports multiple actions for the selected candidate. You can add your own actions, but by default there is a copy action that may be exactly what you need.

With the default key bindings, you can use M-o in the minibuffer to bring up the ivy action menu, and w to copy the currently selected candidate.

EDIT

I see this does not quite address your use case, since the current file name is not the default candidate for find-file when ivy is enabled. I always used to use find-alternate-file (C-x C-v) as a quick way to grab the current file name, and this works fine with ivy using M-o w as noted above. (Now I just have a separate key binding to copy buffer-file-name directly.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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