DEV Community

Cover image for Linux Text Editors: Learning Nano, Vi and Vim as a Beginner
Samkeliso Dube
Samkeliso Dube

Posted on Edited on

Linux Text Editors: Learning Nano, Vi and Vim as a Beginner

As part of my Linux learning journey, I spent time practising three terminal-based text editors: Nano, Vi and Vim.

Before this exercise, I understood that text editors were used to create and modify files. However, I wanted to understand how they work and why they are useful when managing Linux systems.

In DevOps, you will often work with configuration files, scripts and application settings. Knowing how to edit files directly from the terminal is therefore an important practical skill.

1. Nano : A beginner-friendly text editor

Nano was the first editor I practised.

It is straightforward because you can open a file and start typing without switching between editing modes.

To open a file:

nano notes.txt
Enter fullscreen mode Exit fullscreen mode

I practised creating a file, adding text and saving my changes.

nano_editor

Some useful Nano shortcuts:

Shortcut Action
Ctrl + O Save the file
Enter Confirm the filename
Ctrl + X Exit Nano
Ctrl + W Search within the file

One thing I learned is that saving and exiting are two separate actions. Pressing Ctrl + O saves the file, while Ctrl + X exits the editor.

2.Vi : Understanding editing modes

Next, I moved to Vi.

This editor introduced me to an important concept: editing modes.

When vi opens a file, it starts in Normal (Command) mode. Unlike nano, you cannot immediately start typing text.

The two main modes I practised were:

  • Normal mode: Used for navigation and executing commands.
  • Insert mode: Used for typing and editing text.

1. Normal Mode (Command Mode)

This is the mode you start in when opening a file. It is used to navigate through the file and execute commands without directly typing or modifying text.

Command Action
h, j, k, l Move around the file
dd Delete the current line
yy Copy the current line
p Paste copied text
u Undo the last change
x Delete the character under the cursor

vi_editor

Note:You can perform these actions without entering Insert Mode.

2. Insert Mode

This is the mode used to type, add and modify the actual contents of a file.

To enter Insert Mode, press i while in Normal Mode.

For example, when editing an Nginx configuration file, you can use Insert Mode to change a port from 80 to 8080, add a configuration directive, or modify an existing line.

When you finish editing, press esc to return to Normal Mode.

vi_editor2

Some important commands:

Command Action
i Enter Insert mode
Esc Return to Normal mode
:w Save changes
:q Quit if there are no unsaved changes
:q! Quit without saving unsaved changes
:wq Save and quit

Understanding these commands made working with Vi much easier.

Remember:

Normal Mode = Navigate and execute editing commands.

Insert Mode = Type and modify text.

Vi starts in Normal Mode because it allows you to control and manipulate the file before you begin editing its contents.

3. Vim : Vi Improved

After practising Vi, I installed Vim on my Ubuntu machine.

Vim stands for Vi Improved. It builds on Vi and provides additional capabilities.

I checked the installed version using:

vim --version
Enter fullscreen mode Exit fullscreen mode

My machine reported Vim 9.1.

I also explored some of its capabilities:

  • Syntax highlighting: Displays different code elements in different colours.
  • Split windows: Allows you to view multiple editing windows.
  • Code folding: Allows you to collapse sections of code.
  • Persistent undo: Can preserve undo history between editing sessions when configured.

I created a small Python file to observe syntax highlighting in action.

vsplit

4. Why are these editors useful in DevOps?

When managing Linux servers, text editors become useful in everyday tasks.

For example, you might need to:

  • Edit an Nginx configuration file.
  • Create a Bash script.
  • Update application configuration.
  • Inspect environment settings.
  • Modify service configuration files.

You may encounter commands such as:

sudo vim /etc/nginx/nginx.conf
Enter fullscreen mode Exit fullscreen mode

This opens an Nginx configuration file for editing with administrator privileges.

What I learned

  • Nano provides a straightforward editing experience.
  • Vi introduced me to editing modes and command-based operations.
  • Vim builds on Vi with additional capabilities.
  • Saving and exiting are not always the same action.
  • Terminal-based editing is a useful skill when working with Linux servers.
  • Practical testing helps us understand differences instead of relying on assumptions.

Learning Linux one concept and one practical exercise at a time.


Linux #DevOps #Vim #LinuxAdministration #LearningInPublic

Top comments (0)