In this lesson, we will introduce the Emacs editor. Emacs like vi is a powerful editor. Some people prefer vi, others prefer Emacs.

Emacs editor

To edit a file with Emacs , run emacs [file], the file is the file name that you wish to edit.

When you look at the Emacs documentation, you will see C-<char> , this means to hold down the Ctrl key while pressing that <character>. For example, C-h means to hold down the Ctrl + h.

When you see the M-<char> "Meta" key ( This is Alt key ) while pressing that <character>.

C-h Ctrl + hHelp
C-x C-c Ctrl + x followed by Ctrl + cExit
C-x C-s Ctrl + x followed by Ctrl + sSave the file
C-h t Ctrl + h followed by tBuilt-in tutorial
C-h k <key> Ctrl + h followed by k <key>The help on key

Emacs Navigation

In DocumentationKeysMeaning
C-p Ctrl + pPrevious line
C-n Ctrl + nNext line
C-b Ctrl + bBackward one character
C-f Ctrl + fForward one character
M-f Alt + fForward one word
M-b Alt + bBackward one word
C-a Ctrl + aGo to the beginning of the line
C-e Ctrl + eGo to the end of the line
M-< Alt + <Go to the beginning of the file
M-> Alt + >Go to the end of the file

Emacs - Deleting Text

In DocumentationKeysMeaning
C-d Ctrl + dDelete a character
M-d Alt + dDelete a word

Emacs - Copying, Pasting, and Undo

In DocumentationKeysMeaning
C-k Ctrl + kKill (cut)
C-y Ctrl + yYank (paste)
C-x u Ctrl + x followed by uUndo

Emacs - Searching

In DocumentationKeysMeaning
C-s Ctrl + sStart a forward search
C-r Ctrl + rStart a reverse search

Emacs - Repeating Commands

Like vi Emacs provides a way to repeat Commands.

In DocumentationKeysMeaning
C-u N <command> Ctrl + u followed by N <command>Repeat <command> N times.

For example, to kill three lines of text, enter Ctrl + u followed by 3 followed by Ctrl + k.