8

Can I disable ivy completion for a single command while in minibuffer?

For example I am in folder ~/code/study/ . If I open find file and autocomplete with Ivy I will see

Find file: ~/code/study/

./ 
../ 
[...]

and I want, in a single jump go to ~/other/code/study. Since I have ivy-mode to autocomplete I cannot move my cursor to the first / and just type other there. This is being a pain for some things. Can I somehow edit the first part of a completion or even disable completion temporarily just for this command?

Thanks a lot!

10

I think what you're looking for is C-M-j (ivy-immediate-done) in the mini buffer. This function is described as follows in the Ivy manual:

Exits with the current input instead of the current candidate (like other commands).

This is useful e.g. when you call find-file to create a new file, but the desired name matches an existing file. In that case, using C-j would select that existing file, which isn't what you want—use this command instead.

  • But how can I get my cursor to ~/<here>/code/study to edit and apply the immediate-done? – Rafa de Castro May 18 '17 at 7:26
  • I don't think you can with C-M-j, but it is one way of disabling completion. – tirocinium May 18 '17 at 12:58
5

There are multiple approaches to file navigation that apply here.

Just to rephrase your statement:

switch from ~/code/study to ~/other/code/study

  1. Easiest and most consistent: use ~ to switch to ~/ and navigate from there.
  2. Assume you visited ~/code/study once before in the current Emacs session. Press C-r to access all files you visited before. You can erase the file part with C-k.
  3. Assume you have ~/code/study as a bookmark or in recentf. Press M-o b to get completion for those.
  4. Assume you are in the dired buffer of ~/code/study. Press 0w to copy the current path. Press C-x C-f C-y: you can edit the yank in the minibuffer.

Edit: one more approach

With the most recent commit, you can press C-M-o w C-y to edit the full path in the minibuffer. If you use this a lot, counsel-find-file-map is available to bind this combination to something shorter.

1

You can edit the filename root during completion by typing DEL or <backspace>. Each such keypress switches to the parent directory.

See section File Name Completion of the Ivy User Manual for more information. In particular, you may be interested in the the special handling of slashes and tildes - entering two slashes during any part of the completion will change the directory to the root directory (/) and similarly a tilde will switch to your home directory.

See also customisable variable ivy-on-del-error-function.

  • If I do that I'd have "~/code/study" then backspace "~/code/" then "~" code. And I'd had to start again with Dropbox/code/study. I'd like to avoid that repeat of code/study. – Rafa de Castro May 18 '17 at 7:25
0

You can still get the default find-file behavior if you do

(defun default-find-file ()
  (interactive)
  (exit-minibuffer)
   (let  ((completing-read-function 'completing-read-default))
     (call-interactively 'find-file) ))

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.