How to edit text files in Ubuntu Server 18.04

The following steps show how to edit a text file in Ubuntu Server 18.04 using the terminal.

In these examples we’ll show how to use vi Editor and Nano to open, edit and save a text file.

How to edit a file using vi Editor

  1. Using the terminal, navigate to the directory where the file is saved
  2. Enter the following command to open the file in Vi – where test_file.txt is the name of the file
  3. vi test_file.txt
  4. When vi Editor is first started it is in “command mode”
  5. Press i on your keyboard to enter “insert mode” – which allows you to insert text into the file
  6. Use the arrow keys your keyboard to navigate to where you need to edit the text and edit as required
  7. To save and exit – press Escape then Shift + Z and Shift + Z again

How to edit a file using Nano

  1. Using the terminal, navigate to the directory where the file is saved
  2. Enter the following command to open the file in Vi – where test_file.txt is the name of the file
  3. nano test_file.txt
  4. Use the arrow keys your keyboard to navigate to where you need to edit the text and edit as required
  5. To save and exit – Ctrl + X then Y