Vim Shortcut Practice

How to use
STARTSTOP
*Toggle input mode: ctrl + shift + alt + space
PRE
NEXT
Exclude this question from the list
Restore excluded questions
Get a URL for the current exclusions
https://command-lab.com
Copy
Guide mode
Repeat mode

*Recommended browser: Google Chrome

PUSH ENTER
If you enjoy this site, please share it — it keeps us motivated to keep improving!

Vim Keyboard Shortcuts: Full List (101 shortcuts)

Every Vim keyboard shortcut used in the practice above, listed in full. Each row shows the Windows and Mac keys plus a short explanation of what the shortcut does. Find one you want to learn, then drill it above until your fingers remember it.

Motion

Vim — Motion
Action Shortcut What it does
Move to upper character k Moves the cursor up one line in normal mode. It lets you navigate without leaving the home row, making it one of the first movements to learn in Vim.
Move to lower character j Moves the cursor down one line in normal mode. It lets you move vertically without reaching for the arrow keys, forming the basic building block of up/down navigation.
Move to the right character l Moves the cursor one character to the right in normal mode. It handles the rightward direction of the h/j/k/l movement keys and is used for fine positioning within a line.
Move to the left character h Moves the cursor one character to the left in normal mode. It handles the leftward direction of h/j/k/l and is commonly used when backtracking within a line to make a fix.
Move to upper character on display g k Moves up one displayed (wrapped) line rather than one logical line. Unlike k, it follows the on-screen wrapping, which is useful when a long line spans multiple visual rows.
Move to the lower character on the display g j Moves down one displayed (wrapped) line rather than one logical line. It is useful when editing a long line and you want the cursor to follow the visible wrapping.
Move to beginning of line (first character) ^ Moves the cursor to the first non-blank character of the line in normal mode. Even on an indented line, it jumps straight to where the actual text begins, past the leading whitespace.
Move to beginning of line (first column) 0 Moves the cursor to column 1 of the line (the absolute start) in normal mode. Unlike ^, it always lands at the very leftmost position, regardless of indentation.
Move to end of line Shift+$ Moves the cursor to the end of the line (the last character) in normal mode. It is commonly used when you want to add text at the end of a line or quickly check its contents.
Go to beginning of word w Moves the cursor to the beginning of the next word in normal mode. It is faster than moving character by character with h or l, and is a basic movement for word-based editing.
Return to beginning of word b Moves the cursor to the beginning of the previous word in normal mode. It moves in the opposite direction to w, useful for going back to fix a word you just typed.
Go to end of word e Moves the cursor forward to the end of a word in normal mode. It is often used when you want to target the last character of a word, or as the starting point for commands like de to delete to the end of a word.
Return to end of word g e Moves the cursor backward to the end of the previous word in normal mode. It moves in the opposite direction to e, used when you want to edit the end of a preceding word.
Move to the beginning of the file g g Jumps the cursor straight to the beginning of the file (line 1) in normal mode. It is handy for quickly returning to the top when working in a long file.
Move to the end of the file Shift+G Jumps the cursor straight to the last line of the file in normal mode. It is often used to check the tail of a file, such as a log file.
Move to line 77 :77 Enter In command-line mode, typing ":line-number" and pressing Enter jumps directly to the specified line (line 77 here). It lets you jump straight to a known location, such as when an error message points to a specific line number.
Scroll to center the cursor on the screen z z Scrolls the view so the current cursor line is centered on the screen, without moving the cursor itself. It is useful when you want to see the surrounding context before and after the point you are editing.
Search for "," in the forward direction of the line f , In normal mode, searches forward within the current line from the cursor position and moves the cursor onto the specified character (here, ","). It is used to jump straight to a delimiter such as a comma within a line.
Repeat one character search in the forward direction ; Repeats the last f (or t) single-character search in the same direction. It is used to move through successive occurrences of the same character on a line.
Repeat one character search in the opposite direction , Repeats the last f (or t) single-character search in the opposite direction. Useful for going back with ; when you have moved too far.
Search backward for "n" in that row Shift+F n Using F (uppercase) searches backward within the line from the cursor and moves onto the specified character (here, "n"). It is the reverse-direction counterpart of f, used to move quickly leftward within a line.
Search for the string "and" in the forward direction /and Enter In command-line mode, typing "/" followed by a search string (here, "and") and pressing Enter searches forward through the whole file. It is used to quickly locate a specific word or piece of code.
Repeat string search forward n Repeats the last multi-character search (with / or ?) in the same direction. It is used to move through successive matches of the same word in a document.
Repeat string search in reverse direction Shift+N Repeats the last multi-character search (with / or ?) in the opposite direction. Unlike n, it is used to go back to the previous match.
Return to where you jumped Ctrl+O Moves back to the previous position in the jump list, which records large cursor movements caused by searches, gg, line jumps, and similar commands. It is handy for returning to where you were after jumping elsewhere while reading code.
Go to the place where you jumped Ctrl+I Moves forward one step in the jump list, in the opposite direction of ctrl-o. It is used to move forward again after going back too far.
Move up half screen Ctrl+U Scrolls the cursor and the view up by half a screen height. It moves in slightly smaller increments than ctrl-b, useful for reading back through a document gradually.
Move half screen down Ctrl+D Scrolls the cursor and the view down by half a screen height. It is the opposite of ctrl-u, commonly used to read forward through a document gradually.
Move up one screen Ctrl+B Scrolls the cursor and the view up by a full screen (one page). It moves further than ctrl-u, useful for quickly scrolling back through a long document.
Move down one screen Ctrl+F Scrolls the cursor and the view down by a full screen (one page). It is the opposite of ctrl-b, useful for quickly reading through a long document.
Go back one place you changed g ; Moves the cursor back to the previous change location, following the change list. It is used to return to an earlier edit for review after making changes in several places.
Move forward one place g , Moves the cursor forward one step in the change list, in the opposite direction of g;. It is used to move forward again after going back too far in the change history.

Editing

Vim — Editing
Action Shortcut What it does
Switch to edit mode (before cursor) i Switches from normal mode to insert mode, letting you type text immediately before the character under the cursor. It is one of the most frequently used commands for entering new text in Vim.
Switch to normal mode Esc Returns to Vim's default normal mode from other modes such as insert or visual mode. Since navigation, copying, and deleting are performed in normal mode, this is a key you use after every round of editing.
Switch to edit mode (behind the cursor) a Switches from normal mode to insert mode, letting you type text immediately after the character under the cursor. Unlike i, insertion starts one position later, which is handy for appending text at the end of a line.
Return to normal mode (ctrl press var) Ctrl+[ Works the same as the Escape key, returning to normal mode from insert mode and similar modes. It is often used instead of Escape when you want to switch modes without moving your hands from the home row.
Insert line below to enter mode o Inserts a new blank line below the current line and enters insert mode on it. It is handy for starting a new line of code or text regardless of where the cursor was on the current line.
Insert a line above and enter input mode Shift+O Inserts a new blank line above the current line and enters insert mode on it. It works in the opposite direction to o, used when you want to add a new line before the current one.
Go to the beginning of the line and enter input mode Shift+I Moves the cursor to the first non-blank character of the line and enters insert mode there. It combines ^ and i in one step, handy for adding text at the beginning of a line.
Go to end of line and enter input mode Shift+A Moves the cursor to the end of the current line and enters insert mode there. It combines $ and a in one step, and is very commonly used to append text at the end of a line.
Replace the character on the cursor with "M" r Shift+M In normal mode, typing "r" followed by a character replaces just the single character under the cursor with it. This example replaces it with "M"; the key benefit is fixing one character on the spot without entering insert mode.
Enter "vim" in multi-character replacement mode Shift+R v i m Pressing R (uppercase) enters replace mode, where typed characters overwrite the existing text from the cursor position onward. Here "vim" is typed; it is used when you want to correct text by directly overtyping it.
Switch to normal mode Esc Returns to normal mode from insert mode, replace mode, and similar modes. After typing or replacing text, this key brings you back to the standard operating mode.
Erase one character x Deletes the single character under the cursor in normal mode. It is the quickest way to remove just one mistyped character on the spot.
Change to visual mode v Switches from normal mode to visual mode (character-wise selection). Moving the cursor extends the selection, which can then be acted on with commands like y (yank) or d (delete).
Move to end of word e Moves the cursor to the end of a word, whether in normal mode or visual mode. Used while in visual mode, it extends the selection to the end of the word.
Yank (copy) y Yanks (copies) the range selected in visual mode into a register. It corresponds to "copy" in copy-and-paste, used when you want to duplicate the selected text elsewhere.
Paste what you yank p Pastes the most recently yanked (copied) or deleted content after the cursor position. It corresponds to "paste" in copy-and-paste, and is an operation used constantly when editing in Vim.
Erase one line d d Deletes the entire current line in normal mode. It is used to remove an unwanted line in one go, and the deleted content is automatically stored in a register.
Yank (copy) one line y y Yanks (copies) the entire current line in normal mode. When you want to copy a whole line, this single command does it without needing to select a range first.
Paste what you yank p Pastes the line just yanked with yy below the line where the cursor is. It is used to duplicate a copied line or move it to another location.
Delete the contents of the html tag and enter edit mode cit With the cursor inside an HTML tag, this deletes only the content between the opening and closing tags and enters insert mode there. It combines "c" (change) with "it" (inner tag), useful for rewriting just the tag's content while keeping the tag structure intact.
Select contents of html tag vit With the cursor inside an HTML tag, this selects, in visual mode, just the content between the tags. It combines "v" (visual) with "it" (inner tag), typically used before yanking or deleting the tag's content as a whole.
Delete contents of html tag dit With the cursor inside an HTML tag, this deletes just the content between the tags. It combines "d" (delete) with "it" (inner tag), used when you want to empty the content while keeping the tag itself.
Yank the contents of html tag (copy) yit With the cursor inside an HTML tag, this yanks (copies) just the content between the tags. It combines "y" (yank) with "it" (inner tag), useful for duplicating just the tag's content elsewhere.
Delete the contents of "" and enter edit mode c i Shift+" With the cursor inside a double-quoted string, this deletes only the text between the quotes and enters insert mode there. It combines "c" with "i\"" (inner quote), useful for rewriting just the value of a string.
Select the contents of "" v i Shift+" With the cursor inside a double-quoted string, this selects, in visual mode, just the text between the quotes. It is used as a selection step before copying or checking the value.
Erase the contents of "" d i Shift+" With the cursor inside a double-quoted string, this deletes only the text between the quotes. It is used when you want to empty the value while keeping the quotes themselves.
Yank (copy) the contents of "" y i Shift+" With the cursor inside a double-quoted string, this yanks (copies) only the text between the quotes. It is useful when you want to copy just the value to another location.
Erase the word on the cursor and enter edit mode ciw Deletes only the word under the cursor and enters insert mode there. It combines "c" with "iw" (inner word), commonly used to rewrite a single word on the spot without manually selecting it.
Select word on cursor viw Selects the entire word under the cursor in visual mode. It combines "v" with "iw" (inner word), convenient for selecting a whole word before yanking or deleting it.
Erase word on cursor diw Deletes the entire word under the cursor. It combines "d" with "iw" (inner word), used to remove a whole word at once without the effort of manually selecting part of it.
Yank (copy) the word on the cursor yiw Yanks (copies) the entire word under the cursor. It combines "y" with "iw" (inner word), saving the effort of manually selecting a range when you want to copy a single word.

File operations

Vim — File operations
Action Shortcut What it does
Create a new file called "test.js" :e test.js Enter In command-line mode, typing ":e filename" opens the given file, creating it if it does not already exist. This example shows creating a new file called "test.js".
save : w Enter In command-line mode, typing ":w" and pressing Enter saves the file currently being edited. It corresponds to a regular save, and is one of the most frequently used commands when working in Vim.
End current file : q In command-line mode, typing ":q" quits Vim. If the file has unsaved changes, it will refuse to quit and show an error, so it is normally used only after saving.
Kill current file (exit without saving) : q Shift+! Enter In command-line mode, typing ":q!" forcibly quits Vim without saving changes. It is used when you want to discard experimental edits and abandon the file as it was.
Change the file name to "othr.js" :f othr.js Enter In command-line mode, typing ":f new-filename" changes only the name of the buffer currently being edited. This example renames it to "othr.js"; a subsequent :w is needed to actually save it under the new name.
Save and exit :wq Enter In command-line mode, typing ":wq" saves the file and then quits Vim. It combines ":w" and ":q" in one step, and is the standard way to finish an editing session.
suspend vim Ctrl+Z Sends Vim to the background and returns to the shell, suspending it temporarily. It is used when you want to run another command briefly without quitting Vim, and you can return to the editing screen later with fg.
Restore suspended state f g Enter Typed at the shell as "fg" followed by Enter, this brings a Vim session suspended with ctrl-z back to the foreground. It is a shell command rather than a Vim command, used when you want to resume editing.

Split screen (Mac)

Vim — Split screen (Mac)
Action Shortcut What it does
Split screen vertically :sp Enter In command-line mode, typing ":sp" splits the current window horizontally (stacked top and bottom). It is used when you want to view and edit a different part of the same file, or another file, at the same time.
Split screen left and right :vsp Enter In command-line mode, typing ":vsp" splits the current window vertically (side by side). It is convenient on a wide screen for comparing two files, or two parts of the same file, side by side.
Close window : q Enter In command-line mode, typing ":q" closes only the currently active split window. It is used to close one window you are finished with while leaving the other split windows open.
Close all windows :qall Enter In command-line mode, typing ":qall" closes all split windows at once. It saves the trouble of closing each one individually with :q, useful for wrapping up work all at once.
Close all but the current window :only Enter In command-line mode, typing ":only" closes every split window except the current one. It is used to return to a single full-size view after working with multiple split windows.

Split screen (Win)

Vim — Split screen (Win)
Action Shortcut What it does
Split screen vertically :sp Enter In command-line mode, typing ":sp" splits the current window horizontally (stacked top and bottom). It is used when you want to view and edit a different part of the same file, or another file, at the same time.
Split screen left and right :vsp Enter In command-line mode, typing ":vsp" splits the current window vertically (side by side). It is convenient on a wide screen for comparing two files, or two parts of the same file, side by side.
Close window : q Enter In command-line mode, typing ":q" closes only the currently active split window. It is used to close one window you are finished with while leaving the other split windows open.
Close all windows :qall Enter In command-line mode, typing ":qall" closes all split windows at once. It saves the trouble of closing each one individually with :q, useful for wrapping up work all at once.
Close all but the current window :only Enter In command-line mode, typing ":only" closes every split window except the current one. It is used to return to a single full-size view after working with multiple split windows.

Using registers

Vim — Using registers
Action Shortcut What it does
Select current line Shift+V Pressing V (uppercase) in normal mode enters visual line mode (line-wise selection). Unlike character-wise v, the selection always spans whole lines, useful for operating on several lines at once.
Select the three lines below jjj Pressing j three times while in visual line mode extends the selection down by three more lines. It is used to add the following lines to a selection you have already started.
Save selection in register "a" Shift+" a y Yanks the visually selected range into the named register "a" instead of the default register. Specifying "a with \"a and then pressing y saves the copy separately, so it will not get overwritten by a later, unrelated copy.
Move 3 down jjj Pressing j three times in normal mode moves the cursor down three lines. Here it is used to move to the destination line before pasting the content just saved in register a.
Paste the contents of register "a" Shift+" a p Specifying register a with \"a and then pressing p pastes the content stored in register a at the cursor position. Unlike plain p, this lets you paste the content of a specific register precisely.
Save the current line in register "b" Shift+" b y y Specifying register b with \"b and then pressing yy yanks the entire current line into register b. It is used when you want to keep multiple copied pieces of content in separate registers.
Paste the contents of register "b" Shift+" b p Specifying register b with \"b and then pressing p pastes the content stored in register b at the cursor position. It lets you paste the line saved in b independently of whatever is in register a.
Select current line Shift+V Pressing V (uppercase) in normal mode selects the current line in visual line mode. Here it is the starting point for adding more lines to the selection before saving them to register c.
Also select the bottom 5 rows jjjjj Pressing j five times while in visual line mode extends the selection down by five more lines. It is used to select a larger block of lines in one go, in addition to the line already selected.
Erase selected range and save in register "c" Shift+" c d Specifying register c with \"c and then pressing d deletes the visually selected range while saving its content into register c. This corresponds to "cut," used after selecting a range you want to move elsewhere.
Move down j Pressing j in normal mode moves the cursor down one line. Here it is used to move to the destination line before pasting the content saved in register c.
Paste the contents of register "c" Shift+" c p Specifying register c with \"c and then pressing p pastes the content stored in register c at the cursor position. It is used as the final step of moving content that was cut with d to a new location.
Erase current line and save in register "d" Shift+" d d d Specifying register d with \"d and then pressing dd deletes the current line while saving its content into register d. It corresponds to a line-wise cut, used when you want to keep it in a specific register.
Paste the contents of register "d" Shift+" d p Specifying register d with \"d and then pressing p pastes the content stored in register d at the cursor position. It is used to bring back a line deleted with dd, checking the placement as you go.
Display register information list :reg Enter In command-line mode, typing ":reg" and pressing Enter lists the contents of all currently stored registers. It is used to check what was copied where when you have forgotten which register holds what.
Enter VISUAL mode v Pressing v in normal mode enters visual mode (character-wise selection). Here it is the setup step before extending the selection word by word with repeated e presses, in order to save it to register e.
Select 2 words e e Pressing e twice while in visual mode extends the selection by two words, using word endings as the boundary. It is faster than selecting character by character when you want to select whole words.
Save selection in register "e" Shift+" e y Specifying register e with \"e and then pressing y yanks the two words selected in visual mode into register e. It is used to keep a word-level copy separate from the other registers (a through d).
Enter INSERT mode i Pressing i in normal mode enters insert mode. Here it is used before pasting the word yanked into register e directly with ctrl-r.
Paste register "e" while in INSERT mode Ctrl+R e While in insert mode, pressing ctrl-r followed by a register name (here, "e") inserts the content of register e directly at the cursor position. The key benefit is inserting previously copied text into what you are typing without leaving insert mode.
Back to top