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.
Copying file in emacs using existing file name as a "base"
448 Views Asked by Greg W. At
2
There are 2 best solutions below
0
On
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:
I then receive this message:

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:

Just use
Cin Dired to copy the file of the current line to another file. At the prompt, useM-nto retrieve the existing file's name as the default, and edit it.Throughout Emacs,
M-nwhen you see a prompt retrieves the default value for your input. For file-name input in Dired,M-ntypically retrieves the name of the file on the current line.