Progress: 0/62 (0%)

📝 Viewing and Editing Text Files

Viewing and Editing Text Files

Linux offers several text editors for different needs — from simple terminal editors perfect for beginners to powerful editors used by professionals. Whether you prefer working in the terminal or using a graphical interface, there's an editor for you.

nano — Simple Text Editor

nano is a beginner-friendly terminal text editor. Think of it like Notepad in Windows, but inside the terminal. You can view, create, and edit files easily without learning complex commands.

Basic usage
nano filename.txt
📌 Example:
nano notes.txt
  • Opens notes.txt in nano
  • If the file doesn't exist, it creates a new one
nano interface

Text area → where you type

Command shortcuts → displayed at the bottom, starting with ^ (means Ctrl)

  • ^O → Save (Ctrl + O)
  • ^X → Exit (Ctrl + X)
  • ^K → Cut a line
  • ^U → Paste a line
Editing in nano
  • Use arrow keys to move around
  • Type normally to add text
  • Use the shortcuts at the bottom to save, exit, cut, or paste

It's very intuitive — no modes to remember, just edit and use Ctrl shortcuts!

Real-life analogy

Imagine nano as a digital notepad on your terminal:

  • Easy to use
  • Simple shortcuts
  • Great for quick edits or creating small scripts

vi — Classic Terminal Editor

vi is a powerful terminal text editor that comes preinstalled on almost every Linux system. It's a bit more complex than nano, but very efficient once you know the modes and commands. Think of it like moving from Notepad → Microsoft Word with shortcuts in the terminal.

Modes in vi

vi has two main modes:

Normal mode → for navigating and issuing commands

  • Default mode when you open a file
  • You cannot type text directly here

Insert mode → for typing and editing text

  • Enter by pressing i in normal mode
  • Press Esc to go back to normal mode
Basic commands

Open a file:

vi filename.txt

Switch to insert mode → press i

Save changes → in normal mode, type:

:w

Exit → in normal mode, type:

:q

Save and exit:

:wq

Exit without saving:

:q!
Navigation in vi
  • Arrow keys → move cursor
  • h → left, j → down, k → up, l → right (classic vi keys)
  • gg → jump to start of file
  • G → jump to end of file
Real-life analogy

Imagine vi like learning to drive a manual car:

  • At first, you need to understand the clutch, gears, and brakes (modes and commands)
  • Once you get it, you can navigate and edit very efficiently

vim — Advanced Version of vi

vim stands for "Vi Improved". It's basically vi but with extra features like syntax highlighting, undo/redo, plugins, and better customization. Think of it like upgrading from a manual bike (vi) → a motorbike with gears, speedometer, and lights (vim).

Basic usage
vim filename.txt
  • Opens the file like vi
  • Same Normal and Insert modes apply
Extra features

Syntax highlighting → colors code automatically for programming files

Undo/Redo

  • Undo → u (normal mode)
  • Redo → Ctrl + r (normal mode)

Visual mode → select text to copy or delete

  • Enter visual mode → v
  • Move cursor → select text

Search/keyword then n for next match

Saving and exiting
  • Save → :w
  • Exit → :q
  • Save and exit → :wq
  • Exit without saving → :q!
Real-life analogy

vim is like a pro-level toolkit:

  • For programmers, system admins, or anyone editing code, it's super fast and powerful once you master it
  • Has more control and shortcuts than vi or nano

gedit — GUI Text Editor

gedit is the graphical text editor for Linux. Think of it like Notepad on Windows or TextEdit on macOS — easy to use with menus, buttons, and mouse support. It's ideal if you don't want to use terminal-only editors like nano or vim.

Basic usage
gedit filename.txt
  • Opens filename.txt in a windowed GUI
  • If the file doesn't exist, it creates a new one
Features
  • Syntax highlighting for programming languages
  • Undo/Redo
  • Copy/Paste using mouse or keyboard shortcuts
  • Search and replace
  • Multiple tabs for editing several files at once
Real-life analogy

Imagine gedit as a simple office notebook app:

  • Click, type, scroll — everything visually intuitive
  • Great for beginners or for quick edits without remembering terminal commands

Topic Summary: Viewing and Editing Text Files

nano → simple terminal editor, beginner-friendly (like Notepad in terminal)

vi → classic terminal editor, requires learning modes (powerful once mastered)

vim → advanced version of vi with more features (syntax highlighting, undo/redo, plugins)

gedit → GUI editor, easy and visual (like Notepad on Windows)