Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say for instance I'm editing a config file and I want to type in a path. Is there a plugin for emacs that lets you complete a file path in that buffer? I've searched for this and there's like a bazillion completion plugins out there.

share|improve this question
I'm not clear on what you area asking here. Modern emacen have path completion in the mini-buffer (when using find-file for instance). Do you want a similar behavior in a content buffer? – dmckee Nov 7 '09 at 16:18
@dmckee - Yes, that's actually exactly what I'm looking for. – Jason Baker Nov 8 '09 at 13:58
@dmckee Is this OS specific? I had file name completion in Find File in ubuntu but there is no completion in OSX. For instance I have a file called "reference" in root and I am in mini buffer: "Find file: ~/" and I enter "ref" and I expect completion but nothing happens. Do I need to install something? – Zeynel Dec 9 '13 at 0:12
@Zeynel Works fine for me in Mac OS, too. Either with the Apple installed version or the homebrew version. Also worked with the fink version on my older machine. – dmckee Dec 9 '13 at 0:17
@dmckee Strange. Maybe I ask a new question. Thanks. – Zeynel Dec 9 '13 at 0:30
up vote 9 down vote accepted

Try Hippie Expand, which as one of it's possibilities has 'try-complete-file-name. You can change the order and list of expansion functions hippie expand will use to favor expanding the file name.

Or, you could even write a custom wrapper that would only do the file name expansion. Something like:

(global-set-key (kbd "C-M-/") 'my-expand-file-name-at-point)
(defun my-expand-file-name-at-point ()
  "Use hippie-expand to expand the filename"
  (let ((hippie-expand-try-functions-list '(try-complete-file-name-partially try-complete-file-name)))
    (call-interactively 'hippie-expand)))
share|improve this answer

I usually type Ctrl-X Ctrl-F like I would open a file, but instead of pressing RET I press Ctrl-A Ctrl-K Ctrl-G to copy the path and then paste it into the buffer I was editing with Ctrl-Y.

I don't need this often enough, but if I really wanted a better solution, I would definitely use Trey Jackson's solution using hippie-expand. I thought about how hippie-expand might be a better way to do this when first answering, but I didn't know and was too lazy to look it up, so I just wrote what I do.

share|improve this answer
Clunky and inelegant, but working. I have to admit to doing this from time to time myself. I'm still interested in a neater solution, though... – dmckee Nov 7 '09 at 21:56
Indeed. It doesn't really seem like a lot less work than typing it out manually though. – Jason Baker Nov 8 '09 at 14:00
@Jason Baker: It depends on whether you know the exact file name or if you need to explore a bit for it. – Teddy Nov 11 '09 at 16:44

The vanilla, out-of-the-box

M-x comint-dynamic-complete-filename

works outside of comint mode. Of course, you can use the minibuffer's dynamic expansion to use less keystrokes to get to it (e.g., M-x comint-dynamic-complete-filename). Or, if you will be using it frequently, you can bind it to a key sequence of your choice using global-set-key .

share|improve this answer

I recently discovered the works of Tomohiro Matsuyama (@m2ym) and I have been very impressed by the quality of its emacs packages.

I have struggled with most auto-completion extensions and found out that they all have major shortcomings.

Check out Tomo's auto-complete ( it has been a breeze to install (I'm on Linux) and covers many auto-completion needs in a modern fashion.

Of course, your request for in-buffer file names completion is perfectly covered.

Finally, if you happen to do Ruby too, make sure not to miss his RSense extension; again, the best of its kind.

share|improve this answer
The link is broken – xuhdev Apr 20 '15 at 7:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .