If I use C-xC-w (write-file)
to write the current buffer's content to a new location, then afterwards my buffer will be visiting the new file instead of the original one. Sometimes I would like to save off a copy of the buffer to a new location, but then keep editing at the original location.
I know I can kill the existing filename from the (write-file)
minibuffer history, and then yank that back at the C-xC-f (find-file)
prompt immediately afterwards to re-visit the original file, and this is the work-around I use at the moment. However, this feels inelegant.
I had wondered if (write-file)
might take a prefix argument of some kind to not visit the buffer, but this only appears to affect overwrite confirmation.
So: Is there any simpler way to save my buffer content to a file without altering which file I'm visiting?
1) Saving Files in Emacs Emacs allows you to save the contents to the current buffers by hitting the keys Ctrl + x followed by Ctrl + s. Users can also save the current buffer to some other file name by hitting the keys Ctrl + x, followed by Ctrl + w.
To save the file you are editing, type C-x C-s or select Save Buffer from the Files menu. Emacs writes the file. To let you know that the file was saved correctly, it puts the message Wrote filename in the minibuffer.
When you want to leave Emacs for a short time, type a C-z and Emacs will be suspended. To get back into Emacs, type %emacs at the shell prompt. To quit Emacs permanently, type C-x C-c.
When you have entered the file name, press the return key, and emacs will load the file into a buffer, and display it in the text window. The command to save the contents of the buffer to a disk file is Control-X-Control-S. The save command overwrites the old version of the file.
Select the entire buffer with C-xh, then use M-xwrite-region
.
If you do this regularly enough that it's getting annoying for you, you could define this function
(defun write-file-copy (filename) (interactive "F") (write-region (point-min) (point-max) filename))
and bind it to something that makes sense to you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With