Use command-line text editors in Terminal on Mac
To edit a plain text file in Terminal, you can use a command-line text editor.
For general-purpose work, it’s easiest to use one of the text editors included with macOS. If you want to use a graphical text editor, use TextEdit (in Launchpad). Otherwise, use one of the command-line editors included with macOS:
Nano nano
is a simple command-line editor. It’s a good introduction to using a command-line editor because it includes easy-to-follow on-screen help. See the nano man page.
Vim vim
is a vi
-compatible text editor. It has many powerful enhancements for moving around, searching, and editing documents. Basic editing is simple to learn, and there’s additional functionality to explore. You can access most of the functionality by using keystroke combinations that trigger certain behavior. vim
, or the editor it’s modeled after, vi
, is found in most UNIX-based operating systems. See the vim man page.
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 vim
. They have very different design philosophies, so spend some time with each of them to determine which works best for you.
Go to the Terminal app on your Mac.
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