I use ido-mode for finding files and directories, which is generally very efficient in terms of keystrokes.

The one annoyance I've found is when deleting the trailing pathname component when using ido-find-file. E.g., if the minibuffer contains /some/long/directory/path/and.some.long.file.name, I would like to quickly delete and.some.long.file.name with a single keystroke. It seems hard to believe that this isn't built-in, but if so I haven't found the keybinding for it.

Is there a quick way to erase the trailing file name, or another efficient way of dealing with this?

  • 2
    There probably is, and an Ido user will no doubt help you with a good answer. I tried looking in the Ido manual. It's a mess, IMHO. The index is pretty much useless. If I were an Ido user I would ask for an improvement. As an Emacs user, I at least filed a bug report just now suggesting that the index be improved. – Drew Oct 11 '14 at 20:28

I didn't find a built-in way to do that (well M-^ C-k seems to work, but that's a little bit hacky). That said, implementing it doesn't look too difficult. I believe the following would do:

(defun ido-clear-fname ()
  (setq ido-text-init ""
        ido-exit 'refresh)

(define-key ido-common-completion-map (kbd "<C-M-backspace>") 'ido-clear-fname)
  • This is pretty much exactly what I was hoping for, thank you! – user1968 Oct 14 '14 at 19:50

M-backspace (Alt+Backspace) is quite efficient. It'll kill whole words instead of single characters. It's perhaps not a single key solution in your case, but you can use it pretty much everywhere in Emacs or in shell.


I found in my .emacs the following function which does work as expected:

(defun kill-back-to-indentation ()
  "Kill from point back to the first non-whitespace character on the line."
  (let ((prev-pos (point)))
    (kill-region (point) prev-pos)))

(global-set-key (kbd "C-M-<backspace>") 'kill-back-to-indentation)

Yes, this function is not ido-specific but rather for general purposes.

  • 1
    You can also just use this as the function body: (kill-region (point) (progn (back-to-indentation) (point))). – Drew Oct 14 '14 at 3:14
  • Be warned that C-M-<backspace> may log you out of your Linux session with no warning. – nispio Oct 17 '14 at 0:54
  • @nispio which distros do you mean? – Andriy Tykhonov Oct 17 '14 at 9:39
  • I put the warning in because it happened to me, and took me totally by surprise. After a little research, it looks like Ctrl+Alt+BackSpace is often the default binding for "Kill X-Window Session." But since X is going away, newer distros may not have a similar binding. Just like all things Linux, YMMV. I am using GNOME desktop on RHEL 6.5, and that is the default setting. – nispio Oct 17 '14 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy