How do I re-open a file in emacs?
Solution 1:
I use M-x find-alternate-file
which is by default bound to C-x C-v
.
This command allows to reload a file onto the current buffer, reloading the same file include - which is shown in the mini-buffer by default. This is however not as convenient if you have ido-mode enabled for buffer-switching as it will not display the current file name by default.
Solution 2:
Are you sure you don't want to just revert the buffer?
M-x revert-buffer RET
Solution 3:
You can do C-x C-f M-n RET
. The behavior was changed because C-x C-f RET
to reopen a file wasn't nearly as common as C-x C-f DEL RET
to invoke Dired on the directory.
You can also use M-x revert-buffer
to reload a file from disk, and Emacs will tell you (on most operating systems) if you try to edit a file whose copy on disk has been modified externally.
C-x C-f M-n
is also useful to obtain the full path to the file in the minibuffer, so you can open a file with a similar name or copy it to the kill ring or clipboard.
Solution 4:
I found a useful suggestion to go back to the previous behaviour of C-x C-f RET
on help-gnu-emacs mailing list:
This hack was posted by Ted Stern:
(defun find-file-read-args (prompt mustmatch)
(list (let ((find-file-default
(and buffer-file-name
(abbreviate-file-name buffer-file-name))))
(read-file-name prompt nil find-file-default mustmatch))
t))
I tried it out and it works well for me on emacs 23.1.1.