Xah Lee, 2008-06
This page gives some tips on setting up emacs so it uses standard interface in modern applications. For example, Ctrl+c is copy, Ctrl+v is paste, Ctrl+o is open file, show tabs for opened files, have redo, line numbering, etc.
If you are on a Mac, you can download Aquamacs at http://aquamacs.org/, which has complete modern UI using Apple's user interface standards.
If you are on Windows, download EmacsW32 to start: http://www.ourcomments.org/Emacs/EmacsW32.html. It changes emacs so the user interface is similar to most applications on Microsoft Windows.
See also “Easymacs” by P J Heslin 2005. Easymacs is a collection of elisp packages with a coherent install instruction, so that after installing them on a standard emacs, it makes emacs's UI behave like a modern text editor. http://www.dur.ac.uk/p.j.heslin/Software/Emacs/Easymacs/index.php. (emacs wiki page: http://www.emacswiki.org/cgi-bin/wiki/Easymacs )
The following guide assume you are using emacs version 22, released in 2007.
How to have standard keys for Copy and Paste?
In emacs, turn on the CUA Mode, using menu “Options‣C-x/C-c/C-v Cut and Paste (CUA)”, then use menu “Options‣Save Options”.
The CUA mode will achieve 4 things: (1) Cut/Copy/Paste has shortcuts with x/c/v keys; (2) Text selection will be highlighted; (3) Typing while a region is selected will delete/over-ride it. (4) Text selection can be done by holding down the Shift key and press a arrow key.
Or, use the package provided at: A Ergonomic Keyboard Shortcut Layout For Emacs.
How to have standard shortcut keys like “Ctrl+o” for Open, “Ctrl+w” for Close, and “Ctrl+s” for Save, “Ctrl+a” for Select All?
Use the package provided at: A Ergonomic Keyboard Shortcut Layout For Emacs.
How to have redo?
You need to install the redo mode, available at: http://www.wonderworks.com/download/redo.el. For some discussion, see: http://www.emacswiki.org/cgi-bin/wiki/RedoMode. Once you install it, you can set the following keys:
(global-set-key (kbd "C-z") 'undo) ; undo (global-set-key (kbd "C-S-z") 'redo) ; redo
How to have text selection highlighted?
Put this code in your “.emacs”:
(transient-mark-mode t) ; turn on selection highlighting
Note: CUA mode automatically turns on transient-mark-mode.
How to have syntax coloring on by default?
Starting with emacs 22 (released in 2007), syntax coloring is on by default. If you are using a emacs 21, pull menu “Options‣Syntax Highlighting” then “Options‣Save Options”. Alternatively, put the following code in your “.emacs” file:
(global-font-lock-mode t) ; turn on syntax coloring
How to have typing overwrite selected text?
Put this code in your “.emacs”:
(delete-selection-mode 1) ; make delete or typing delete whole selected text
Note: CUA mode automatically turns on delete-selection-mode.
How to have matching parenthesis highlighted?
Use the menu “Options‣Paren Match Highlighting” then “Options‣Save Options”. The equivalent elisp code is this:
(show-paren-mode t) ; turn on paren match highlighting
show-paren-mode can be setup so that it highlight the entire paren enclosed text. For how to, see: Tips For Editing Lisp Code With Emacs.
How to have emacs display line numbers?
“Alt+x line-number-mode”. The line the cursor is on will be shown in the info bar at the bottom. To always have it on, place the following in your emacs customization file:
(defun my-turn-on-line-number-mode () (line-number-mode 1)) (add-hook 'text-mode-hook 'my-turn-on-line-number-mode)
How to show the cursor's column position?
“Alt+x column-number-mode”. To always have it on, put the following code in your “.emacs”.
(column-number-mode t)
How to have emacs show tabs for opened files?
You need to install tabbar-mode (2003) by David Ponce, see: http://www.emacswiki.org/cgi-bin/wiki/TabBarMode.
The tabbar mode.
The default color for background tabs are dim'd and difficult to read. To change it like the screenshot above, type “Alt+x customize-group” then “tabbar”. Then, scroll to “Tabbar Selected Face”, press Show Face, give the background a value of “bisque”. Do the same for “Tabbar Default Face” and give the Foreground value of “blue”. When done, click “Save for Future Sessions” at the top then close the buffer.
By default, the tabbar mode group buffers into categories, so the current set of tabs shown are buffers having the same mode as the current buffer. To have it show all user buffers as tabs, put the following code in your “.emacs”:
(defun my-tabbar-buffer-groups (buffer) "Return the list of group names BUFFER belongs to. This function is a custom function for tabbar-mode's tabbar-buffer-groups. This function group all buffers into 2 groups: Those user buffer, and those emacs buffer. Emacs buffer are those starting with “*”." (with-current-buffer (get-buffer buffer) (if (string-equal "*" (substring (buffer-name) 0 1)) '("emacs-buffer") '("user-buffer")))) (setq tabbar-buffer-groups-function 'my-tabbar-buffer-groups) (global-set-key (kbd "C-S-<tab>") 'tabbar-backward) (global-set-key (kbd "C-<tab>") 'tabbar-forward)
How to make emacs stop creating those “backup~” files all over the place?
Put the following in your “.emacs”.
(setq make-backup-files nil)
How to have a list of recently opened files?
You need to turn on the recentf mode. Put the following in your “.emacs”:
(recentf-mode 1)
Once turned on, you can open recently opened files under “File‣Open Recent”, or by typing “Alt+x recentf-open-files”.
How to set up emacs so that each file opens in a new window?
Put this code in your “.emacs”:
(setq pop-up-frames t)
How to have the down arrow key move a line on screen? (as opposed to the line by new line return)
Use this code:
(longlines-mode 1)
Note: As of emacs 22, longline-mode is buggy. If you have custome lisp code that insert text, or using cvs or other modes that manipulate large chuncks of text, longlines-mode will screwup your code. I recommond not to use it when you are editing code.
For alternatives, see http://www.emacswiki.org/cgi-bin/wiki/MoveByVisibleLineCommands.