GNU Emacs

Emacs is a graphical text editor.  Commands are given by using combination or sequence keys


     C-x  (^x) (control-x)    must be done in combination
     M-x  (Meta-x) (usually Escape-x) must be done in sequence

to start Emacs:
 % emacs filename         << begins editing on the file named
 % emacs                      << begins editing on a new unnamed buffer

creates a work-buffer with a name associated with the file
won't modify the file associated with the buffer until the buffer is saved
name of the file can cause it to enter a special purpose mode when the editor starts special purpose such as for a programming language such as LISP or C or for writing a text layout language such as LaTeX or nroff
Will usually assume fundamental mode for multiple purpose text files

Screen Parts
 
 work buffer screen
     cursor
     minibuffer  M-x to get into the mini-buffer C-g to get out of the mini-buffer
                      tab when in mini-buffer will act as command completion
                      ? gives list of all possible completions
     mode line: stars tell if a change has been made
                     name tells the name of the work buffer
                     mode tells the mode of operation
                    amount tells the amount displayed (top bot %)

Saving to a file and leaving Emacs
 

Short Name Full Name
C-x C-c save-buffers-kill-emacs
if you have made changes, you will be asked if you want to save those changes
C-x C-w write-buffer-to-file
asks for the name of the file
C-x C-s save-buffer-to-file
assumes file associated with the buffer name

 
Moving the Cursor

usually the arrow keys will work  
 

Larger Scopes
M-b One word back
M-f or forward 
C-a begin of current line
C-e end of current line
M-v previous screen
C-v next screen
M-< begin of buffer
M-> end of buffer
M-x goto-line  allows you to specify what line to go to

Getting Help
 

C-h puts you into the help menu unless it is remapped to be the backspace then you must use
M-x help many ways to get help
a apropos   type a keyword and will tell commands which are associated with that keyword
t tutorial  opens a new buffer so you can edit the tutorial file
C-x k kills that buffer so you can go back to what you were doing
k key description type a key sequence or combination and it will described the current binding to that command

Buffer Commands

C-x C-v replace current contents of the buffer with the named file
C-x C-f open an additional buffer with the contents of the named file
C-x b switches to the named buffer
C-x C-b list buffers so you can know the name of the one you want to go to
C-x k kill the current buffer
C-x C-s to save the current buffer before killing

Window Commands
 

C-x 2  split screen horizontally
C-x 3 spit screen vertically
C-x o (lowercase Oh) advance cursor to next window
C-x 0 (number zero) close the current window
C-x 1 close all but the current window
C-x ^ enlarge the current window

 
Deleting Text

        <delete> <backspace> or whichever is mapped     delete prev. char
        C-d             delete current character
        M-<delete>      one word backwards
        M-d             one word forwards

        C-k             deletes to end of line
        C-k C-k         deletes to end of line and end-of-line character
        M-# C-k         M-# is a general multiplier so will cause the
                        deletion to the end of the current line and a
                        number of lines after
                        i.e. M-2 C-k deletes to the end of the current line
                                and the one line after

"kill-ring" = vi's pasting buffer except multiple sequential deletions
        collected
        no single character deletions are kept
        keeps those which have "kill" in the name of the command

"yank"  = vi's "paste"
        C-y  allows you to bring the most recent thing out of the
                pasting buffer
        M-y  allows you to go to the previous one
 

Using Blocking to delete or put into the kill ring
-----------------------------------------------
 
C-@     sets a marker to indicate the beginning of a block
        often mapped also to C-<space>
C-x C-x to see where the marker is set and then to go back to the other end
C-w     kill the block (delete from buffer and put into kill ring)
M-w     copy the block into the kill ring without modifying the buffer

Undo
----
C-_     or    C-x u
                undoes the one last change to the work buffer
                if repeated continues going back until nothing to undo

M-x revert-buffer       allows you to get back the buffer as it was when you
                                last saved the file - will make sure
                                of the file name associated with the buffer
=====================
Shell commands
--------------
M-! command             allows you to do one shell command
                        opens a new window for the output of that command
                        use   C-x o             to go into that window
                        or    C-x 1             to get rid of that window

C-u M-! command         puts output into the current work buffer
---------
M-| command             allows you to act on the marked portions such as find
                        misspelled words
C-u M-| command         allows you to replace that portion of the document
                        such as      C-u M-| sort

-------------
Interactive shell
        M-x shell       starts the interactive shell in a new buffer so you
                        can then use C-x b to switch into it when ever needed
                        terminal type is "emacs"
searching
-----------
        C-s   string            isearch-forward       incremental search

searching for regular expressions
-----------------------------------
        M-x isearch-forward-regexp
        M-x re-search-forward

        regular expression allows these meta-characters
                ^ - beginning of line
                $ - end of line
                . - one character
                * - multiple occurrences of character before
                [ ] - contain a class of characters

replacing
-----------
    interactive replace
    ----------------------
        M-% oldstring <return> newstring <return>
        answer with     y - yes, replace this one, but go on
                        n - no, do not replace this one, but go on
                        q - no, do not replace this one, and quit now
                        ! - yes, do replace this one and all others that follow
     global replace
     ------------------
        M-x replace-string <return> oldstring <return> newstring <return>

     replace with regular expressions in the search string
     ---------------------------------------------------------
        M-x replace-regexp <return> oldstring <return> newstring <return>

spelling
--------
        can use the regular shell command
                C-@      to set the mark
                M-| spell    to run the spell utility on the marked region
            but this has limitations such as what is used as the dictionary

        Emacs speller -
                M-x spell-buffer    to look through the whole buffer
                                        showing misspelled words

        personalize the speller with the .spell file
        the .spell file can hold your own words - then set up Emacs
                to use that file with the set up command
                (setq spell-command "spell +.spell")
        tells it to use the standard shell dictionary plus the extra
                words in the .spell file
        .spell must have a blank line at the end

Setting up Emacs
------------------
        in file named .emacs or after M-x

        general form in .emacs file
                                (setq variablename value)

        general form in session is
                                M-x  set-variable <return>
                                        variablename <return>
                                        value <return>

        value is t for on, nil for off or a specified numeric or string value

common variables and their default values
        kill-ring-max           10
        window-min-height       3
        tab-width               7
        case-fold-search        t
        auto-save-default       t
        auto-save-interval      100
        fill-column             70

modes of operation
        M-x  auto-fill-mode  to turn on the ability to do filling
                        (auto line wrap)

        Major Modes             Minor Modes
        ------------            -----------
        Fundamental             Fill mode
        text mode               abbrev mode
        C                       autosave mode
        LaTeX
        picture

        (setq  default-major-mode  'text-mode)
or
        M-x text-mode

        (setq text-mode-hook  'turn-on-auto-fill)
or
        M-x auto-fill-mode
-----------------------------------------------------------
Binding Keys
        (global-set-key         "\M- "  'set-mark-command)
or
        M-x    global-set-key <return>  <escape>-<space>  set-mark-command
 

        (global-set-key         "\M-h"    'hanoi)
or
        M-x     global-set-key <return> <escape>-h  hanoi
 

Picture Drawing
-----------------
        M-x  picture-mode     to go into picture mode

    to draw a line
        C-c   direction
 
        direction =     ^       up
                        `       up and left
                        '       up and right
                        <       left

                        >       right
                        /       down and left
                        \       down and right
                        .       down
 

    other special picture mode commands
                C-d             deletes the contents of a character space
                C-c C-d         deletes the character space itself
                C-k             deletes contents of the current line
                <return>        moves cursor down
                C-b             inserts a blank line

Back Home Up Next