The EPITA computer rooms are equipped with two command-line text editors: Vim and Emacs. You will use them throughout the year to write and edit code. Both work very differently from anything you have likely used before, but a handful of commands is enough to be productive.

Vim#

Vim is launched from the terminal only. Open a terminal (Mod + Enter) and type:

vim filename.c

Modes#

Vim is a modal editor: the keyboard has two completely different behaviors depending on the current mode.

  • Normal mode — the default when you open a file. Keystrokes are interpreted as commands, not text. You navigate and edit here.
  • Insert mode — the mode where you type text that goes into the file.

When you first open a file, you are in normal mode. Nothing you type will appear as text; it will be interpreted as a command. This is the source of nearly all beginner confusion.

Press i to enter insert mode. The status bar at the bottom will show -- INSERT --. Type your text. Press Esc to return to normal mode when you are done.

Saving and quitting#

From normal mode, type : to open the command prompt at the bottom of the screen, then type a command and press Enter.

Command Action
:w Save the file
:q Quit (fails if there are unsaved changes)
:wq Save and quit
:q! Quit without saving

Quick reference#

Key Action
i Enter insert mode (start typing)
Esc Return to normal mode
:w Save
:q Quit
:wq Save and quit
:q! Quit without saving

Emacs#

Emacs can be opened from dmenu (Mod + D, type emacs, press Enter) or from a terminal:

emacs filename.c

Unlike Vim, Emacs has no modes. The cursor behaves like a normal text editor: you can type immediately. Navigate with the arrow keys.

Keyboard shortcut notation#

Emacs shortcuts use two prefixes:

  • C- — hold Control and press the key. C-x means Ctrl+X.
  • M- — hold Alt (Meta) and press the key. M-x means Alt+X.

A two-part shortcut like C-x C-s means: press Ctrl+X, release, then press Ctrl+S.

C-g cancels any command in progress. Use it whenever something is not behaving as expected.

Quick reference#

Shortcut Action
C-x C-f Open a file
C-x C-s Save the current file
C-x C-c Quit Emacs
C-g Cancel the current command