Emacs for Dummies

Jan 19, 2003 1:36 PM
Tags: emacs, howto
Some people want to learn about every last capability of emacs. Others just want to edit and then save the damn file. This is for you ...

Emacs for dummies:

To open a file, use the filename as a command-line argument: emacs foo.txt

To make any changes to that file, just type as if you were in any other editor or word processor.

To save that file, hit CONTROL-X, then CONTROL-S.

To exit emacs and go back to the command line, hit CONTROL-X, then CONTROL-C.

The "panic button" is CONTROL-G. You can hit that combination at any time to escape back to the regular editing mode.

That's all you *need* to know about the very unintuitive, but very powerful editor.

If you want to learn more, you can read many of the websites or books. If you want to learn from the built-in tutorial, then do this:
  • Launch emacs.
  • Type ALT-X. This will move your cursor to the bottom of the editor.
  • Type help-with-tutorial and then press ENTER.
(This mini-guide was inspired by the sight of a coworker hitting ESC CTRL-Q get-me-out-of-here because I set VISUAL=EMACS for a Linux account we both use.
Comments: Emacs for Dummies

EXACTLY what I was looking for.
Thanks.

Posted by: Marcus on November 7, 2003 12:49 PM | permalink

All I want to know is how to disappear the message buffer since it takes up half the window. My current method for doing this is to kill Emacs and restart it. I would also like to make code completion smarter. I might have found cperl-mode sooner if that option had appeared when I typed in 'perl'

Posted by: on August 31, 2007 7:32 PM | permalink

1) CTRL-X and then 1 will make your current window (not "buffer" -- that's something else) take up the whole frame. (CTRL-X and then O will switch which window you are currently in; you may wish to do this first.)

2) Do ALT-X and then type apropos-RETURN-perl. You will see lots of info about things perl-related.

Posted by: Joe Grossberg on August 31, 2007 9:51 PM | permalink

A few more necessities:

1) Search: M-SHIFT-Dash. C-s through each match.
2) Replace: M-SHIFT-%. 'y' to replace match, 'n' to go to next, '!' to replace all.
3) Go to beginning/end of buffer: M-SHIFT-
4) Goto line: M-g-g
5) Open new file buffer ("tab" for Emacs-newbies): C-x f
6) Auto-comment (love this one): M-;
7) Switch buffers: C-x left/right arrow

These are the commands I use every day in emacs when programming...

Posted by: ohxten on February 18, 2008 11:31 AM | permalink

Great tips! They work for me, except #1; it says M-_ is undefined. I just use CTRL-S instead.

Posted by: Joe Grossberg on February 18, 2008 1:29 PM | permalink

Yes, my mistake. #1 should simply be C-s.

C-SHIFT-Dash will undo the last operation. :)

Posted by: ohxten on February 18, 2008 5:51 PM | permalink

FUCK THIS STUPID SHIT! Just kidding, good article but I think emacs is quickly fading. Modern editors have the same great customizability but with better, more user friendly, interfaces.

Posted by: Jake Davidson on February 19, 2008 10:10 PM | permalink

Jake:

emacs and vi are forever! (Just kidding.)

That said, I'm not looking for a shallow learning curve and a beautiful UI; I'm looking for efficiency, customizability, a large community, something open-source, cross-platform use and lots of third-party tools.

Textmate, though gorgeous, only really succeeds on the first count and flat-out fails by being Mac-only and unfree (in both senses).

Posted by: Joe Grossberg on February 20, 2008 9:17 AM | permalink

I'm also a great fan of Emacs. Plus you get the bonus of learning a great language (Lisp). Here are a few more i use quite often:
zap-to-char: Alt-z
redo last command (with optional modification): C-x Alt Alt
do a command n times: C-u n or Alt n <command>
Auto-indent code: C-Alt-\
Auto-complete (based on buffers contents): Alt-/
search with regexp: C-Alt-s
replace with regexp: C-Alt-%
Alt-x igrep-find: grep for something in directories (requires igrep.el)

and then of course there's CVS, dired, snippets (a la textmate), ECB, JDEE, mmm mode for files with more than one mode (html + php for ex), CPerl, etc etc etc

for people coming from windows it might be usefull to do:
(delete-selection-mode)
(pc-selection-mode)

and

;; Redefine the Home/End keys to (nearly) the same as visual studio behaviour
;; special home and end by Shan-leung Maverick WOO
(global-set-key [home] 'My-smart-home)
(global-set-key [end] 'My-smart-end)
(defun My-smart-home ()
"Odd home to beginning of line, even home to beginning of text/code."
(interactive)
(if (and (eq last-command 'My-smart-home)
(/= (line-beginning-position) (point)))
(beginning-of-line)
(beginning-of-line-text))
)
(defun My-smart-end ()
"Odd end to end of line, even end to begin of text/code."
(interactive)
(if (and (eq last-command 'My-smart-end)
(= (line-end-position) (point)))
(end-of-line-text)
(end-of-line))
)
(defun end-of-line-text ()
"Move to end of current line and skip comments and trailing space.
Require `font-lock'."
(interactive)
(end-of-line)
(let ((bol (line-beginning-position)))
(unless (eq font-lock-comment-face (get-text-property bol 'face))
(while (and (/= bol (point))
(eq font-lock-comment-face
(get-text-property (point) 'face)))
(backward-char 1))
(unless (= (point) bol)
(forward-char 1) (skip-chars-backward " \t\n"))))
)


and last but not least a great screencast showing some great stuff:

http://platypope.org/yada/emacs-demo/

Posted by: David on February 21, 2008 6:49 PM | permalink

No more comments! Either someone has violated Godwin's Law, I'm tired of the discussion or, most likely, the ten-week window has closed. You can, however, contact me through email.