Where can I find my .emacs file for Emacs running on Windows?

89,076

Solution 1

Copy and pasted from the Emacs FAQ, http://www.gnu.org/software/emacs/windows/:

Where do I put my init file?

On Windows, the .emacs file may be called _emacs for backward compatibility with DOS and FAT filesystems where filenames could not start with a dot. Some users prefer to continue using such a name, because Windows Explorer cannot create a file with a name starting with a dot, even though the filesystem and most other programs can handle it. In Emacs 22 and later, the init file may also be called .emacs.d/init.el. Many of the other files that are created by Lisp packages are now stored in the .emacs.d directory too, so this keeps all your Emacs related files in one place.

All the files mentioned above should go in your HOME directory. The HOME directory is determined by following the steps below:

  1. If the environment variable HOME is set, use the directory it indicates.
  2. If the registry entry HKCU\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates.
  3. If the registry entry HKLM\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates. Not recommended, as it results in users sharing the same HOME directory.
  4. If C:\.emacs exists, then use C:/. This is for backward compatibility, as previous versions defaulted to C:/ if HOME was not set.
  5. Use the user's AppData directory, usually a directory called Application Data under the user's profile directory, the location of which varies according to Windows version and whether the computer is part of a domain.

Within Emacs, ~ at the beginning of a file name is expanded to your HOME directory, so you can always find your .emacs file with C-x C-f ~/.emacs.

There's further information at HOME and Startup Directories on MS-Windows.

Solution 2

It should be stored in the variable user-init-file. Use C-H v user-init-file RET to check. You can also open it directly by using M-x eval-expression RET (find-file user-init-file) RET

Solution 3

Open the file like this in Emacs for Windows:

C-x C-f ~/.emacs

More information in the Emacs Wiki

Solution 4

On my Vista box it's in C:\Users\<USER>\AppData\Roaming\

Solution 5

Note that it may NOT be enough to just type Ctrl-x Ctrl-f ~/.emacs and create the file.

It may be that your Emacs application uses a different place to store your init file, and if so, then creating the file ~/.emacs simply creates a useless file which your Emacs application ignores.

Also, you may want to do more than just access the .emacs init file, but you may want to know where it is, i.e., its pathname.

To get at this there are two methods:

Easy way: type Ctrl + H V user-init-file Return

Slightly trickier way: You can find out where your system is storing its own .emacs file by:

  1. Click options and scroll down to "Set Default Font..."
  2. Change the font setting and click okay
  3. On the options menu, go down to "Save Options"
  4. When the options are saved, the system saves its .emacs file, and you can read the file path in the minibuffer at the bottom of the Emacs screen
Share:
89,076
Ray
Author by

Ray

Writes code and likes it. A lot.

Updated on September 21, 2020

Comments

  • Ray
    Ray over 3 years

    I tried looking for the .emacs file for my Windows installation for Emacs, but I could not find it. Does it have the same filename under Windows as in Unix?

    Do I have to create it myself? If so, under what specific directory does it go?

  • remcycles
    remcycles over 13 years
    I've now noticed that Windows will set the HOME environment variable differently, depending on how I start runemacs.exe. If I start it from within the Explorer, HOME is set to C:\Documents and Settings\username, but if I start it from the Start Menu, HOME is C:\Documents and Settings\username\Application Data. Strange.
  • Yoo
    Yoo about 13 years
    And then click File > Open File... or Save As... to see where ~/ is in a familiar Windows Open dialog.
  • Chris
    Chris over 12 years
    Finally I found this! Thanks!
  • labyrinth
    labyrinth over 12 years
    Or you may need to find with C-x C-f ~/_emacs (instead of the period). Using the underscore for your init is common (and suggested) practice for both Vim and Emacs.
  • lowerkey
    lowerkey about 11 years
    Finally I found this! Me too!
  • Brian Z
    Brian Z over 10 years
    This is so helpful, I'm surprised it is not mentioned in the manual section on init files.
  • Bhavik Shah
    Bhavik Shah over 10 years
    Please refer the docs about formatting your answer. Its quite easy and will earn you more reputation.
  • Brian Z
    Brian Z about 9 years
    Emacs complains that "_emacs" is deprecated :(
  • kri
    kri almost 9 years
    Same for windows 8.1 (Emacs 24) with an exception. When Emacs is opened from Windows Explorer, a link or cmd console it uses C:\Users\<USER>\AppData\Roaming\.emacs profile file but if you open Emacs from PowerShell console, Emacs will look for .emacs file in C:\Users\<USER> folder.
  • Siniyas
    Siniyas over 8 years
    Thanks. This explanation actually helped me set up emacs properly following a clojure tutorial, where they didnt even mention this. Created the HOME variable on windows and now it works.
  • Marko Grdinić
    Marko Grdinić over 7 years
    I wonder why when I try this, I get trailing garbage following expression?
  • user8128167
    user8128167 over 7 years
    For me in reference to your point 5 above, the directory emacs is looking in for me is C:\Users\userid\AppData\Roaming on Windows 7 but of course my computer is on a domain.
  • Bae
    Bae over 7 years
    On Windows 10 I set the variable HOME to be %USERPROFILE% to avoid the AppData suffix.
  • Jose Romero
    Jose Romero about 7 years
    Did you use the parenthesis?
  • Peter Mortensen
    Peter Mortensen about 7 years
    By "set", do you mean creating that key (with no content)?
  • Retro Gamer
    Retro Gamer almost 6 years
    This worked for me. I created a .emacs file in the Roaming directory in AppData, and works like a charm! Windows 10.
  • PatS
    PatS over 5 years
    When I saved a file named ~/.emacs.el file, it was created in c:/Users/user1/AppData/Roaming/.emacs.el. This site emacswiki.org/emacs/DotEmacsDotD helped me realize I needed to name the file ~/.emacs.d/init.el which meant the file in the file system was at c:\Users\user1\AppData\Roaming\.emacs.d\init.el (not at all what I expected). I prefer setting the HOME environment variable and place the file in my %USERPROFILE% directory which is the logical HOME directory on windows (at least as far as I'm concerned).
  • Sebastiaan
    Sebastiaan over 5 years
    "Got to love how Windows works. (not)" -- This issue doesn't have anything to do with Windows other than this is what Emacs developers have done to people who run Emacs on Windows.
  • Alex Kaszynski
    Alex Kaszynski almost 5 years
    Worked in Windows 10