Vim Keybindings Guide for Beginners

By
Vladimir Kaplarevic
Published:
June 26, 2025
Topics:

Originally, Vim was created to run on terminals without arrow keys or mouse support. The entire editor can be used from the home row of the keyboard with minimal hand movement.

That's why many of its keybindings feel unusual by today's standards.

Learn how Vim keybindings work, internalize them, and you'll be able to move faster in Vim than you would in most conventional editors.

Guide to Vim keybindings for beginners.

What Is a Vim Keybinding?

Vim keybindings are keyboard shortcuts, a physical key or sequence of keys you press to perform a specific action within the Vim text editor. These keybindings work like in any other system, except that in Vim, they are not optional.

The command-line interface (CLI) version of the editor lacks a toolbar and does not support drag-and-drop features. Even simple actions, such as opening a file, deleting a word, or copying a line are all performed via the keyboard using dedicated bindings.

Note: Vim is not the default text editor in Ubuntu 24.04. Find out how to install the latest Vim version on Ubuntu.

Why Use Vim Keybindings?

Using Vim keybindings has several practical advantages, which include:

  • Full keyboard control. Hands always stay on the keyboard, allowing users to issue direct commands for nearly any action instantly. There is no need for repetitive mouse movements or excessive clicking.
  • No wasted motion. Keys are positioned to minimize finger movement. Users who internalize Vim keybindings can edit text or code faster and with greater precision than in most editors.
  • Reduced strain. Users can perform tasks with less physical movement and strain. This increases focus and reduces fatigue during long editing sessions.
  • Consistency. Workflows are more predictable and uniform because the same key-driven interface applies regardless of the task.
  • Customization and automation. Users can map frequently used actions to custom keybindings and incorporate complex sequences into scripts to automate repetitive tasks.

Note: Compare Vim with other cross-platform text editors for Linux, Windows, and macOS to more clearly evaluate its benefits.

How to Use Vim Keybindings?

In most editors, pressing a key usually types a character. In Vim, the key's function depends on the keybinding associated with it and the current mode Vim is operating in.

Vim Modes

Switching between different modes is fundamental to how Vim works and is just as important as hitting the correct key.

For example, in Normal mode, pressing d starts a delete command. In Insert mode, the same key just types the letter d. Users often navigate through a text document in Normal mode, delete a section, switch to Insert mode to type replacement text, and then return to Normal mode to continue navigating.

Vim displays the current mode in the lower-left corner of the terminal window, except for Normal mode, which shows no prompt.

Vim in Insert mode.

The following table lists the most commonly used Vim modes:

ModeDescriptionShortcut to Enter
Normal ModeThe default mode for navigating and selecting text, and running commands. You cannot type text in this mode.Esc
Insert ModeType and edit text directly, like in any other text editor. Use this mode when adding new content.i, I, a, A, o, O
Visual ModeThis mode allows users to select text, similar to clicking and dragging with a mouse, only using the keyboard.v (character), V (line), Ctrl+v (block)
Command-Line ModeRun commands to save changes, exit files, or find and replace text in Vim.:
Replace ModeOverwrite existing text one character at a time.R
Select Mode
(rarely used)
Similar to Visual mode, but mimics the way text is selected in graphical editors.Depends on the Vim build.

Combining Keybindings

Many Vim commands consist of a single key, but more powerful operations combine three elements:

  • Operator. Defines what action to perform.
  • Count (Optional). A numerical prefix that specifies how many times to apply the motion.
  • Motion. Tells Vim the scope and direction in which the action will be performed.

Users can combine operators, counts, and motions to perform complex actions by entering a sequence of keys in rapid succession.

For example, the following keybinding (in Normal mode) deletes the next four words after the cursor:

d4w
KeybindingDescription
dThe delete operator. Tells Vim to remove text based on the motion.
4Repeats the forward motion (w) 4 times.
wMove forward by one word at a time. Repeat the motion four times due to the count value (4).

The following sections explain how to navigate and edit text using keybindings in different Vim modes.

Navigating Using Keybindings

Normal mode is the default mode for navigating and manipulating text in Vim. Most keybindings in this mode are single-letter commands.

Moving by Character or Line

Use the following keys to move the cursor left, right, up, and down:

KeyDescription
hMove the cursor one character left.
lMove the cursor one character right.
jMove the cursor one line down.
kMove the cursor one line up.

Moving by Word or Sentence

The following commands enable users to traverse larger sections of text in one go:

KeyDescription
wMove forward to the start of the next word.
WMove forward to the start of the next word and ignore punctuation.
bMove back to the beginning of the current word.
BMove back to the beginning of the current word and ignore punctuation.
eMove forward to the end of the current word.
geMove backward to the end of the previous word.
)Move forward to the start of the next sentence.
(Move backward to the start of the previous sentence.

Moving within a Line

These keys allow users to move the cursor to specific positions on the screen or the current line:

KeyDescription
0Move to the beginning of the current line.
$Move to the end of the current line.
^Move to the first non-whitespace character.

Moving by Paragraph

Use the following commands to move between paragraphs:

KeyDescription
}Move to the beginning of the next paragraph.
{Move to the beginning of the previous paragraph.

Search for Patterns

Vim has a built-in search feature that allows users to move to matching text using simple pattern-based commands:

KeyDescription
/ followed by the search patternSearch forward for a string or pattern.
? followed by the search patternSearch backward for a string or pattern.
nRepeat the last search in the same direction.
NRepeat the last search in the opposite direction.
*Search forward for the word under the cursor.
#Search backward for the word under the cursor.

Note: Searching is one of the most common actions in Vim. Learn the basics and explore different strategies and advanced search commands in Vim.

Moving Across the File

Use the following commands to move to the beginning, end, or a specific line of the file:

KeyDescription
ggMove to the beginning of the file.
GMove to the end of the file.
nGMove to line n (e.g., 42G jumps to line 42).

Moving by Half or Full Pages

To move through large documents, you can move by half or full pages in one go:

KeyDescription
Ctrl-dScroll down half a screen.
Ctrl-uScroll up half a screen.
Ctrl-fScroll forward one full screen.
Ctrl-bScroll backward one full screen.

Note: When a command is written as Ctrl-u, it means press and hold the Ctrl key and press u at the same time.

Editing Text Using Keybindings

Text editing in Vim is primarily performed in Normal mode. Many of the commands are simple key combinations of operators, motions, and optional counts.

Deleting Text

Use these commands to remove characters, words, lines, or sections of text:

KeybindingDescription
xDelete the character under the cursor.
XDelete the character before the cursor.
ddDelete the entire current line.
d$Delete from the cursor to the end of the line.
d0Delete from the cursor to the beginning of the line.
d4wDelete the next 4 words.

Note: Explore our detailed guide to learn the various ways to delete lines in Vim.

Copying (Yanking) Text

Copying in Vim is called yanking. These commands copy lines, words, or ranges of text into the unnamed register, which is Vim's default clipboard:

KeybindingDescription
yyCopy the current line.
y$Copy from the cursor to the end of the line.
y0Copy from the cursor to the beginning of the line.
y2jCopy the current line and the 2 lines below it.
ywCopy the next word.

Pasting Text

After copying or deleting text, use the following commands to paste relative to the cursor position:

KeybindingDescription
pPaste after the cursor or the current line.
PPaste before the cursor or the current line.

Changing Text

Use the following commands to delete the selected text and switch to Insert Mode to enter replacement content.

KeybindingsDescription
cwChange the word from the cursor onward.
CChange from the cursor to the end of the line.
ccChange the entire current line.
ci"Change everything inside the double quotes.
ci(Change everything inside the parentheses.

Undo, Redo, and Repeat

Undo mistakes, redo changes, or repeat the last command with these keybindings:

KeybindingsDescriptions
uUndo the last change.
Ctrl-rRedo the last undone change.
.Repeat the last command exactly as it was run.

Note: The following text provides detailed insight into how undo, redo, and repeat commands in Vim work.

Indenting

The following commands allow you to adjust or auto-format indentation to, for example, control code alignment:

KeybindingDescription
>>Indent the current line to the right.
<<Indent the current line to the left.
= followed by a motionAuto-indent a range (e.g., gg=G indents the entire file).

Keybindings in Insert Mode

Insert mode allows users to type and edit text directly, just like in a regular text editor. You enter Insert mode from Normal mode and return by pressing Esc.

Access Insert Mode

Vim provides multiple ways to enter Insert mode, which differ based on the cursor position:

KeybindingsDescription
iInsert before the cursor.
IInsert at the beginning of the line.
aAppend after the cursor.
AAppend at the end of the line.
oOpen a new line below and enter Insert Mode.
OOpen a new line above and enter Insert Mode.

Deleting in Insert Mode

The following keys enable users to delete or adjust text while in Insert Mode:

KeybindingDescription
BackspaceDelete the character before the cursor.
Ctrl-wDelete the previous word.
Ctrl-uDelete from the cursor to the start of the line.
Ctrl-hAlternative to Backspace.

Completion and Assistance

Use these keys for autocompletion based on existing words or keywords.

KeybindingDescription
Ctrl-nAutocomplete the next match.
Ctrl-pAutocomplete the previous match.

Exit Insert Mode

Use the following commands to return to Normal Mode after editing the content in Insert Mode:

KeybindingDescription
EscReturn to Normal Mode.
Ctrl-[Alternative to Esc.

Keybindings in Visual Mode

Visual mode is used for selecting and manipulating blocks of text. Once the text is selected, you can apply most operators (like delete, copy, or change) directly to the selection. This mode is handy when motions are not precise enough to define the editing range.

Entering Visual Mode

There are three types of Visual mode depending on the range of text you need to edit. Use one of the following commands to enter Visual mode, depending on the range of text you need to edit:

KeybindingsDescription
vStart character-wise selection.
VStart line-wise selection.
Ctrl-vStart block-wise selection.

Editing in Visual Mode

Once you've made a selection, apply regular Normal mode commands directly to the highlighted area:

Keybindings Description
dDelete the selected text.
yCopy the selected text.
cChange the selected text and enter Insert Mode.
>Indent the selection.
<Unindent the selection.
~Toggle the case of the selected characters.
:Enter command-line mode only for the selected text.

These are the same operators used in Normal mode, but now act only on the selected text. There is no need to use counters and motion components.

Keybindings in Command-Line Mode

Command-line mode in Vim is used to enter commands for saving, quitting, searching, replacing text, and more.

Entering Command-Line Mode

While in Normal Mode, enter the following command to switch to Command-line Mode:

KeybindingDescription
:Enter command-line mode.
/Start a forward search.
?Start a reverse search.

Common Commands

These are the most frequently used command-line operations:

KeybindingDescription
:wSave the current file.
:qQuit Vim.
:wqSave the file and quit.
:q!Quit without saving changes.
:e <filename>Open a new file.
:helpOpen Vim help.

Find and Replace

In Vim, users can quickly find and replace all occurrences of a pattern using a single command:

KeybindingDescription
:s/old_text/new_text/Replace the first occurrence of old_text with new_text in the current line.
:s/old_text/new_text/gReplace all old_text with new_text in the current line.
:%s/<strong><code>old_text/new_text/gReplace all old_text with new_text in the entire file.
:%s/<strong><code>old_text/new_text/gcReplace all instances of old_text with new_text throughout the entire file, prompting confirmation for each change.

Editing and History

These keys help you navigate and edit within the command-line prompt itself:

KeybindingsDescription
q:Open the command-line history window.
q/Open the search history window.
arrow up key / arrow down keyCycle through previous command-line history.
Ctrl-bMove to the beginning of the command line.
Ctrl-eMove to the end of the command line.
Ctrl-wDelete the previous word.
Ctrl-uDelete from the cursor to the beginning of the line.
Ctrl-r"Insert the last copied text from the unnamed register into the command line.

Keybindings in Replace Mode

Replace mode in Vim is similar to Insert mode, but instead of inserting new text and shifting existing content forward, it overwrites characters at the cursor position. It is useful when you want to substitute characters directly without deleting or shifting the line.

A typical Replace mode workflow includes the following actions:

  • Start in Normal mode at the cursor position.
  • Press R to enter Replace mode.
  • Type a replacement string to overwrite existing text.
  • Press Esc to return to Normal mode.

Use Replace mode for quick corrections to avoid the need to delete text in Normal mode and then reinsert it in Insert mode.

Keybindings in Select Mode

Select mode is not available by default in many terminal-based Vim setups. It is similar to Visual mode, but instead of waiting for you to issue an operator command, for example, d or y, typed characters immediately replace the selected text, just like in GUI-based text editors.

FeatureVisual ModeSelect Mode
Selection BehaviourWaits for an operator (d, y, etc.)Typing replaces the selected text.
Mode Shown in Status--Visual----Select--
Default in Vim CLIYesNo

Select mode is rarely used in command-line Vim, and many users may never encounter it in daily workflows. However, it's helpful to understand how it differs from other modes.

Programing-Specific Keybindings

Vim keybindings are particularly useful when writing or editing code. Many of these work out of the box in Normal or Visual mode, while others rely on optional features like filetype detection or external plugins.

Source code is often structured around text objects, functions, code blocks, and indentation, which Vim can operate on directly. The following keybindings help users navigate codebases and perform repetitive edits with precision.

Text Objects

Text objects allow you to act on logical units of code like words, quotes, parentheses, and blocks:

KeybindingDescription
ci\"Change the content inside the double quotes.
di{Delete the content inside the curly brackets.
va(Visually select a block, including the parentheses.
yi'Copy the content inside the single quotes.
da[Delete the entire bracketed expression, including the brackets.

Function and Block Navigation

Use the following keybindings to move between functions or block structures in code:

KeybindingDescription
[[Jump to the beginning of the previous function.
]]Jump to the beginning of the next function.
{ and }Jump between code blocks (based on blank lines or indentation).
%Jump to the matching bracket, parentheses, or brace.

Folding Code

Code folding lets you collapse or expand code blocks to focus on important sections. This is especially useful in large files or while debugging.

KeybindingDescription
zaToggle folder under the cursor.
zcClose fold.
zoOpen fold.
zMClose all folds.
zROpen all folds.

Macros

Vim allows users to record short sequences of actions to automate repetitive tasks, so-called macros.

KeybindingDescription
q<register>Start recording a macro into the given register. For example, enter qa to record a macro in the a register.
qStop recording the macro.
@<register>Play the macro stored in the listed register. For example, @a plays the macro stored in the a register.
@@Repeat the last played macro.

Note: When working with code, it is sometimes helpful to display line numbers. This guide explains how to show or hide line numbers in Vim.

Additional Vim Keybindings - Quick Reference

This quick-reference table summarizes additional useful keybindings that do not appear in the main instructional sections above.

CategoryKeybindingDescription
NavigationHMove to the top of the screen.
MMove to the middle of the screen.
LMove to the bottom of the screen.
zzCenter the current line in the middle of the screen.
ztMove the current line to the top of the screen.
zbMove the current line to the bottom of the screen.
Ctrl-yScroll the screen up one line.
Ctrl-eScroll the screen down one line.
Formattinggg=GAuto-indent the entire file.
JJoin the current line with the next one and remove the new line.
~Toggle the case (uppercase/lowercase) of the character under the cursor.
g~wToggle case of the next word.
guuMake the current line lowercase.
gUUMake the current line uppercase.
gqqReformat the current line to fit within the textwidth setting.
Insert ModeCtrl-oTemporarily switch to Normal mode for one command.
Ctrl-r"aInsert content from register a.
Ctrl-x Ctrl-lInsert a whole line completion.
Ctrl-x Ctrl-fInsert a filename completion from a file system.
Visual ModegvReselect the last visual selection.
r<character>Replace all selected characters with the specified character. For example, to replace each selected character with 3, enter r3.
=Auto-indent the selection.
:Open the command-line mode with a selection range prefilled.
gUConvert the selection to uppercase.
guConvert the selection to lowercase.
Replace ModeREnter Replace mode.
r<character>Replace the character under the cursor.
Text Objectsvi(Select inside the parentheses.
va'Select the string around the single quotes.
va"Select the string around the double quotes.
ci]Change inside the square brackets.
di>Delete inside the angle brackets.
Macros:let @a='...'Define a macro directly using a command
:regShow contents of all registers.
Search and Patterns*Search forward for the word under the cursor.
#Search backward for the word under the cursor.
:nohClear the search highlight.
:vimgrepSearch across multiple files using Vim's grep.
:cnJump to the next match in the quickfix list.
:cpJump to the previous match in the quickfix list.
Command-Line:xSave and quit if changes exist.
:!<command>Run a shell command without leaving Vim.
:r !<command>Insert the output of a shell command below the current line.
:cd <directory_name>Change the working directory inside Vim.
:pwdPrint the current working directory.
:lsList all open buffers.
:sp <file_name>Open the file in a horizontal split.
:vs <file_name>Open the file in a vertical split.
:tabnew <file_name>Open a new tab and load the specified file.

Note: Vim has a steep learning curve, but you can enhance your editing experience with syntax highlighting and customizable interface colors. Read our guide to learn how to configure Vim color schemes.

Conclusion

Vim is not known as a beginner-friendly text editor. Use the commands outlined in this guide to practice, and over time, many of these keybindings will become part of your muscle memory.

If you work with code, learning Git from the command line pairs naturally with Vim.

Was this article helpful?
YesNo