The window that is displayed after GNU Emacs has started

Setting up GNU Emacs in Windows[edit | edit source]

Installation[edit | edit source]

1. Go to and download the latest zipped binary version of GNU Emacs (currently

2. Extract the folder inside of the archive to a directory with a path name without spaces.

3. In the Emacs folder, the program that you want to run is bin\runemacs.exe. Create a shortcut to it on the desktop or in the start menu if you feel like it.

4. Also add the address of the bin folder to the system path, since some of the programs in the bin folder can be run as shell commands and other programs which work together with emacs may have to be able to call them.

Setting up the variables[edit | edit source]

The variables that stores the settings you wish to use are stored in the elisp source file called .emacs (located in your home directory). You can either change them manually directly in the source file or you can edit them through GNU Emacs by clicking (in the menu) Options->Customize Emacs->Top-level Customization Group. If you choose to change them manually you may have to restart Emacs after modyfying the file for the changes to take effect.

Indentation[edit | edit source]

When programming in C/C++ you may want to adjust the width that the indentation has. Or maybe you want to indent with tabs instead of spaces. The variables you want to change in that case are

  • c-basic-offset: The width of the indentation when writing C/C++ files (I have it set to 4)
  • indent-tabs-mode: Emacs can replace multiple spaces in the indentation with tabs (as many spaces as the tab width becomes one tab). For using this option, indent-tabs-mode should be set to t (for true), otherwise nil (for false). If you do use the option, c-basic-offset should preferably be set to something that is a multiple of the tab width. Be aware of that using tabs with a different tab width than the default (8 spaces) may result in unwanted behaviour (such as code being misaligned) when displaying the code in other programs, for example web browsers.
  • tab-width: the width of tab in number of spaces (the default that most programs use is 8).

This can be changed by browsing for the appropriate options in Options->Customize Emacs->Top-level Customization Group, or by setting the variables in your .emacs file directly.

Other options[edit | edit source]

There are also some options you can change directly in the Options menu: You may want to activate Active Region Highlighting if you are not used to that the active region is not highlighted. If you are irritated by the blinking cursor there is an option for this too. If you want the scroll bar on the left side of the window you can change this by clicking Options->Show/Hide->Scroll-bar->On the Left.

File type association[edit | edit source]

In Windows Vista and later, it's not possible to associate file types with programs that are not located in certain standard program folders, such as the Program Files folder. To do a workaround on this problem, one can instead make a program that works as a middle hand, which with the file types are associated instead. The program, once started, opens Emacs, passing it the same arguments (except the first one which is the search path to the program) as it got itself. The program should be located in one of the standard program folders (for example Program Files), and to make it able to find Emacs, it is necessary that the address of the bin folder in the Emacs directory is added to the system path.

Getting started with GNU Emacs[edit | edit source]

Keyboard commands[edit | edit source]

There are a number of Emacs commands that it is good to know about. There are a number of good pages on the web listing many useful Emacs commands, and here are some of them:

Otherwise, the most common of the commands are listed in the table bellow (here, C = Control, and M = Meta (alt or escape in windows)):

Command What it will do
C-x C-f Find file (open/create file in, this will create a new buffer)
C-x C-s Save file
C-x s Save all buffers
M-w Copy
C-w Cut
C-y Yank (paste)
C-x u OR C-_ OR C-/ Undo (or redo)
C-space Start active region (start selection, if you want to remove selected text you have to cut it (C-w), or select it with the mouse and delete it)
C-x h Select the entire text (doesn't work in all operating systems)
C-s Search/search forward
C-r Search backward
tab Indent current line (indent every row in the active region in Windows)
tab in Windows
Indent every row in the active region (same as M-x indent-region)
C-x right/left arrow Switch between different buffers
C-x b Switch to buffer
C-x C-b Show buffer list
C-x k Kill buffer
C-x 0 Close window (if more than one is open)
C-x 1 Close all windows but the one the cursor is in
C-x 2 Split the window vertically
C-x 3 Split the window horizontally
C-x 5 2 Create new frame
M-x Go to the minibuffer (write command)
C-g Quit running/entered command (cancel)
C-x ( Start recording macro
C-x ) Finish recording macro
C-x e Run last recorded macro
M-n C-x e Run last recorded macro n times (useful for repeating something many times), where n is a positive integer
M-n In general: Do the following n times, where n is a positive integer
C-h v name Get description and value of a variable, where name is the name of the variable
M-: Evaluate single Lisp expression written in the minibuffer and print the result in the echo area
C-x C-e Evaluate the Lisp expression before where the cursor is and print the result in the echo area

Note that the keyboard commands differ notably from most other text editors; copy, paste and cut don't have the same commands, text can't be selected by holding down shift and moving the cursor and selected text isn't replaced if new text is entered or if text from the clip board is pasted. These are the differences that are the most notable, but one will get used to them after a while.

Minibuffer commands[edit | edit source]

There are also a number of useful minibuffer commands, which you enter in the minibuffer by first pressing M-x. Minibuffer commands are used in more special occasions, hence the longer names.

Command What it will do
recover-session Recover files being edited before crash
indent-region Indent every row in the active region
comment-box Make a box around the region which is commented (looks good when writing C files)
compile Display a standard line for you to edit in the minibuffer, which is then run as a shell command
describe-variable Get description and value of a variable (same as C-h v)
set-variable Set the value of a variable
eval-region Evaluate all Lisp expressions in the active region
eval-current-buffer Evaluate all Lisp expressions in the buffer

A list of commands that can be entered can also be shown by pressing tab when entering a command in the minibuffer.

Undoing[edit | edit source]


"Emacs' undo facility works slightly differently from that of other editors. In most editors, if you undo some changes, then make some new changes, the states formerly accessible with "redo" can no longer be recovered! So when using "undo" and "redo" extensively, one has to be very careful to avoid accidentally clobbering the redo list.

Emacs uses a different undo model which does not have this deficiency. After any consecutive sequence of undos, Emacs makes all your previous actions undoable, including the undos. (This will happen whenever a sequence of undos is broken by any other command.)

If this sounds complicated, just remember that "undo" is always capable of getting you back to any previous state your buffer was in (unless Emacs has run out of memory to store the undo history). The principle here is that Emacs makes it very difficult to accidentally lose your work."

Compiling[edit | edit source]

When compiling a project from Emacs, the best thing is to learn how to use a makefile, and write one.

When compiling, enter a buffer that contains a file which is in the same directory as the makefile (maybe the makefile it self’s buffer), and type M-x compile. A standard shell line will now be displayed in the minibuffer ("make -k"), which can be modified, and when return is pressed the content of the minibuffer is run as a shell command.

To use make, MSYS must be installed and set up properly, otherwise MinGW contains a program called mingw32-make.exe which works as make.exe. On the other hand, MSYS contains many programs which are common Linux shell commands, so it is good to have MSYS installed too. Then make.exe will call the compiler in question, for which you need to have MinGW installed and set up properly. You will need to have both MinGW's and MSYS' bin folders added to your system path.

External links[edit | edit source]

EmacsWiki, a whole wiki about Emacs

Community content is available under CC-BY-SA unless otherwise noted.