H
10Corp Premium Hosting

The vim Text Editor — Quick Reference

Last Updated: 2025-01-01 3 min read

Overview

vim is a powerful text editor available on virtually every Linux system. While it has a learning curve, knowing the basics allows you to quickly edit configuration files, scripts, and other text files directly on your server without needing to download, edit locally, and re-upload.

Opening a File

vim filename.txt          # Open an existing file (or create a new one)
vim +25 filename.txt      # Open and jump to line 25
vim +/search filename.txt # Open and jump to first occurrence of "search"

Vim’s Two Main Modes

Vim operates in two primary modes:

ModePurposeHow to enter
Normal modeNavigate, delete, copy, pastePress Esc
Insert modeType and edit textPress i, a, o, or I, A, O

When you open a file, you start in Normal mode. Press i to start typing (Insert mode), and press Esc to go back to Normal mode.

Essential Commands

Entering Insert Mode

KeyAction
iInsert before cursor
aInsert after cursor
oOpen a new line below and enter insert mode
OOpen a new line above and enter insert mode
IInsert at beginning of line
AInsert at end of line

Saving and Quitting (from Normal Mode)

CommandAction
:wSave (write) the file
:qQuit (fails if unsaved changes exist)
:wqSave and quit
:q!Quit without saving (discard changes)
ZZSave and quit (shortcut)
KeyAction
h j k lMove left, down, up, right
Arrow keysAlso work for navigation
0Jump to beginning of line
$Jump to end of line
ggGo to first line of file
GGo to last line of file
:25Jump to line 25
Ctrl+FPage down
Ctrl+BPage up
wJump forward one word
bJump backward one word

Editing (Normal Mode)

KeyAction
xDelete character under cursor
ddDelete entire current line
5ddDelete 5 lines
yyCopy (yank) current line
5yyCopy 5 lines
pPaste below cursor
PPaste above cursor
uUndo last change
Ctrl+RRedo

Searching

CommandAction
/patternSearch forward for “pattern”
?patternSearch backward for “pattern”
nGo to next match
NGo to previous match

Search and Replace

:s/old/new/        # Replace first occurrence on current line
:s/old/new/g       # Replace all occurrences on current line
:%s/old/new/g      # Replace all occurrences in entire file
:%s/old/new/gc     # Replace all with confirmation for each match

Practical Hosting Examples

Edit your WordPress config

vim /home/username/public_html/wp-config.php

Edit .htaccess

vim /home/username/public_html/.htaccess

View a file read-only

vim -R /etc/nginx/nginx.conf

Or use view which is equivalent:

view /etc/nginx/nginx.conf

Quick Survival Guide

If you’re stuck in vim, remember:

  1. Press Esc (maybe a couple of times) to get back to Normal mode
  2. Type :q! and press Enter to quit without saving
  3. Type :wq and press Enter to save and quit

Tips

  • If vim feels overwhelming, try nano instead — it’s a simpler editor with on-screen shortcut hints.
  • Use :set number in Normal mode to display line numbers.
  • Use :set paste before pasting text from your clipboard to preserve formatting.
  • Practice on a test file before editing production configs.
Tags: ssh linux vim text-editor

Still need help?

Our support team is available 24/7 to assist you.