Is there a function I can call that opens my init file for editing or returns its path?
See the variable
user-init-file described in section 38.1.2 The Init File of the Emacs Lisp manual.
Using this variable it is easy to build an interactive command that opens the init file:
(defun my-open-init-file () "Open the init file." (interactive) (find-file user-init-file))
One simple alternative would be to add a bookmark for your init file (
bookmark-set, bound to
C-x r m by default). Then you can use
C-x r b) to return to it.
Also, if you enable
recentf-mode and use either Helm, or Ido with the
ido-use-virtual-buffers mode, then switching to any recent file is as quick as
C-x b <filename>. After enabling this and setting
recentf-max-saved-items to a nice high value (1000), I practically never even think about whether a file is already open or not -- everything is accessible through a single key binding all the time.
This isn't so helpful if you use Emacs on multiple systems which put the init file in different places, or if you don't edit your
init.el frequently (but what kind of Emacs user would that be true of?!?)