16

I'm trying to make myself use Ido mode. Some times it's nice, but other times it is extremely stupid. Here's my greatest disappointment.

I read some log with full file names, then I copy one name, try open that file.

The way to do this without Ido: C-aC-yC-kRET

With Ido there are two major problems:

  1. If I have the entire file name, there's no way to input that (I must remove the first slash, else even pressing // will not help.

  2. I can't edit intermediate parts of the file name leaving the rest unmodified.

Or can I?

3
  • 2
    You can drop back to stock find-file with C-x C-f and paste in normally. But then, that's more keystrokes. Or you can use Helm if you want a feature rich find-file and still satisfy that use case of yours.
    – Tu Do
    Commented Dec 15, 2014 at 10:04
  • 1
    Ah, thanks, nah, I don't do this so often that I'd complain about two extra keystrokes. This would actually answer my needs for now. Thanks!
    – wvxvw
    Commented Dec 15, 2014 at 10:09
  • @Tu Do You should put that down as an answer below. I have found the C-x C-f fallback useful so many times! Commented Dec 15, 2014 at 10:50

4 Answers 4

19

While an ido command is active (ido-find-file in this case), you can drop back to the non-ido version of the same command (find-file in this case) using the ido-default binding C-x C-f for ido-fallback-command.

To answer you question,

  • The first C-x C-f will call ido-find-file.
  • The second C-x C-f will fall back to find-file.
  • Then you can do C-a C-y C-k RET as you usually do to yank a copied file path into the minibuffer.

Note: In ido, C-x C-f C-x C-f will do the same thing as C-x C-f C-f, i.e. fall back to find-file.

About C-f in ido In ido-mode, C-f is bound to ido-magic-forward-char. From ido.el,

(defun ido-magic-forward-char (arg)
  "Move forward in user input or perform magic action.
If no user input is present, or at end of input, perform magic actions:
C-x C-b ... C-f  switch to `ido-find-file'.
C-x C-f ... C-f  fallback to non-Ido `find-file'.
C-x C-d ... C-f  fallback to non-Ido brief `dired'.
C-x d ... C-f    fallback to non-Ido `dired'."
4
  • 2
    For me it's just C-f to get back to find-file, not C-x C-f. I don't see that I've customized it (and I, like others here rely on the fallback a lot. ido is almost as much trouble as it's worth, after using it for a while now).
    – harpo
    Commented Dec 15, 2014 at 16:12
  • 1
    @harpo I just updated the answer above explaining why C-x C-f C-f also works. Commented Dec 15, 2014 at 16:17
  • Thanks to @kaushalmodi for most of the work. My answer is initially simple like the comment. It should be his answer :) Just a note for credibility.
    – Tu Do
    Commented Dec 15, 2014 at 16:29
  • This saved my sanity, as ido does not play nicely with tramp when using absolute paths. Thank you.
    – Jérémie
    Commented Jan 17, 2018 at 9:15
6

Given you're dealing with full path names, other methods may work:

  • use M-x ffap (find-file-at-point): it will automatically read the path name and open the file
  • activate M-x compilation-shell-minor-mode which will change the font of paths and make them "clickable" (with mouth or RET). Clicking on it brings you to that file and the specific line, and you can use next-error and previous-error to navigate. I often use it, like in shell-mode.
5

Since there's always more than one way to do it, here's a variation on @abo-abo's idea that keeps ido completion active rather than falling back to the normal find command.

(defun ido-yank ()
  (interactive)
  (let ((path (current-kill 0)))
    (if (file-exists-p path)
        (progn
          (let ((dir (file-name-directory path)))
            (if dir (ido-set-current-directory dir)))
          (setq ido-exit 'refresh)
          (setq ido-text-init (if (file-directory-p path) nil (file-name-nondirectory path)))
          (setq ido-rotate-temp t)
          (exit-minibuffer))
      (yank))))

(define-key ido-file-dir-completion-map (kbd "C-y") 'ido-yank)

With this binding:

  • If the current kill is a valid directory path, you can start ido-find-file, hit C-y to jump to the yanked directory, and then continue to use ido completion to choose a file.

  • If the current kill is a valid file path, you can start ido-find-file, hit C-y to jump to the yanked directory and offer the yanked file name as the completion, and hit RET to open that file.

  • If the current kill is anything else it gets yanked normally.

3
  • Might it not be better to let-bind the various ido-... variables rather than setq them? Right now, it looks like you're permanently setting values rather than doing so for the life of the function.
    – Dan
    Commented Dec 15, 2014 at 16:03
  • @Dan I'm following the pattern of ido commands like ido-next-work-directory. I think the variables get set so that they survive across the exit-minibuffer call and the subsequent refresh. But I still don't fully grok the ido internals!
    – glucas
    Commented Dec 15, 2014 at 16:06
  • Yeah, I was wondering if they get subsequently refreshed anyway. Just wanted to put in a heads-up.
    – Dan
    Commented Dec 15, 2014 at 16:12
4

Maybe like this:

(define-key ido-file-dir-completion-map (kbd "C-y") 'ido-yank)
(defun ido-yank ()
  (interactive)
  (if (file-exists-p (current-kill 0))
      (ido-fallback-command)
    (yank)))

If the current kill is a file that exists, doing C-y C-y should probably give you what you want.

0

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.