» about » content » twitter » github »

Emacs Jump-Start


I created this document as a quick reference. There are many other references out there, and emacs gives you a lot of help itself, but I find this useful from time-to-time so I made it available to anyone who's interested.

basic commands

exit emacs = c-x c-c  

open file : c-x c-f (for new file, enter non-existant name, for directory enter .) (to open a file via ftp see tips'n'tricks below)

save file : c-x c-s

close file : c-x k (enter name or <ret> for current)

access menu : m-` (useful for terminal mode)

conv. DOS to UNIX : C-x <ret> f unix <ret>

toggle buffers : c-x b up/down arrows <ret>

change buffer : c-mouse left click

kill buffer : c-x k

split window : c-x 2 (or c-x 3 for horizontal)

unsplit window : c-x 1

change window : c-x o (that's "o" (not zero))

change frame : c-x 5 o (as above, can use this for speedbar too)


mark (to copy/cut) : c-spc (or left-click, and drag over the text)

select all : c-c h

copy : m-w

cut : c-w

paste : c-y (yank)

cut line : c-k

undo : c-x u

backspace : DELETE (on Linux), Backspace (on win32)

delete : c-d (on Linux), DELETE (on win32)

line beginning : c-a

line end : c-e

forward a word : m-f      

backward a word : m-b

buffer end : m->                      

buffer start : m-<

jump to start : m-c-u jumps to start of section of any kind of parethesis

search : c-s (then begin typing) c-s c-w to search THIS word, c-s <ret> for search-next

replace : m-x replace-string

search in files : m-x find-grep-dired (will ask for dir and then word to look for)

word-wrap : m-x auto-fill-mode (turns on word-wrapping)

word-wrap selected : m-x fill-region

open speedbar : m-x speedbar

execute command on buffer/file (such as in a compile) : select all, then m-| then command for example, after selecting everything on a perl script, check its syntax = m-| then type perl -cw <ret>

suspend emacs : c-z (%emacs, or fg to unsuspend from the command line)

emacs tutorial : c-h t

find command : c-h c-f

emacs info help : c-h i (for specific help, use = c-h i m emacs <ret> m TOPIC <ret>)

open shell : m-x shell

change font : SHIFT-Mouse Left Click

insert page-break : c-q c-l

compare files : menu->Tools->Compare->Two Files...

conv. to uppercase : m-x upcase-region

conv. to lowercase : m-x downcase-region

capitalize : m-x capitalize-region

sort : m-x sort-lines

sql*plus : m-x sql-mode <ret> m-x sql-oracle

write mail : c-x m (c-c c-c to send)

run calendar/diary : m-x calendar

run "dungeon" : m-x dunnet (there are other games too)

create a changelog : m-x add-change-log-entry (see changelog for info) m-x change-log-mode

evaluate elisp : c-x c-e (or c-j)

display the time : m-x display-time in the .emacs file, can put (display-time)


turn on syntax highlighting (if not already set in .emacs file) : m-x font-lock-mode (or m-x global-font-lock-mode t (for global)) or from menu, select help->options->Global Font Lock

word wrap : from menu, select help->options->Auto Fill(Word Wrap) In Text Modes (Note this only applies from that moment on) to word-wrap an entire-selected area choose m-x fill-region

emacs spell-checker : requires ispell installed

emacs web browser (w3) : requires w3 installed {http://www.cs.indiana.edu/elisp/w3/}

emacs XML(DTD) validation : requires sgmls application installed. Find more information here

emacs JDE (Java Development Environment - compiling, debugging etc.) : requires Emacs JDE, although the emacs compile option can be used (m-x compile (but this requires the filename to be typed each time))


to get a directory listing (from which you can open a file, or delete/rename/etc a file) : c-x c-f type directory, and then type "."

handy commands in the directory listing mode include...

# : flag all #'ed files for deletion

~ : flag all ~'ed files (backup files) for deletion

u : unflag file

x : delete all flagged files

C : copy file

d : delete file

to open a file via ftp, use : c-x c-f and /HOST:FILENAME or /USER@HOST:FILENAME c-x c-f /myname@myhost:myfile.txt

here's an example to enable a mode in a file (text must be on top) : -*- Mode = Emacs-Lisp -*-

to add an "info" file:

1. Place the info file in emacs' info directory

2. Modify the "dir" file in that directory to reflect the new file, here's an example:

* Elisp Intro : (emacs-lisp-intro).   Introduction to Emacs Lisp

to view an ascii-table, use the following lisp:

(defun ascii-table (new)
  "Show the buffer *Ascii Table* or make one.
Make a new one if NEW (or prefix arg) is non-nil."
  (interactive "P")
  (let ((buf "*Ascii Table*")
        (c 0)
        (header "char  8  10  16%s")
        c64 c128 c192)
    (if (and (not new) (get-buffer buf))
        (display-buffer buf)
      (with-output-to-temp-buffer buf
        (message "Building ascii table...")
        ;;Silly spacing, but it looks better that way.
        (princ (format header "    "))
        (princ (format header "       "))
        (princ (format header "      "))
        (princ (format header "\n"))
        (while (< c 64)
          (setq c64 (+ c 64)
                c128 (+ c 128)
                c192 (+ c 192))
          (princ (format
                  ;;Yes, it's possible to take out the remaining
                  ;;spaces in the format string by changing the field
                  ;;widths, but that would make it even more illegible.
                  "%3s%4o%4d%4x %6s%4o%4d%4x %9s%4o%4d%4x %8s%4o%4d%4x\n"
                  (key-description (char-to-string c)) c c c
                  (key-description (char-to-string c64)) c64 c64 c64
                  (key-description (char-to-string c128)) c128 c128 c128
                  (key-description (char-to-string c192)) c192 c192 c192))
          (setq c (1+ c)))
        (message "Building ascii table...done.")))))

examples from the command line

change colors : emacs -fg black -bg grey

run in terminal : emacs -nw

start emacs in another x-window : emacs &

favourite settings

background color : #2F4F4F (dark slate gray)

foreground color : #F5DEB3 (wheat)

font : 9x15 Regular 11


The FAQ for Win32 emacs : http://www.gnu.org/software/emacs/windows/ntemacs.html

Emacs Lisp Introductions : http://www.delorie.com/gnu/docs/emacs-lisp-intro/, http://www.rattlesnake.com/intro/index.html

Emergency ELisp : A great ELisp primer

Examples of .emacs files (Note some are for XEmacs) : http://www.dotemacs.de and http://www.dotemacs.de/dotfiles/AndreyAKulaga.emacs.html

Emacs Lisp Cookbook : http://www.emacswiki.org/emacs/ElispCookbook

setting up a personalised .emacs file

Note for Windows the .emacs file should be c:\.emacs

Here is my emacs configuration file as an example (;; is a comment):

;; ----------------------------
;; -- roqetman's .emacs file --
;; ----------------------------

;; background & text colors (for windows/x-windows)
(when window-system
  (set-foreground-color "#F5DEB3")
  (set-background-color "#2F4F4F"))
;;  (set-background-color "#fffbf0")) ;ivory

;; change cursor color
(set-cursor-color "white")

;;switch off blinking cursor (for emacs 21)
(if (fboundp 'blink-cursor-mode)
    (blink-cursor-mode 0))

;; set the format for the title bars 
(setq frame-title-format "emacs  %f")

;;set scroll to move 1 line at a time
(setq scroll-step 1)

;;enable column number display
(column-number-mode t)

;; enable horizontal scrolling
(hscroll-global-mode t)

;; show marked text in inverse video
(setq-default transient-mark-mode t)

;make the y or n suffice for a yes or no question
(fset 'yes-or-no-p 'y-or-n-p)

;; platform-specific settings
(if (eq system-type 'windows-nt)
    (progn ;; windows-specific settings

      ;;change default font (this *is* the default on *NIX, so not required on that 
      (set-default-font "-*-9x15-normal-r-*-*-15-112-96-96-c-*-*-#33")

      ;; set the default printers
      ;; NB for postscript printers, ghostscript must be installed (you can find it at 
      ;; ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/aladdin/gs650/gs650w32.exe)
      (setq printer-name "//MYDOMAIN/HPLaserJ")  ; network printer
      (setq ps-lpr-command "") 
      (setq ps-printer-name "//MYDOMAIN/HPLaserJ") ;network printer
      ;(setq ps-printer-name "//MYDOMAIN/HPColorL") ;network color printer
      (setq ps-lpr-switches nil)
      ;; set up mail defaults
      (setq user-full-name "roqetman")
      (setq user-mail-address "roqetman@mydomain.com")
      (setq smtpmail-default-smtp-server "MYDOMAIN")
      (setq smtpmail-local-domain nil)
      (setq send-mail-function 'smtpmail-send-it)
      (load-library "smtpmail")

      ;;load w3 browser (can be downloaded from 
      (setq load-path (cons "C:/Program Files/emacs-21.1/w3-4.0pre.47/lisp" load-path))
      ;;(require 'w3-auto)

      ;; enable standard display (for pasting from rich-text etc.)
      (standard-display-8bit 128 159)

      ;; enable gnuserv, so that files can load into a single instance (can be 
      ;; downloaded (for win32) from http://www.wyrdrune.com/index.html?gnuserv.html~main
      (require 'gnuserv)
      ;; allows gnuserv to use the current frame to hold opened files
      (setq gnuserv-frame (selected-frame))

      ;; add to path to Emacs Load Path                                  
      (setq load-path (append (list nil "c:/roqetman/lang/lisp") load-path))
      ;;set default directory in win32
      (defun buffer-set-default-directory ( dir )
	;; Sets the current directory to DIR for buffers that do not have a file name 
        ;; associated. The function is indented for the w32 port to set the login 
        ;; directory (~/) because on startup the default directory for *scratch* and 
        ;; *Messages* are the emacs bin directory or the long directory name that was 
        ;; set in the properties of a emacs icon."
	"Sets the current directory to DIR for buffers that do not have a file name associated."
	  (let (
		(list (buffer-list))
	    (while list
	      (set-buffer (car list))
	      (if (eq buffer-file-name nil)
		  (setq default-directory dir)
	      (setq list (cdr list))
      (buffer-set-default-directory "c:/roqetman/")
  (progn ;; linux-specific settings
    ;; add to path to Emacs Load Path                                  
    (setq load-path (append (list nil "~/emacs") load-path))

    ;; set local printer
    (setq lpr-command "/usr/local/bin/lpr")


;; activate CUA-mode (gives ms-windows c-x (cut), c-c (copy) and c-v (paste) 
;; functionality)
;; NB the cua.el file must be in your emacs lisp path: find it at http://www.cua.dk/
(require 'cua)
(CUA-mode t)

;; activate generic modes for additional syntax highlighting
(require 'generic-x)

;;adds "recent files" to menu. Standard on version 21. Available at 
(require 'recentf)
(recentf-mode 1)

;; add extensions to be colorized
(setq auto-mode-alist (cons '("\\.jhtml" . html-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.css" . html-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.xsl" . sgml-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.xsd" . sgml-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.ora" . sql-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.changelog" . change-log-mode) auto-mode-alist))

;; make change-log-mode auto-filled
(add-hook 'change-log-mode-hook 'turn-on-auto-fill)

;; personal elisp loads
;; roq-mode a personalized mode for colorizing ".roq" files 
;; (note that roq-mode.el must be in the load path), find it at 
;; http://www.roqet.org/software.html
(load "roq-mode")

;; turn on syntax highlighting
(global-font-lock-mode t)

;; show that we're done
(message "roqetman's .emacs Loaded")

© Roqet 2018 :: 2018-05-11 17:07:10