Emacs is a powerful, extensible and customizable text editor. GNU Emacs is probably the most popular variant of Emacs as it is included in the repositories of many popular GNU/Linux distributions. Emacs runs on several operating systems including GNU/Linux, OpenBSD, FreeBSD, NetBSD, MacOS, MS Windows and Solaris.

Install Emacs on OpenBSD

$ doas pkg_add emacs

Emacs comes with a comprehensive, built-in help system which can be accessed by pressing C-h t; In other words, pressing Control h, followed by t. This starts an interactive tutorial that you can follow, save and continue at a later time.

Emacs cheat sheet

Emacs key bindings are unique, but easy to understand and remember when you become familiar with its terminology. In Emacs C-x means "click on Control and x at the same time". M-x means: "type Alt then x"; M refers to Meta. In most cases the Alt key functions as the Meta key. However on some keyboards there is a real Meta key. In this cheat sheet we use the popular naming of the keys as Alt and Control.

Starting emacs

$ emacs [Enter]

    to start emacs. 

$ emacs filename [Enter]

    to start emacs and load a file 

$ emacs -nw filename [Enter]

    to start emacs with no new window (load file) 


[Ctrl]x [Ctrl]c

    quit emacs (Emacs will prompt if any of the files have not yet been saved.) 


    aborts any command in progress 


[Ctrl]h t

    to see the tutorial 

[Ctrl]h a topic [Enter]

    to see help about topic 

[Ctrl]x u

    undo the last command

Cursor positioning and navigation within a file

[Ctrl]f or [>-]

    forward (right) one character. 

[Ctrl]b or [>-]

    back (left) one character 

[Ctrl]p or [^]

    up one screen line 

[Ctrl]n or [v]

    down one screen line 


    left one word 


    right one word 


    to beginning of line 


    to end of line 


    start of document 


    end of document 


    page up 


    page down 	


    cursor in middle of screen 

[Ctrl]u 20 [Ctrl]n

    advance 20 lines 

[Ctrl]x w

    display the line number where the cursor is located 

[Esc]x goto-line [Enter] 999 [Enter]

    go to line number 999

Search and Replace

[Ctrl]s dance [Enter]

    search for dance; cursor moves as you type. Press [Enter] once at the correct location 

[Ctrl]r dance [Enter]

    search backwards for dance; cursor moves as you type. 

[Ctrl]s [Enter] [Enter]

    search for the next occurrence 

[Esc]% oldstring [Enter] newstring [Enter]

    Search for oldstring and replace it with newstring. The y key confirms each replacement, n skips it, q to exit 



    set mark at cursor 


    kill region 


    copy region to kill ring 


    yank back last thing killed 

Loading and Saving

[Ctrl]x [Ctrl]f filename

    create new filename for editing (clears workspace) 

[Ctrl]x [Ctrl]f filename

    load in filename for editing 

[Ctrl]x [Ctrl]w filename

    write (save) as filename 

[Ctrl]x [Ctrl]s

    resave under the current filename (based on above or name given when starting emacs)

Cutting and Pasting


     Mark one end of region


     Cut (after you Mark and move to other end)


     Copy (after you Mark and move to other end)


     Yank (paste) most recently killed (cut or copied); will also use text currently selected in another application.


     Next most recently killed (do [Ctrl]y first, repeat [Alt]y to cycle thru all)‍