Site icon CentLinux

Vim Cheat Sheet for DevOps and Linux Admins

Share on Social Media

Master Text Editing in Linux with this ultimate VIM cheat sheet tailored for DevOps and Linux Admins. Learn essential commands, shortcuts, plugins, and pro tips to boost your productivity in the terminal. #centlinux #linux #ubuntu



Introduction to Vim

What is Vim?

Vim, short for “Vi Improved,” is a highly configurable, powerful text editor that is an enhanced clone of the vi editor distributed with most UNIX systems. While it was created decades ago, its value hasn’t diminished—in fact, it’s only grown stronger in the realm of DevOps and Linux system administration. Vim operates primarily in a command-line environment, and it’s known for being lightweight, blazing fast, and incredibly robust once you master its shortcuts and commands.

Imagine having a tool that lets you move, edit, and manipulate files faster than any GUI-based editor. That’s Vim. It may look intimidating at first glance, but once you’re past the initial learning curve, it becomes a game-changer. Vim doesn’t just edit text—it becomes an extension of your hands on the keyboard.

What makes Vim particularly special is its modal nature. Unlike standard editors where you’re either typing or not, Vim separates concerns. There’s a mode for inserting text, one for navigating, another for selecting, and one for executing commands. This design makes your workflow more efficient once mastered.

Vim is installed by default on almost every Linux distribution, making it an essential tool in the toolkit of every Linux admin or DevOps engineer. No need to fumble around trying to install a new editor on a remote server—Vim is already there, ready for action.

Vim Cheat Sheet for DevOps and Linux Admins

Why Vim is Essential for DevOps and Linux Admins

For DevOps and Linux admins, Vim isn’t just another tool—it’s a survival kit. Here’s why Vim should be your go-to editor:

Think of Vim as a Swiss army knife for DevOps. Whether you’re editing a Kubernetes YAML file, tweaking a Bash script, or modifying a system configuration file deep inside /etc, Vim has your back.

Recommended Training: Complete Linux Training Course to Get Your Dream IT Job 2025 from Imran Afzal


Getting Started with Vim

Install Vim Text Editor

Install Vim text editor process is usually straightforward because it comes pre-installed on many Linux distributions. But if for some reason it’s missing, you can install it easily depending on your OS:

Ubuntu/Debian:

sudo apt update 
sudo apt install vim

CentOS/RHEL:

sudo yum install vim

Arch Linux:

sudo pacman -S vim

macOS (with Homebrew):

brew install vim

Once installed, you can verify it with:

vim --version

You’ll see a list of features, compilation options, and version info—another clue to just how robust Vim text editor is.

Read Also: Nano Commands Cheat sheet for Linux

Launching Vim and Understanding the Interface

To launch Vim text editor, simply type vim followed by a filename:

vim filename.txt

If the file exists, it opens. If not, it creates a new one. At first, you’ll see something that might resemble a blank terminal window with a ~ on the side. Those tildes indicate unused lines—don’t be alarmed.

The real trick is knowing what you’re looking at:

Now, don’t panic. You’re in Vim text editor. You might be tempted to hit Ctrl+C or just close your terminal window out of frustration. Instead, let’s make sense of what’s going on.

Vim Modes Explained (Normal, Insert, Visual, Command)

Understanding Vim means understanding modes. Here’s a breakdown of the four key modes:

Each mode is a world of its own. The power of Vim lies in smoothly moving between them like a keyboard ninja. Think of modes as gears in a car—each serves a purpose, and switching at the right time keeps things running smoothly.


Essential Navigation Commands

Moving Around in a File

Navigating through files in Vim is one of its superpowers. Here’s how to move like a pro:

Mastering these commands will save you from wasting time reaching for the mouse or using arrow keys endlessly.

DevOps work often means handling multiple files at once. Vim makes it seamless:

Use these buffer commands like browser tabs—quick, easy toggling between files makes multi-file editing feel natural.


Editing Text Efficiently

Inserting and Deleting Text

Editing is where Vim really begins to shine. Forget about dragging your mouse or fumbling through menus—Vim text editor lets you manipulate text with laser precision using just your keyboard.

To insert text, you’ll need to enter Insert mode. Here are the main ways to do that:

These give you full control over how you enter text into your file. You’ll use i and a frequently, but o and O are lifesavers when you need to inject lines on the fly.

To delete text:

You can even combine deletion with motions. For example, d3w deletes the next three words.

Want to delete everything inside a set of quotes or parentheses? Use:

Mastering these lets you surgically remove or insert text with just a few keystrokes—no backspacing necessary.

Copying, Pasting, and Cutting (Yank, Paste, Delete)

Forget Ctrl+C and Ctrl+V—Vim does it smarter with yank, put, and delete:

These commands make it lightning fast to move code blocks or configuration sections from one spot to another.

Vim also uses registers to store what you yank or delete. So you can yank one thing, do something else, then come back and paste it—all without losing your clipboard.

Undo, Redo, and Repeat

We all make mistakes—even in Vim. The good news? Fixing them is easy.

Made a mistake five steps ago? No sweat—Vim’s undo tree lets you rewind time. And the ability to redo gives you a safety net.


Searching and Replacing

Searching Text Within a File

Searching in Vim is both powerful and straightforward. You can search forward or backward, case-sensitive or insensitive, and even use regular expressions.

To search:

Search modifiers:

Want to highlight all matches? Use:

:set hlsearch

You can turn it off with:

:nohlsearch

This is ideal when scanning through large config files, logs, or codebases.

Using Find and Replace Commands

Vim’s find and replace is deadly accurate and fast:

Basic usage:

:%s/old/new/g

This replaces all occurrences of “old” with “new” in the entire file.

Breakdown:

Replace only in a range:

:10,20s/old/new/g

Add confirmation before replacing:

:%s/old/new/gc

This is a lifesaver when you’re fixing config parameters or refactoring code across large files.


Working with Multiple Files

Opening and Managing Multiple Files

Managing multiple files is a daily routine in DevOps, and Vim makes it surprisingly simple.

To open multiple files:

vim file1.txt file2.txt

To switch between them:

You can also use the :e command:

:e /path/to/anotherfile

If you want to keep one file open while editing another, use buffers (more on that in the next section). Vim treats each file as a buffer behind the scenes, and once you get used to it, toggling between files becomes seamless.

Working with Tabs and Buffers

Let’s demystify buffers, windows, and tabs:

To open a file in a new tab:

:tabnew filename

Navigate tabs:

Working with buffers:

With tabs and buffers, you can juggle multiple files, logs, and scripts without leaving your Vim session.


Useful Configuration Settings

Editing .vimrc for Customization

The .vimrc file is where Vim transforms from a basic text editor into a tailored coding environment. It’s like your personal Vim playbook—set it once, and Vim behaves just how you like it every time.

The .vimrc file typically lives in your home directory:

~/.vimrc

Here are some must-have settings for DevOps and Linux admins:

syntax on             " Enable syntax highlighting
set number            " Show line numbers
set relativenumber    " Show relative line numbers
set autoindent        " Auto-indent new lines
set smartindent       " Smarter indenting
set tabstop=4         " Number of spaces per tab
set shiftwidth=4      " Indentation amount
set expandtab         " Convert tabs to spaces
set cursorline        " Highlight the current line
set background=dark   " Better color scheme for dark terminals
set clipboard=unnamedplus " Use system clipboard

Want to save your cursor position every time you exit a file? Add:

autocmd BufReadPost *
  \ if line("'\"") > 0 && line("'\"") <= line("$") |
  \   exe "normal! g'\"" |
  \ endif

Customizing your .vimrc boosts efficiency like nothing else. You’re no longer wrestling with the defaults—you’re driving a fully-tuned machine.

Enabling Syntax Highlighting and Line Numbers

Vim supports syntax highlighting for virtually every language or config format under the sun.

Enable it globally:

syntax on

You can even specify filetypes manually:

:set filetype=sh
:set filetype=yaml

To enable line numbers:

:set number

For relative numbers (great for jumping around with 10j or 5k):

:set relativenumber

Line numbers help with navigation, debugging, and when reading logs or editing huge config files.


Advanced Vim Features for Power Users

Macros and Registers

Macros in Vim are like recorded keyboard shortcuts. You can record a sequence of commands and replay them as needed—ideal for repetitive tasks like formatting lines or adding annotations.

To record a macro:

To run the macro:

You can even do it multiple times:

10@a

Registers store text you’ve yanked, deleted, or recorded macros into. List them with:

:registers

Combining macros with registers allows for extremely powerful and repetitive editing capabilities—perfect for sysadmins processing logs or DevOps engineers updating repetitive YAML blocks.

Using Marks and Jumping Efficiently

Marks in Vim let you “bookmark” locations within your files so you can jump back instantly.

Use capital letters (e.g., mA) to mark positions across files. This is super helpful when debugging across multiple log files or editing several config files.

There are also special marks:

In combination with search and macros, marks make navigation lightning-fast.


Vim Plugins for DevOps and Admin Tasks

Vim plugins can supercharge your workflow. Here are a few must-haves:

These plugins are game-changers. With them, Vim text editor starts to feel like a full IDE—but lighter and faster.

Managing Plugins with Vim-Plug

Vim-Plug is the go-to plugin manager for Vim users.

Install it by adding this to your .vimrc:

call plug#begin('~/.vim/plugged')

Plug 'preservim/nerdtree'
Plug 'tpope/vim-fugitive'
Plug 'vim-airline/vim-airline'
Plug 'tpope/vim-commentary'
Plug 'ctrlpvim/ctrlp.vim'

call plug#end()

Then run:

:source ~/.vimrc
:PlugInstall

Boom—you’ve got plugins. Managing and updating them is now a breeze:

For DevOps folks who bounce between shell scripts, Dockerfiles, and YAMLs, plugins like these can make daily work way more efficient.


Practical DevOps Use Cases in Vim

Editing Configuration Files

From Nginx and Apache to systemd, editing config files is an everyday task for sysadmins. Vim is purpose-built for this.

Open your config:

sudo vim /etc/nginx/nginx.conf

Use:

Use folding (zc, zo) to hide or reveal config sections.

And remember:

sudo visudo

…opens the sudoers file in Vim with syntax checking. A life-saver.

Writing and Debugging Shell Scripts

Writing bash scripts in Vim is smooth when combined with the right .vimrc settings and plugins.

Enable auto-indenting:

filetype plugin indent on

Syntax check before running:

bash -n script.sh

Inside Vim, you can:

A well-configured Vim makes writing and debugging shell scripts feel intuitive and powerful.


Common Shortcuts Every Linux Admin Should Know

Time-Saving Commands and Combinations

Knowing the right shortcuts in Vim is like having cheat codes in a video game. These combos boost your productivity and make everyday tasks faster.

Here are some universal shortcuts every DevOps and Linux admin should have burned into muscle memory:

These shortcuts alone can cut your file editing time in half. Combined with practice, they make you a true Vim wizard.


Troubleshooting Vim Issues

Dealing with Common Errors and Mistakes

Let’s be real—Vim isn’t always sunshine and rainbows. When things go sideways, here’s how to get back on track.

Problem: Stuck in a mode

Problem: Vim doesn’t save the file

Problem: Syntax highlighting not working

:syntax on 
:filetype plugin indent on

Problem: Tabs are too wide or inconsistent

set tabstop=4 
set shiftwidth=4 
set expandtab

Problem: Accidentally opened Vim and don’t know how to quit

General Troubleshooting Tips:

With time, Vim becomes second nature—and you’ll troubleshoot it like a champ.


Mastering Vim Text Editor Over Time

Practice Strategies for Daily Use

Mastery doesn’t come overnight, but with consistent use, Vim transforms from overwhelming to indispensable.

Here’s how to build your skills daily:

  1. Use Vim text editor for everything—even small tasks.
  2. Practice modes: Get comfortable switching between Normal, Insert, and Visual modes.
  3. Set a goal per day:
    • Day 1: Learn navigation commands
    • Day 2: Practice yanking and pasting
    • Day 3: Master search and replace
  4. Use .vimrc tweaks to make Vim comfortable.
  5. Force yourself not to touch the mouse. Keep fingers on the keyboard.

Just like learning a musical instrument, small daily reps lead to huge long-term gains.

Resources to Learn More Vim

Want to level up further? Check out these resources:

The Vim community is massive and full of helpful people—don’t hesitate to explore it.


VIM Cheat Sheet

We’ve also included a one-page VIM Cheat Sheet in this article to give you quick access to all essential shortcuts. Perfect for printing or bookmarking for on-the-go reference!

VIM Cheat Sheet

Frequently Asked Questions (FAQs)

Q1: How can I remember all the Vim commands?
Start by mastering the basics and use cheat sheets. Over time, with repetition and usage, your muscle memory will take over. Tools like Vim Adventures also make learning fun.

Q2: Is Vim better than Nano for sysadmins?
Absolutely. While Nano is simpler, Vim is more powerful and efficient once learned. For tasks like config editing, scripting, and bulk changes, Vim is unbeatable.

Q3: Can I use Vim on Windows for DevOps tasks?
Yes! You can install Vim via Git Bash, Windows Subsystem for Linux (WSL), or even standalone packages. It works great on Windows when configured properly.

Q4: What’s the best way to learn Vim fast?
Force yourself to use it daily. Set learning goals, install a few helpful plugins, and gradually introduce new commands into your routine.

Q5: How do I recover files in Vim after a crash?
Use the swap recovery feature. Open the file, and Vim will prompt you to recover. You can also check ~/.vim/tmp or similar directories for backups.


Conclusion

Vim isn’t just a text editor. For DevOps and Linux admins, it’s a full-blown productivity engine that helps you work faster, think clearer, and handle everything from configs to code. It may be intimidating at first, but once you break through that learning curve, you’ll never want to go back.

In a world of GUIs and bloatware, Vim stands out by staying lean, clean, and wickedly fast. And the more time you invest, the more power it reveals. So if you’re serious about leveling up your Linux and DevOps skills, Vim is absolutely worth mastering.

Whether you’re editing crontabs, updating Dockerfiles, fine-tuning Nginx, or debugging Bash scripts, Vim will always have your back.

Searching for a skilled Linux admin? From server management to security, I ensure seamless operations for your Linux systems. Find out more on my Fiverr profile!

Struggling with AWS or Linux server issues? I specialize in configuration, troubleshooting, and security to keep your systems performing at their best. Check out my Fiverr profile for details.


Exit mobile version