emacs "Find File:" default path

Shishir Pandey picture Shishir Pandey · Jun 24, 2011 · Viewed 10.5k times · Source

I am using emacs on windows. I would like to know how to change the default "Find File:" path in emacs i.e. When we press "C-x C-f" I want the default file path to point to my Documents directory and not to "c:\emacs-**\bin/".

Answer

Thomas picture Thomas · Jun 24, 2011

In a buffer that is visiting a file, the default path you see when you visit a new file (C-x C-f) is the directory that contains the current buffer's file.

In order to override the value "c:\emacs-**\bin/" with something more sensible, set the default-directory variable in your .emacs file:

(setq default-directory "/path/to/documents/directory/")

Note that the path value should end with a slash (or backslash on Windows).

However, you might also want to consider changing the value of your HOME environment variable, as by default, this is what the variable default-directory points at at startup (unless set to some other value like shown above).