Command-line text editors

To edit a plain text file, you can use a command-line text editor.

Text editors are among the oldest programs available on any operating system, and come in a wide variety—from completely automatic text editors, where you essentially write a recipe for what actions should be taken on text and then let the computer do the work, to much more interactive text editors that can edit (and save) text in a wide variety of formats.

For general-purpose work, it’s easiest to deal with one of the text editors included with OS X. If you want to use a graphical text editor, use TextEdit (in Launchpad). Otherwise, use one of the many command-line editors provided. The three most full-featured command-line text editors included with OS X are:

If you’re new to using the command line and don’t anticipate using it much for editing, nano is probably your best choice. If you expect to spend a lot of time using the command-line environment, it’s probably worth learning either vim or emacs. They have very different design philosophies, so spend some time with each of them to determine which works best for you.

For more information about using nano, vim, or emacs, see their man pages.

You invoke a command-line editor by typing the name of the editor, followed by a space and then the name of the file you want to open. If you want to create a new file, type the editor name, followed by a space and the pathname of the file. Here’s an example of using nano to open a new file named “myFile.conf” in your Documents folder:

$ nano ~/Documents/myFile.conf