This page collects some answers to questions asked on community channels.
Either get CVS GNU Emacs (a.k.a. Emacs 22) or XEmacs 21. For new users, the differences between XEmacs and GNU Emacs are negligible. Except where explicitly stated, this article applies equally to both.
To install CVS GNU Emacs on
To install XEmacs 21 on
If you work on embedded systems (e.g. routers) that don’t have a few dozen megabytes needed for GNU Emacs or XEmacs, check out QEmacs, Zile and mg.
Emacs has a built-in tutorial that covers the most basic commands, such as moving around within a buffer. Please take a few minutes to go through it, if you haven’t already. You can access the tutorial by holding Control, pressing h, releasing Control, and pressing t.
Please also familiarize yourself with the following commands. You can answer many basic questions without help using these.
|C-h t||Start the tutorial.|
|C-h i m emacs RET||Read the EmacsManual.|
|C-h m, C-h b||Describe the current major mode.|
|M-x customize group RET foo RET||Configure handling of .foo files.|
|C-h c, C-h k||What does this key do?|
|C-h f||What does this function do?|
|C-h v||What does this variable do?|
|C-h a||Search for commands by regexp.|
|M-x customize apropos||Search for options by regexp.|
|M-:||Prompt for expression.|
|M-x load-file RET ~/.emacs RET||Reload .emacs without restarting.|
(setq inhibit-startup-message t)
There are a number of ways to change Emacs’ font. The easiest is to start Emacs with the -fn option:
emacs -fn fixed
Where “fixed” is your favourite font. X11 users can use the xlsfonts, xfontsel and xfd programs to examine different fonts.
A small selection of fonts can be chosen from a menu by holding shift and pressing the left mouse button in the main text area. You can also set the default font using M-x customize face RET default RET. You can set the current frame’s font using M-x set default font RET.
X11 users can also use X resources by adding a line of the form
to their .Xdefaults file, and running
xrdb -merge ~/.Xdefaults
each time they start X.
Recommended fonts are Terminus, Schumacher Clean and GNU Unifont.
For interactively setting the font with Emacs,
M-x customize-face RET default
Or for a the most difficult method
And for Lisp to put in your .emacs
;; Set font size to 11pt (let ((11pt (round (* 11.1 10)))) (set-face-attribute 'default (not 'this-frame-only) :height 11pt))
;; Set font to Dejavu sans mono (set-face-attribute 'default (not 'this-frame-only) :font "DejaVu Sans Mono")
Windows users check ChangeFontsPermanentlyOnWindows.
By default, Emacs uses a font called “default”. This should be a system-wide alias for some sensible default font. Ubuntu, particularly, has no such alias. Consequently, Emacs displays boxes instead of characters.
You can fix this by changing the font Emacs uses (see previous question), or by using antialiased fonts (see next question). Possibly you can also fix this by adding a default alias to the font subsystem; I don’t know how to do that.
Use emacs version 23.1
Old versions of Emacs have syntax highlighting off by default. To enable it, do M-x customize option RET global font lock mode RET.
Further, under the gui or X-based window, find where it says Options at the top and within this menu select and depress the “Syntax Highlighting (Global Font Lock mode)” option. Finally, look further down under this same Options menu and select “Save Options”.
The fastest way to change the foreground and background is to start emacs thusly:
emacs -fg white -bg black
‘black’ are your favourite colours. You can also set the default colours using M-x customize face RET default RET.
X11 users can use X resources to set the default colours by adding lines of the form
Emacs*background: black Emacs*foreground: white
to their .Xdefaults file, and running
xrdb -merge ~/.Xdefaults
each time they start X.
Open the file and run the following command:
C-x RET f
Select the coding you want and save the file.
C-\ It will switch the input method to latin-1-prefix. Typing ‘ followed by e will give é. To see all the possible combinations right click on the 1> at the bottom left on the mode line.
There are many other input modes, to list them all run
M-x list-input-methods. To use a different input method you need to customize the variable
default-input-method. For example if you wanted to use Japanese you would add the following in your
(setq default-input-method "japanese")
Write the following in your
(setq-default tab-width 4)
See http://www.ibb.net/~anne/keyboard.html for the full story.
In many modes the TAB key does not insert a literal tab character, but instead indents the current line. If the current line is already indented correctly, pressing TAB will have no effect. To insert a literal tab, type C-q TAB or C-q C-i. Please note that TabsAreEvil. If you disagree with what Emacs thinks is correct indentation, you can customize it, see e.g. IndentingC
You may also be interested in the following (where N is an integer):
C-u N C-x TAB C-u N C-M-\ C-a C-x r t C-u N SPC RET
You probably need to set the metaSendsEscape resource to “true”. Follow the instructions given in the section “How do I change Emacs’ default font?”, substituting “XTerm*metaSendsEscape: true” where it says “Emacs.Font: fixed”. Then restart Xterm.
Do M-: window-system RET. If emacs prints
‘x’, this fix should work. Do M-x customize option RET x select enable clipboard RET. To find out why this is necessary, see http://www.jwz.org/doc/x-cut-and-paste.html
M-x align in most mode will do something useful. If it doesn’t work try M-x align-regexp
M-x customize option RET line number mode RET and M-x customize option RET column number mode RET.
By default, Emacs wraps long lines at the last character (whereas e.g. notepad wraps at the last word) unless you have split the screen.
Most likely, you are editing a DOS file and the DOS line-endings are being displayed by emacs. You should run the dos2unix command before editing the file, or upgrade to a more recent version of emacs.
You can’t use \n or \t when entering a regexp interactively (when using C-M% - query-replace-regexp for instance). Simply type <TAB> or C-i to enter a tab (instead of \t) or C-q C-j to enter a newline (C-q quote C-j newline, instead of \n)
C-o in regexp replacement string inserts a newline without moving the cursor. So
C-o C-f has the same effect as
C-q C-j. This trick does not work with incremental search commands.
To execute a single shell command, use one of the following:
|M-!||Execute a shell command.|
|M-1 M-!||Execute a shell command and paste stdout.|
|M-|||Execute a shell command with selection as stdin.|
|M-1 M-|||Execute a shell command with selection as stdin and paste stdout.|
|M-x compile||Like M-!, but highlights compiler messages.|
To get an interactive shell, use one of the following:
|M-x shell||Start an interactive shell.|
|M-x eshell||A hybrid of M-x shell and M-x ielm.|
|M-x term, M-x ansi term||Start an interactive terminal.|
To get an interactive REPL (a.k.a. listener), use M-x run foo RET or M-x comint run RET foo RET, where
‘foo’ is your favourite programming language.
Use M-x ansi color for comint mode on RET if you see output like this:
M-x customize option RET c default style RET.
M-x customize option RET c basic offset RET.
Use the LineNumbers package. Note that uses a selected region the way vi uses line numbers, so this is not very useful.
The C-x z key is similar to vi’s . command.
Try M-^ and M-SPC.
Just do `C-x C-f ~/.emacs RET’ in Emacs. Emacs will find it, or create it if it doesn’t already exist. You can prove this by adding
(insert "It worked!")
to the bottom of the file, saving (C-x C-s), and restarting Emacs. If the file is being loaded, “It worked!” will be printed in the
XEmacs by default uses a different configuration file ~/.xemacs/init.el (and ~/.xemacs/custom.el); a ~/.emacs is generally provided for compatibility. You can follow the instructions above with the changed file names; e.g., C-x C-f ~/.xemacs/init.el RET
window-system stores the name of the windowing system being used to display the current frame.
Its value is, for instance,
x for X11, or
nil for a text-only terminal.
You can’t. When emacsclient creates a new X frame, it just tells the Emacs server to create a new X frame, so if the server is on a remote host, and you’re not using SSH X forwarding, you’re not going to get a frame on your display. If you can not or do not want to use X forwarding, then you will have to use emacsclient in a terminal.
Most likely because they can not be entered in a terminal. For example,
C-M-S-f is equivalent to
C-M-f in a terminal, because shift can not be used as a modifier for control characters. Why? Because ‘f’ and ‘F’ are separate characters, but there is only one control-F character,
^F; control characters are case-less. Modifiers also can’t be applied to the cursor keys, and there are no control chatacters for the cursor keys.
ELisp is Emacs Lisp, a dialect of Lisp that Emacs uses. It is a powerful language which you can use to add extra functionality to emacs.
If you would like to expand your knowledge of programming, or add powerful code to emacs, it is a good idea. But that is really up to you.
Consult the ElispCookbook for helpful recipes.