Need help? Chat now!
Search results for:
Table of Contents
Editing text-based files in Linux can be confusing if you are unfamiliar with using the command-line as there is no graphical user interface to help guide you. But fear not, we will cover two of the most popular console-based text editors, nano and vi, in this article.
You'll need to be logged into your server via SSH before beginning. If you're not sure how to do this, you may refer to the following guide, which covers Connecting to Your Server via SSH.
This text editor is a growing favorite among Linux users due to its overall ease of use and default on most modern Linux distributions. nano's most commonly used shortcut keys are shown at the bottom of the page with the ^ symbol representing the CTRL key followed by a lowercase letter.
This will save the contents to the file you opened. Just press ENTER if this is still the file name you wish to edit or CTRL-C to cancel or CTRL-X to exit.
This will close the nano program. If you've made any unsaved changes, it will ask you if you'd like to continue without saving.
vi is an older text editor and the most widely installed. It is a bit less intuitive than nano. However, once you learn a few common commands, you won't find them too difficult to use.
Editing a file in vi is a fairly straightforward process.
Once you're done editing a file, you'll need to save the changes you have made.
This will place the editor into INSERT mode so you can make changes to the text.
This will save the contents to the file you opened. (write and quit)
Close: :q or :q!
This will close the vi program. If you would like to quit without saving any changes you've made, then use :q! instead of :q
Save and Close: Hold the shift key and press ZZ
You should now be able to successfully create, edit, and save a file in two of the primarily used text-based editors in Linux.
Written by Michael Brower / March 28, 2017