What Is Vim?

Vim is a keyboard-driven text editor commonly used in terminals, remote servers, and development environments. Its defining idea is modal editing: the same keys perform different jobs depending on the current mode.

In Normal mode, keys move, delete, copy, and change text. Insert mode is for typing. Command-line mode handles actions such as saving, quitting, and search-and-replace. This may feel unusual at first, but it lets experienced users combine short commands without constantly reaching for a mouse.

When in doubt, press Esc once or twice to return to Normal mode.

Open Vim

Open a terminal or command prompt, then use the command that fits the task:

CommandWhat it does
vimOpen Vim with an empty buffer.
vim notes.txtOpen an existing file or begin a new file with that name.
vim file1 file2Open multiple files as separate buffers.
vi notes.txtOpen the system's Vi editor. It may start Vim in a compatibility mode or use another Vi implementation.
vim --versionConfirm Vim is installed and inspect its version and compiled features.
vimtutorOpen Vim's interactive practice lesson when it is installed.

Use vim when it is available so this guide's behaviour matches more closely. If the command is missing, install Vim through the operating system's normal package manager or official installer.

Understand the Main Modes

ModePurposeHow to enterHow to leave
NormalNavigate and run editing commands.Vim starts here; press Esc from most other modes.Use a key for another mode, such as i, v, or :.
InsertType ordinary text.i, a, o, I, or A.Esc
VisualSelect characters, lines, or blocks.v, V, or Ctrl+v.Esc
Command-lineSave, quit, configure, replace, and run longer commands.:, /, or ? from Normal mode.Press Enter to run or Esc to cancel.
ReplaceOverwrite text as you type.REsc

Your First Edit from Start to Finish

  1. Open a practice file with vim practice.txt.
  2. Press i to enter Insert mode.
  3. Type two or three lines of text.
  4. Press Esc to return to Normal mode.
  5. Type :w, then press Enter to save.
  6. Type :q, then press Enter to quit.

If Vim reports unsaved changes, use :wq to save and quit or :q! only when those changes should be discarded.

Move Around in Normal Mode

KeyMovementExample use
h / One character left.Correct the previous character.
j / One display line down.Move to the line below.
k / One display line up.Return to the line above.
l / One character right.Move toward the end of a line.
wBeginning of the next word.3w moves forward three words.
bBeginning of the previous word.Jump back to edit an earlier word.
eEnd of the current or next word.de deletes through a word ending.
0First character of the line.Return to column zero.
^First non-blank character of the line.Jump past indentation.
$End of the line.d$ deletes to the line end.
ggFirst line of the file.Return to the top.
GLast line of the file.Jump to the bottom.
25GLine 25.Move to a known line number.
f{char} / F{char}Find a character to the right or left on the current line.f: jumps onto the next colon.
t{char} / T{char}Move just before a character to the right or just after one to the left.dt, deletes up to—but not including—the next comma.
%Jump to a matching bracket or another supported paired item.Move between the opening and closing bracket around a block.
Ctrl+d / Ctrl+uScroll about half a screen down or up.Read a long file without making full-page jumps.
Ctrl+f / Ctrl+bPage forward or backward.Move through a long file quickly.
H / M / LMove to the top, middle, or bottom line currently visible.Reach a visible area without counting lines.

Enter Text Efficiently

KeyWhat it doesExample
iInsert before the cursor.Place the cursor on a word and type at that position.
aAppend after the cursor.Add a character after the current one.
IInsert at the first non-blank character.Add text before an indented line's content.
AAppend at the end of the line.Add a sentence ending or comment.
oOpen a new line below and enter Insert mode.Add the next item in a list.
OOpen a new line above and enter Insert mode.Insert a heading before the current line.
REnter Replace mode.Overwrite a run of existing characters.
EscReturn to Normal mode.Finish typing before navigation or commands.

Delete, Change, Copy, and Paste

CommandActionExample use
rReplace the character under the cursor.Press rx to replace it with x.
xDelete the character under the cursor.Remove one unwanted character.
ddDelete the current line.3dd deletes three lines.
DDelete from the cursor through the end of the line.Remove the remainder of a sentence.
dwDelete from the cursor through a word motion.Remove the next word-sized section.
cwChange a word motion and enter Insert mode.Replace a word without a separate insert command.
yyYank, or copy, the current line.2yy copies two lines.
pPut copied or deleted text after the cursor or below the line.Copy a line with yy, move, then press p.
PPut text before the cursor or above the line.Paste a copied line above the current one.
uUndo the latest change.Reverse an accidental deletion.
Ctrl+rRedo an undone change.Restore a change after pressing u.
.Repeat the last change.Apply the same edit at another location.

Understand Vim Registers

When Vim yanks or deletes text, it stores that text in a register. An ordinary p uses the unnamed register, while a double quote followed by a register name lets you choose a particular one.

ExampleWhat it does
"0pPut the most recently yanked text from register 0, even if a later deletion changed the unnamed register.
"+yAfter selecting text in Visual mode, yank it to the system clipboard register. In Normal mode, follow y with a motion, such as "+yw.
"+pPut text from the system clipboard into the file.

The + register depends on Vim being built with clipboard support and having access to the desktop clipboard. Check :version when these commands do not work in a terminal or remote session.

The Operator-and-Motion Idea

Many Vim commands follow a small grammar: operator + motion. The operator says what to do, and the motion says how far.

OperatorMeaningCombined examples
dDelete.dw, d$, dG
cChange, then enter Insert mode.cw, c$
yYank, or copy.yw, y$

Counts can come before an operator or motion: 3w moves three words, 2dd deletes two lines, and d3w deletes across three word motions. Learn the pieces instead of memorising every possible combination.

Select Text with Visual Mode

KeySelectionTypical next step
vCharacter-wise selection.Move to expand, then press y, d, or c.
VWhole-line selection.Select several lines for copying or indentation.
Ctrl+vRectangular block selection.Edit aligned columns of text.
> / <Indent or unindent the selection.Adjust a selected code block.
=Reindent according to Vim's rules.Use gg=G to reindent the whole file.

Search and Replace

CommandPurpose
/textSearch forward for text.
?textSearch backward for text.
n / NRepeat the search in the same or opposite direction.
*Search forward for the word under the cursor.
:%s/old/new/gReplace every old match with new on every line.
:%s/old/new/gcPerform the same replacement but ask for confirmation.

Vim search patterns use a regex flavour with its own escaping rules. Preview a search with /pattern before using it in a file-wide replacement, and add the c flag when the change needs review.

Turn On Helpful Display Settings

Use :set commands to change the current Vim session:

:set number
:set relativenumber

number shows each line's actual number. relativenumber shows nearby lines by their distance from the cursor, which makes commands such as 5j or 3dd easier to plan. Use :set norelativenumber to turn the relative display off.

Save and Quit

CommandResult
:wWrite changes to the current file.
:w new-name.txtWrite the current buffer's contents to another file. This does not necessarily change the filename associated with the current buffer.
:saveas new-name.txtSave under a new filename and make it the current buffer's filename.
:qQuit when there are no unsaved changes.
:wqWrite changes and quit.
:xWrite only when changed, then quit.
ZZNormal-mode shortcut similar to :x.
:q!Quit and discard unsaved changes in the current buffer.
Use :q! deliberately. The exclamation mark forces the action and discards changes that have not been saved elsewhere.

Work with Multiple Files

CommandPurpose
:e FILEEdit another file in the current window.
:lsList open buffers.
:bnext / :bpreviousMove between buffers.
:buffer NUMBEROpen a listed buffer by number.
:split FILEOpen a horizontal split.
:vsplit FILEOpen a vertical split.
Ctrl+w then h/j/k/lMove between split windows.

Keep Small Settings in .vimrc

Session settings disappear when Vim exits. Put deliberate defaults in your Vim startup file—commonly ~/.vimrc on Unix-like systems or _vimrc on Windows—so they are applied each time Vim starts:

set number
set ignorecase
set smartcase
set incsearch

This shows line numbers, ignores case for ordinary searches, restores case sensitivity when the search contains an uppercase letter, and displays matches while a search is being typed. Run :version to see the startup-file locations used by the installed Vim. Begin with a small configuration like this; plugins are not required to learn the editor.

Get Help Inside Vim

:help
:help dd
:help :w
:help pattern

Help topics are tied to the installed Vim version, which makes them especially useful for checking exact behaviour. Press Ctrl+] on a highlighted help tag to follow it and Ctrl+o to return.

Common Beginner Mistakes

  • Typing commands while still in Insert mode. Press Esc first.
  • Forgetting that commands are case-sensitive: i and I do different things.
  • Pressing :q! without realising it discards unsaved work.
  • Using arrow keys exclusively and never learning word, line, and file motions.
  • Copying a configuration file full of plugins before learning core editing behaviour.
  • Ignoring a swap-file warning without first checking whether another Vim session is editing the file or whether recovery is needed.

A Ten-Minute Practice Routine

  1. Open vim practice.txt and type five short lines with i.
  2. Use w, b, 0, $, gg, and G to navigate.
  3. Copy one line with yy and paste it with p.
  4. Change a word with cw, repeat the edit elsewhere with ., then undo and redo it.
  5. Search with /text and move between results with n.
  6. Save with :w, make one disposable change, then leave with :q!.

Quick Recap

  • Normal mode is for commands; Insert mode is for typing.
  • Motions describe where to move, and operators describe what to do.
  • Counts, operator-motion combinations, and the repeat command make edits efficient.
  • Visual mode selects text, while Command-line mode handles saving, quitting, and replacements.
  • Esc, u, :w, and :q! are the essential recovery controls for a beginner.
  • vimtutor and :help are the best next steps after this page.