DEV Community

Cover image for VIM in Action: Mastering the Most Powerful Text Editor for Linux and DevOps
DhavalThakar97
DhavalThakar97

Posted on

VIM in Action: Mastering the Most Powerful Text Editor for Linux and DevOps

Introduction

VIM, known for its speed, flexibility, and terminal efficiency, is foundational in modern Linux-based development and operations. Mastering VIM commands improves your productivity, enhances your troubleshooting capabilities, and allows seamless editing across remote and embedded systems.

In this article, we’ll explore what VIM is, break down its core modes, provide essential keyboard shortcuts, share best practices, and walk through real-world examples. Whether you're just starting or brushing up for RHCSA or DevOps work, this guide is structured to make learning fun and practical.


Table of Contents


What is VIM?

VIM stands for Vi IMproved. It is a highly configurable text editor built to enable efficient text editing and scripting from the command line. Originally developed as an enhancement to the vi editor, VIM has become one of the most widely used tools for editing files within terminal-based environments across Unix, Linux, and even Windows (via WSL or Git Bash).

Key Features

  • Syntax highlighting for many programming languages
  • Persistent undo history
  • Support for plugins and themes
  • Extremely lightweight and fast
  • Operates completely within the terminal (no GUI required)

VIM is essential in environments where GUI tools are inaccessible — such as remote servers, containers, embedded devices, and CI/CD pipelines.


VIM Modes – The Heart of Navigation

There are three primary modes in VIM. Each one serves a unique purpose:

1. Command Mode

This is the default mode when you open a file.

vim filename.txt
Enter fullscreen mode Exit fullscreen mode
  • You can navigate, delete, copy, and paste in this mode.
  • Press i to switch to Insert Mode.

2. Insert Mode

  • This mode allows you to type, edit, and make changes.
  • Once you’re done, press ESC to return to Command Mode.

3. Extended Mode

  • Accessed by pressing : from Command Mode.

  • You can now issue commands such as:

  • :wq → Save and quit
  • :q! → Quit without saving

🎯 Fun Tip: Think of Command Mode as "looking at the paper," Insert Mode as "writing on it," and Extended Mode as "deciding what to do with it."


Best Practice: Enable Line Numbers

Line numbers help you track changes, navigate efficiently, and debug configurations.

Always enable them when working with long scripts or configuration files.

  • Enable line numbers:
:se nu
Enter fullscreen mode Exit fullscreen mode
  • Disable line numbers:
:se nonu
Enter fullscreen mode Exit fullscreen mode

✨ Essential VIM Shortcuts (Command Mode)

🔄 Copy Commands

  • yy – Copy current line
  • nyy – Copy next n lines
  • yw – Copy current word

❌ Delete Commands

  • dd – Delete current line
  • ndd – Delete next n lines
  • dw – Delete current word

🚀 Navigation Commands

  • gg – Go to the top of the file
  • G – Go to the bottom of the file
  • ngg or nG – Go to line number n

📌 Other Shortcuts

  • p – Paste
  • u – Undo
  • Ctrl + r – Redo

🧪 Fun Learning Challenge: VIM Practice Lab

Try creating a file and walk through this challenge:

vim demo.txt
Enter fullscreen mode Exit fullscreen mode
  1. Enable line numbers
  2. Insert 5 lines of text
  3. Copy the second line
  4. Paste it below
  5. Delete the last two lines
  6. Save and quit

✅ Repeat this daily for 5 minutes to build muscle memory and become fluent in VIM navigation!


VIM Tips & Hidden Gems

1. Qucikly switch Between Files

  • Open multiple files:
vim filename1.txt filename2.txt
Enter fullscreen mode Exit fullscreen mode
  • Switch between files:
:n  #next file
:prev  #previous file
Enter fullscreen mode Exit fullscreen mode

2. Search in VIM

  • Use / or ? to search forward or backward.
/wordtosearch
Enter fullscreen mode Exit fullscreen mode
  • Use n and N to jump to the next or previous match.

3. Replace Words

  • Replace all occurrences of a word in the file using substitution commands.
:%s/apple/android/g
Enter fullscreen mode Exit fullscreen mode

4. Highlight Word

  • Press * on a word to highlight all its matches in the file.

5. Split Screen Editing

  • Use :split or :vsplit to open files side-by-side.
  • Horizontal split:
:split otherfile.txt
Enter fullscreen mode Exit fullscreen mode
  • Vertical split:
:vsplit otherfile.txt
Enter fullscreen mode Exit fullscreen mode
  • Use Ctrl + w and arrow keys (or hjkl) to move between splits.

6. Save As

  • Use the :w command followed by a new filename to save the file under a different name.
:w newfilename.txt
Enter fullscreen mode Exit fullscreen mode

7. Jump to Matching Brackets

  • Place the cursor on a bracket or brace and press %.

8. Access Built-in Help

  • Use :help followed by any command name for instant documentation.
:help
:help <command>
Enter fullscreen mode Exit fullscreen mode

Conclusion

VIM may seem overwhelming at first, but with regular use, it becomes a powerful ally in your terminal toolkit. Whether you're editing scripts, updating configuration files, or writing documentation—VIM's efficiency and depth can truly set you apart.

Let’s make VIM second nature — one keystroke at a time. 🚀

📣 Follow me on LinkedIn for more real-world Linux and DevOps guides!


Top comments (0)