User interface in Emacs allowing one to “grab” the buffer’s filename conveniently

copy/pasteemacsfilenames

It happens quite often that I want to use the path of the file opened in a certain buffer in Emacs (either the full path or the basename) in another place (a buffer or a different X program, say, a terminal). I wonder whether there is some pre-defined subsystem in the Emacs "user interface" that would copy the filename of the current buffer ((buffer-file-name)) to the kill-ring.

Related things: There is a simple command in emacs-w3m that does an analoguos thing (yw3m-print-current-url): it prints the URL and copies it to the kill-ring.

Of course, I could simply define the command I want, but I'm asking this question because I hope to learn some user interface subsystem of Emacs that includes such a possibility among other features. (Perhaps, some buffer and path manipulation interfaces.) So that I will know more useful features of Emacs.

Best Answer

I do this:

  1. C-x C-v (find-alternate-file)
  2. C-a (move-beginning-of-line)
  3. C-k (kill-line)
  4. C-g (keyboard-quit)

It's quicker than using the minibuffer history. If all you want is the base name, it's even faster - just skip the C-a in the second step.

Related Question