Greg W.
Greg W.

Reputation: 33

Copying file in emacs using existing file name as a "base"

When in a Dired buffer, is it possible to copy an existing file to a new file using the existing files name as a "base" and then edit it to create a new file name? I know you cannot copy a file to a new file with the exact same name. What I have been doing is copying the old file name to a register, using Shift-C on the old file name, and then pasting and editing the new file name. I'm looking for a way to do this that allows me to skip the step of copying the old file name to a register.

Upvotes: 3

Views: 725

Answers (2)

Ashton Honnecke
Ashton Honnecke

Reputation: 717

I'm not sure what sort of setup this works with, but It's not mine.

For instance, if I'm trying to copy prepare-commit-msg.sample to prepare-commit-msg, emacs will autocomplete the partial filename when I hit enter from the following: enter image description here I then receive this message: enter image description here

The solution (for me, I'm not sure what all I've added to make it so) is, instead of "Enter", hitting C-M-j resulting in a new file that is the exact beginning of an already existing file: enter image description here

Upvotes: 0

Drew
Drew

Reputation: 30708

Just use C in Dired to copy the file of the current line to another file. At the prompt, use M-n to retrieve the existing file's name as the default, and edit it.

Throughout Emacs, M-n when you see a prompt retrieves the default value for your input. For file-name input in Dired, M-n typically retrieves the name of the file on the current line.

Upvotes: 3

Related Questions