DEV Community

Sospeter Mong'are
Sospeter Mong'are

Posted on • Edited on

Vim Tutorial: How to Create, Edit, Save, and Quit Files

Introduction to Vim:
Vim is a powerful text editor available on various operating systems, widely used in Unix-based systems. This guide aims to help beginners understand the basics of Vim, which is essential for tasks like editing configuration files on Linux systems.

Installing Vim:

  • Linux: Use package managers like yum or apt.
  • Windows: Download from the official Vim page.
  • macOS: Use Brew or download from the official Vim page.

Basic Tasks in Vim:

  1. Create or Open a File:

    • Open a terminal and type vim filename to create or open a file.
  2. Vim Modes:

    • Vim starts in Command mode. Switch to Insert mode by pressing i to type text. Return to Command mode by pressing ESC.
  3. Edit a File:

    • In Insert mode, type your text. To save changes, switch back to Command mode (ESC).
  4. Save a File:

    • Use :w to save your changes in Command mode.
  5. Exit Vim:

    • Type :q to quit Vim. Use :wq to save and quit simultaneously. To exit without saving, use :q!.

Additional Features:

  • Display Line Numbers:
    • Use :set number to display and :set nonumber to hide line numbers.
  • File Navigation:
    • Use gg to jump to the top, G to jump to the bottom, and {line_number}G to go to a specific line.
  • Search a File:
    • Use /keyword to search and n/N to navigate through results. Use :nohl to turn off highlighting.

Vim's extensive functionality makes it a preferred tool for developers and administrators. Practice these basic tasks to become proficient and explore more advanced features to enhance your productivity.

For more information, visit the full tutorial on CompTIA's blog.

Top comments (1)

Collapse
 
citronbrick profile image
CitronBrick

Pasting using right click, when you are in command mode, pastes the text but skips the 1st letter of the copied text.