Skip to main content
In this guide, we explore the usage of pagers and the powerful Vim text editor. First, we discuss two popular pagers—Less and More—detailing how to view and navigate through text files in the terminal. Then, we introduce Vim, covering its core functionality, essential commands, and editing techniques.

Using the Less Pager

Pagers like Less allow you to view and navigate through large text files directly in the terminal. Less provides advanced features such as scrolling and searching, making it a popular choice for system log inspections and file viewing. To open a file using Less, enter the following command (here, we inspect the system log):
When the file is open, you will typically see the filename highlighted in the lower left corner. Navigation is easy with the arrow keys for scrolling up and down. Below is an example snippet from a syslog as displayed by Less:
You can scroll further using the arrow keys. For example, this snippet demonstrates additional navigation:
Remember to use the arrow keys in Less for smooth navigation through your log files. For more extensive documents, Less is highly recommended over other simpler pagers.

Searching Within Less

Less includes powerful search functionality. To search within a file:
  1. Press the slash (/) key.
  2. Type the desired search term (e.g., “system”) and press Enter.
  3. Less highlights the matching terms, and you can navigate through occurrences by pressing N for the next match or Shift + N for the previous match.
Below is a sample of search results highlighting various system messages:
By default, searches are case sensitive. To perform a case-insensitive search, append “\c” to your search term (e.g., /example\c):
To navigate backwards through matches, press uppercase N. When you are ready to exit Less, simply press Q.

Using the More Pager

While Less offers many features, the More pager is a simpler alternative with a more straightforward interface. More is effective for quick file views. To open a file with More, run the following command:
When you view a file with More, a progress indicator (like “More (2%)”) appears at the bottom of the screen. Use the spacebar to advance through the file page by page. Below is a sample output from More:
To exit More, press the Q key.

Introduction to Vim

Vim, short for “Vi Improved,” is a powerful text editor designed for efficiency. When you start Vim, a welcome screen appears, providing basic information and usage tips:

Basic Vim Modes

Vim is a mode-based editor, meaning it operates in different modes for specific tasks:
  • Insert Mode: Press the i key to enter Insert mode and start editing your file.
  • Command Mode: Press the Esc key to switch back to Command mode. In this mode, you can run commands for saving, quitting, or navigating within the file.
Always press Esc to ensure you are in Command mode before executing commands.

Creating, Saving, and Quitting Files in Vim

To create or edit a file, run:
While in Command mode, use the following commands:
  • To save your changes, type :w and press Enter.
  • To save and exit, type :wq after pressing Esc if necessary.
  • To exit without saving, type :q!.
To open an existing file, simply enter:
Movement in Vim is efficient with both arrow keys and command shortcuts:
  • Use h, j, k, and l for left, down, up, and right navigation respectively.
  • To search for text, press / followed by your search query (e.g., /example) and press Enter.
  • For a case-insensitive search, append \c to the query (e.g., /example\c).
  • To jump to a specific line, type :10 (where 10 is the line number).

Copying, Pasting, and Cutting Text

Vim offers quick commands for text manipulation:
  • Copy (yank) a line: Press yy.
  • Paste the copied line: Press p (repeat to paste multiple times).
  • Cut (delete) a line: Press dd, and then paste where appropriate using p.
These simple commands help streamline your workflow without reliance on a mouse.

Summary

In this guide, we reviewed the Less and More pagers for file navigation in the terminal, and provided an introduction to Vim with practical commands for editing, searching, and navigating files. Below is an additional text snippet as a closing note:
That concludes our overview of terminal pagers and Vim. Happy editing, and see you in the next lesson!

Watch Video