UNIX systems offer a variety of editors, each with their own set of features and commands. In this blog, we will explore some of the most commonly used UNIX editors and provide a brief overview of their functionalities. While editors like vim and emacs have extensive capabilities and a steep learning curve, we will focus on the basics to help you get started.

ed

ed is the original UNIX text editor and is considered the most basic editor available. Although rarely used by most people, it is worth mentioning. To start an interactive session, simply type ed in the terminal. Once in write mode, indicated by typing a and pressing enter, you can enter your text. To save the content, type a dot (.) on a new line and press enter. To save the buffer to a file, type w followed by the file name. Use q to quit the session.

To edit a file with ed, run the command ed <filename>. Pressing a in the ed session allows you to add content to the end of the file. To print the current file content, type ,p.

vi / vim

vim is a highly popular file editor among programmers. It boasts a large and active community and is continuously updated. In modern systems, vi is an alias for vim, meaning that vi is essentially an improved version of the traditional vi editor.

To start vim, simply run the vi command in the terminal. You can specify a filename to edit a specific file by running vi <filename>. vim has two main modes: command (or normal) mode and insert mode. By default, when you start vim, you are in command mode. To enter insert mode, press the i key. You will see the word -- INSERT -- at the bottom of the editor, indicating that you can start typing and modify the file contents.

Use the arrow keys or the h, j, k, and l keys to navigate within the file. Press esc to exit insert mode and return to command mode. In command mode, you can navigate through the file but cannot add content. To save the file, press : followed by w. To save and quit, press : followed by wq. To quit without saving, press : followed by q!. To undo an edit, press u, and to redo (cancel an undo), press ctrl-r.

These are the basic editing commands in vim. However, vim has many more powerful features and commands that we cannot cover in this introduction. To learn more, refer to the Vim FAQ and run the vimtutor command, which should already be installed on your system.

emacs

emacs is a highly versatile editor and has long been considered the default editor for UNIX systems. Infamous vi vs emacs arguments have sparked heated discussions among developers worldwide.

To open a new emacs session, simply type emacs in the terminal. To edit an existing file, use the command emacs <filename>. After making edits, press ctrl-x followed by ctrl-w to save the changes. Confirm the folder by pressing y and then overwrite the file if necessary. Press ctrl-x followed by ctrl-c or ctrl-x followed by c to exit emacs.

emacs offers a wide range of advanced features that are beyond the scope of this introduction. To access the built-in manual, press ctrl-h r, and for the official tutorial, press ctrl-h t.

(macOS users, please note that while Linux has no issues, macOS does not ship applications using GPLv3. Consequently, built-in UNIX commands that have been updated to GPLv3 are not updated. To resolve this, install emacs via Homebrew using the command brew install emacs.)

nano

nano is a beginner-friendly editor that allows you to directly type characters into a file without worrying about specific modes. To run nano, use the command nano <filename>. You can quit without editing by pressing ctrl-X. If you made changes to the file buffer, nano will prompt you to confirm whether you want to save the edits or discard them. The help at the bottom of the screen displays the keyboard commands for working with the file.

pico is similar to nano, but nano is the GNU version of pico. At some point, pico was not open source, and nano was created as a clone to meet the requirements of the GNU operating system license.

These are just a few of the UNIX editors available to you. Depending on your needs and preferences, you may find one of them more suitable than the others. Feel free to explore their unique features and unleash their full potential.

Tags: UNIX, editors, vim, emacs, nano, ed