Almost every Linux distribution includes the vi text editor, and it’s usually the only text editor included in minimal installations. If you’ve never used vi, it can seem really confusing at first and can even be frustrating since you’ll need to use it to configure network settings prior to downloading another text editor such as nano. If you’re not familiar with vi, it is important to note there is a “command” and “insert” mode. If you’ve never used vi, you’ll probably find it easier at first to enter “insert” mode when modifying a text file, escaping to command mode, and entering the command to save and quit. Here’s a quick cheat sheet of the commands you’ll need:
|i||Enters “insert” mode|
|esc||The escape key exits “insert” mode and returns to “command” mode|
|:wq||In command mode this saves the file and quits once you press the enter key|
|:q!||In command mode this quits the file without saving once you press the enter key|
Open a file to edit with vi
Once you open the file, you’ll be in command mode by default and you’ll see the line count and character count at the bottom of the file
Now, if you press the ” i “ key you’ll now enter insert mode which is noted at the bottom. Once in insert mode, you can edit text where the blinking cursor is located just like most other text editors.
Once you’ve finished your modifications, press the Esc key to return to command mode. In command mode, you’ll see your commands appear at the bottom of the screen when you type them. Save and quite by pressing the colon key, w key, q key, and press the Enter to execute the commands.
Once complete, you’ll see a notification that the file was written.