Modes and Navigation

Summary: in this tutorial, you will learn master vim's modal editing system and learn to navigate files with motions, jumps, and text objects at lightning speed.

Modes and Navigation

Now that Vim is installed and configured, it's time to understand its core concept in depth: modes. Once you understand modes and learn how to move around a file efficiently, everything else in Vim clicks into place.

What you'll learn in this tutorial:

  • What each of Vim's four main modes does and when to use it
  • Multiple ways to enter and exit each mode
  • How to move around a file without using arrow keys or a mouse
  • How to move by words, lines, and pages (much faster than one character at a time)
  • How to search for text and jump to specific locations
  • How to set bookmarks and navigate back to them

Understanding Vim's Modes

Remember from the introduction: Vim has different "modes" for different tasks. Here's a complete reference:

ModeWhat It's ForHow to EnterHow to Leave
NormalNavigate and run commandsDefault when you open Vim(this is home base)
InsertType textPress i, a, o, or othersPress Escape
VisualSelect textPress v, V, or Ctrl-vPress Escape
Command-lineRun Vim commandsPress :Press Enter or Escape

Normal Mode — Your Home Base

Normal mode is the default mode — it's where you start when you open Vim, and where you return to between tasks. In Normal mode, every key is a command:

  • h j k l move your cursor (left, down, up, right)
  • dd deletes an entire line
  • yy copies ("yanks") a line
  • p pastes what you've copied or deleted
  • u undoes your last action

You'll spend most of your time here. Think of Normal mode as the "steering wheel" — you're navigating and controlling the editor.

Common beginner mistake: Trying to type text while in Normal mode. If you press keys and see weird things happening instead of text appearing, you're in Normal mode! Press i to switch to Insert mode first. If things get really confusing, press Escape to make sure you're in Normal mode, then try again.

Insert Mode — For Typing Text

Insert mode is where you actually type text, just like in any regular editor. There are several ways to enter Insert mode, and each one positions your cursor differently:

KeyWhat It DoesWhen to Use It
iStart typing before the cursorMost common — general text insertion
IStart typing at the beginning of the lineAdding something to the start of a line
aStart typing after the cursorAppending text after a character
AStart typing at the end of the lineAdding text to the end of a line
oCreate a new line below and start typingStarting a new line of text
OCreate a new line above and start typingInserting a line above your current position
sDelete the current character and start typingReplacing a single character with different text
SDelete the entire line and start typingRewriting a whole line

You'll know you're in Insert mode because you'll see -- INSERT -- at the bottom of the screen. Press Escape (or Ctrl-[, which does the same thing) to return to Normal mode.

Quick tips for beginners:

  • Use a (append) instead of i (insert) when you want to start typing after the current character, not before it.
  • Use A to quickly jump to the end of a line and start typing — it's much faster than manually navigating to the end first.
  • Use o to create a new line below — it's faster than going to the end of the line, pressing Enter, and then typing.

Visual Mode — For Selecting Text

Visual mode lets you highlight (select) text, then do something with the selection. It comes in three flavors:

KeyMode NameWhat It Selects
vCharacter-wiseIndividual characters (like click-and-drag in other editors)
VLine-wiseEntire lines at a time
Ctrl-vBlock-wiseA rectangular column of text (very unique to Vim!)

Once you've selected text, press a command key to act on it:

  • d — delete the selected text
  • y — copy ("yank") the selected text
  • > — indent the selected text to the right
  • < — unindent the selected text to the left
  • ~ — toggle uppercase/lowercase

Press Escape to cancel the selection and return to Normal mode.

Command-Line Mode — For Vim Commands

Press : (colon) from Normal mode to enter Command-line mode. A cursor appears at the bottom of the screen where you type commands:

:w              " Save the file
:q              " Quit Vim
:wq             " Save and quit
:e filename     " Open a different file
:!ls            " Run a terminal command (ls lists files in a directory)
:%s/old/new/g   " Find and replace all occurrences in the entire file

Press Enter to run the command, or Escape to cancel and go back to Normal mode.

Basic Movement — h, j, k, l

In Normal mode, you use these four keys instead of arrow keys to move your cursor:

     k          (up)
     ↑
h ←     → l     (left / right)
     ↓
     j          (down)

Why these keys instead of arrow keys? When the original vi editor was created in 1976, the computer keyboard had arrows printed on these exact keys. But the real benefit is ergonomic: these keys are on the "home row" (the middle row where your fingers naturally rest), so your hands never need to move away from the typing position.

# Practice: open any file and move around
vim ~/.vimrc
# Press j to move down one line
# Press k to move up one line
# Press h to move left one character
# Press l to move right one character

Arrow keys still work! You can absolutely use the regular arrow keys, especially while you're learning. But training yourself to use hjkl pays off over time — your hands stay in position, and these keys combine with editing commands in powerful ways you'll learn later.

Moving by Words (Much Faster!)

Moving one character at a time with h and l is slow. Instead, you can jump by whole words:

KeyWhere It Moves YouMemory Trick
wForward to the start of the next word"word forward"
bBackward to the start of the previous word"back a word"
eForward to the end of the current/next word"end of word"
geBackward to the end of the previous word"go to end, backwards"
WForward to start of next WORD (spaces only)Same as w but bigger jumps
BBackward to previous WORD (spaces only)Same as b but bigger jumps

What's the difference between w and W? Lowercase w treats punctuation as word boundaries — in the text hello-world, pressing w would stop at hello, then -, then world (three "words"). Uppercase W only uses spaces as separators — hello-world is treated as one single "WORD" and W jumps over the whole thing.

Try it yourself: Open any file and press w repeatedly to watch your cursor jump word by word. Then try b to go backward. You'll immediately see how much faster this is than pressing l over and over.

Moving Within a Line

These commands let you jump to specific positions on the current line:

KeyWhere It Moves YouPlain English
0The very beginning of the lineJump to column 1
^The first non-space characterJump to where the actual text starts (skips indentation)
$The very end of the lineJump to the last character
f{char}Forward to a specific characterf( jumps to the next ( on this line
F{char}Backward to a specific characterF( jumps back to the previous (
t{char}Forward to just before a charactert) stops one character before the next )
T{char}Backward to just after a characterLike F but stops one character short
;Repeat the last f/F/t/T jumpJump to the next match in the same direction
,Repeat in the opposite directionGo back if you overshot

Here's a practical example. Imagine your cursor is at the start of this line:

" Say this is your line: const result = calculateTotal(items);
 
0        " Cursor jumps to 'c' (very start of the line)
$        " Cursor jumps to ';' (very end)
f(       " Cursor jumps to the '(' character
;        " If there's another '(', cursor jumps to it
^        " Cursor jumps to 'c' (first non-space character)

Moving Through the Entire File

These commands let you jump around the whole file quickly — essential for large files:

KeyWhere It Moves YouPlain English
ggThe very first line of the fileJump to the top
GThe very last line of the fileJump to the bottom
42G or 42ggLine number 42Jump to a specific line
Ctrl-dDown half a pageScroll down quickly
Ctrl-uUp half a pageScroll up quickly
Ctrl-fDown a full pageScroll down faster
Ctrl-bUp a full pageScroll up faster
HTop of the visible screenMove to the High position
MMiddle of the visible screenMove to the Middle
LBottom of the visible screenMove to the Low position
%The matching bracketIf cursor is on (, jumps to matching )
gg       " Jump to the very first line
G        " Jump to the very last line
42G      " Jump to line 42
50%      " Jump to 50% through the file (the middle)

gg and G are your best friends when working with files. Need to check something at the top? Press gg. Need to see the end? Press G. Need to go back? Use Ctrl-o (jump back) — we'll cover that below.

Using Counts (Multiplying Any Motion)

Here's a powerful trick: you can put a number before almost any movement command to repeat it that many times:

5j       " Move down 5 lines (instead of pressing j five times)
3w       " Move forward 3 words
10l      " Move right 10 characters
2}       " Move forward past 2 blank lines (2 paragraphs)

The formula is: number + motion = repeated motion. This works with almost every movement command and is one of the things that makes Vim so fast.

Paragraph and Sentence Movement

These commands jump by larger chunks of text — useful for scrolling through code and documents:

KeyWhere It Moves You
{Up to the previous blank line (beginning of a paragraph or code block)
}Down to the next blank line (end of a paragraph or code block)
(Beginning of the previous sentence
)Beginning of the next sentence

In code files, { and } are especially handy because functions and blocks are usually separated by blank lines. Pressing } hops from one block to the next.

Searching for Text

Searching is one of the fastest ways to navigate. It lets you jump directly to any word in the file:

What to TypeWhat It Does
/word then EnterSearch forward (downward) for "word"
?word then EnterSearch backward (upward) for "word"
nJump to the next match (in the search direction)
NJump to the previous match (opposite direction)
*Instantly search for the exact word your cursor is on (forward)
#Instantly search for the word under your cursor (backward)
/function    " Search forward for the text "function"
n            " Jump to the next occurrence
N            " Jump back to the previous occurrence
*            " Instantly search for whatever word your cursor is on

The * key is incredibly useful! Place your cursor on any word and press * — Vim instantly highlights every occurrence of that word in the file and jumps to the next one. Press n to cycle through all the matches. This is one of the quickest ways to find all uses of a variable or function name.

Marks (Bookmarks in Your File)

You can set marks — like bookmarks — at positions in your file and jump back to them later:

ma           " Set a mark named 'a' at your current cursor position
'a           " Jump back to the LINE where mark 'a' is located
`a           " Jump back to the EXACT position (line and column) of mark 'a'

Think of marks like sticking a Post-it note on a specific line. You can move away, do other things, and then flip right back to that exact spot.

You can use any lowercase letter for marks (ma, mb, mc, ... mz), giving you up to 26 bookmarks.

Some special marks that Vim creates automatically:

MarkWhat It Remembers
'' (two single quotes)Where you were before your last big jump
'.Where you made your last edit
'^Where you last left Insert mode

The Jump List (Browser-Like Back/Forward)

As you navigate around — searching, jumping to marks, going to specific lines — Vim remembers everywhere you've been, like a browser's history. You can go back and forward through this history:

KeyWhat It Does
Ctrl-oJump back to where you were before (like the browser Back button)
Ctrl-iJump forward again (like the browser Forward button)
:jumpsShow your entire jump history as a list

This is extremely useful! You can jump to a function definition with /functionName, read it, then press Ctrl-o to go right back to where you were before.

Summary

Here's what you've learned:

  • Vim has four main modes: Normal (commands), Insert (typing), Visual (selecting), Command-line (: commands)
  • Normal mode is the default — every key is a command, not text
  • Enter Insert mode with i, a, o (and others) and leave with Escape
  • hjkl replace arrow keys: left, down, up, right (keeping your hands on the home row)
  • Word motions: w (next word), b (back a word), e (end of word)
  • Line motions: 0 (start of line), $ (end of line), f{char} (find character)
  • File motions: gg (top of file), G (bottom), Ctrl-d/Ctrl-u (scroll half-page)
  • Searching: /pattern (search forward), n/N (next/previous match), * (search word under cursor)
  • Put a number before any motion to repeat it: 5j = move down 5 lines
  • Marks (ma to set, 'a to jump back) let you bookmark positions
  • Jump list (Ctrl-o back, Ctrl-i forward) works like browser history for your cursor

In the next tutorial, you'll learn to combine these movements with editing commands — this is where Vim's real power shines.

🏋️

Practice: Navigation Drill

Open any file with some content (like your ~/.vimrc) and practice these tasks:

  1. Jump to the top of the file with gg, then to the bottom with G
  2. Go to line 10 with 10G, then line 5 with 5G
  3. Search for a word by typing /set and pressing Enter, then use n and N to cycle through matches
  4. Move across a line using w, b, and e
  5. Jump to a specific character with f" (finds the next quotation mark on the line)
  6. Set a mark with ma, move somewhere else, then jump back with 'a
  7. Use Ctrl-o to go back through your jump history
Show Solution
# Open your vimrc (which should have plenty of content to navigate)
vim ~/.vimrc
 
# 1. Jump to top and bottom
# Press gg — cursor jumps to line 1 (the very top)
# Press G — cursor jumps to the last line (the very bottom)
 
# 2. Go to specific lines
# Type 10G — cursor jumps to line 10
# Type 5G — cursor jumps to line 5
 
# 3. Search for text
# Type /set and press Enter — cursor jumps to the first "set"
# Press n — jumps to the next "set"
# Press n again — keeps going to the next one
# Press N — jumps BACK to the previous "set"
 
# 4. Move by words
# Press w — cursor jumps to the start of the next word
# Press w again — keeps jumping word by word
# Press b — cursor jumps back to the previous word
# Press e — cursor jumps to the end of the current word
 
# 5. Find a character on the line
# Press f" — cursor jumps to the next " on this line
# Press ; — jumps to the next " after that
# Press , — jumps back to the previous "
 
# 6. Set and use a mark
# Press ma — sets a bookmark called 'a' at your current position
# Move around the file (try gg, G, /word, etc.)
# Press 'a — cursor jumps right back to where you set the mark!
 
# 7. Jump history
# Navigate around the file (search, gg, G, etc.)
# Press Ctrl-o — cursor jumps back to where you were before
# Press Ctrl-o again — goes back another step
# Press Ctrl-i — jumps forward again
 
# When done, press :q to quit (or :q! if you accidentally edited something)
Was this page helpful?
SR

Written by the ShellRAG Team

The ShellRAG editorial team writes practical, beginner-friendly Vim tutorials with tested code examples and real-world use cases. Every article is technically reviewed for accuracy and updated regularly.

Learn more about us →