5.2. Editors#

Terminal-based text editors allow us to write and edit files when we don’t have access to a GUI (e.g., when we are SSHing into a remote computer). VIM and EMACS are most common. We are requiring that students use EMACS for this course, and those who use VIM will be penalized.

5.2.1. EMACS Basics#

EMACS is a slightly more familiar-looking text editor that is valued for its extensibility. It is extremely configurable with a lot of tools and packages available.

To open a file in EMACS, type emacs <filename>. Unlike in VIM, you will immediately be able to write in/edit thew file. Once you are finished editing, you type ctrl+x followed by ctrl+c to save and exit. It will prompt you to confirm that you want to save and quit. Typing y and then enter will return you to the terminal.

EMACS has a built-in tutorial you can follow. Simply type emacs in the terminal and then scroll down to the tutorial using the arrow keys and press enter. This will take you through EMACS basics.

Here are some navigation commands you might find useful (where C- denotes ctrl+):

  • C-v: go forward one page

  • C-f: move forward one character

  • C-b: move backward one character

  • C-n: move to next line

  • C-p: move to previous line

  • C-a: move to the beginning of a line

  • C-e: move to the end of a line

  • C-g: stop a command that is taking too long to execute

5.2.2. Vim Basics#

Vim is a “simple to use, hard to master” text editor that is valued by vim enthusiasts for its coding effeciency.

To open a file in vim, type vim <filename>. When you enter vim, you will automatically be in normal mode where you can navigate your cursor. To insert text, type i to enter insert mode. To save a file, first press the esc key to enter normal mode, next press : to enter command mode, lastly press w and enter to save. To quit, enter command mode and enter q.