Recently there was a post on the Emacs Redux blog on this topic.
It is mainly implemented in Prelude (the same author), which you can install to get this behavior and many other interesting things. Otherwise, you can put in your configuration file only the corresponding fragment (taken from the blog post above):
(defun rename-file-and-buffer () "Rename the current buffer and file it is visiting." (interactive) (let ((filename (buffer-file-name))) (if (not (and filename (file-exists-p filename))) (message "Buffer is not visiting a file!") (let ((new-name (read-file-name "New name: " filename))) (cond ((vc-backend filename) (vc-rename-file filename new-name)) (t (rename-file filename new-name t) (set-visited-file-name new-name tt))))))) (global-set-key (kbd "Cc r") 'rename-file-and-buffer)
source share