Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

vim
command
quit
exit
unix

What are some of the popular Vim editor commands?

Educative Answers Team

Vim is a lightweight, modal based editor. The whole concept of modal based editors revolves around editing your text/code without having to take your hands off the keyboard. To achieve this, Vim offers seven base modes and several other additional modes, each with its own commands. Even though there are seven modes, you’ll most likely only need command mode or insert mode for your everyday programming use.

svg viewer

Vim commands

Below is a list of common Vim commands and their functions. This is not a complete list, as it does not include the advanced commands, but it is enough for you to be able to functionally utilize Vim. You’ll learn about basic commands, navigating, editing, searching, marking, and working with multiple files.

Note: < and > are omitted from the actual commands. They are simply used to indicate the name of your input.

Basic commands

Esc - Exits current mode into the “command mode”

i - Exists current mode into the “insert mode”

:help &lt;keyword&gt; - Searches the Help documentation for your keyword

:w - Saves your file

:wq - Saves and closes your file

:q - Closes your file

ZZ - Saves your file and exits Vim

Navigating commands

h - Moves the cursor to the left

j - Moves the cursor down one line

k - Moves the cursor up one line

l - Moves the cursor to the right

10j - Moves the cursor down 10 lines

H - Moves cursor to the top line on the screen

M - Moves cursor to the middle line on the screen

L - Moves cursor to the bottom line on the screen

w - Moves the cursor to the beginning of the next word

b - Moves the cursor to the beginning of the previous word

e - Moves the cursor to the end of the current word

gg - Moves cursor to the first line of the file

G - Moves cursor to the last line of the file

0 - Moves cursor to the beginning of the current line

# - This command takes​ you to line #, where # is specified by you

Editing commands

i - Insert before the current character

a - Insert after the current character

o - Insert a line below the current line, then enter insert mode

O - Insert a line above the current line, then enter insert mode

s - Delete character at cursor and insert

S - Delete line at cursor and insert

. - Repeat last command

r - Replace one character and return to command mode

u - Undo

Searching commands

/&lt;keyword&gt; - Searches document for where the keyword is

/word - Finds the next instance of ‘word’

* - Finds the next instance of the current word

# - Finds the previous instance of the current word

n - Searches your text again in the direction of the last search

Working with multiple files

:bn - Moves to next buffer

:bp - Moves to previous buffer

:bd - Deletes a buffer

:sp <filename> - Opens a file in a new buffer and splits screen horizontally

:vsp <filename> - Opens a new file in a new buffer and splits the screen vertically

ctrl + ws - Split windows

ctrl + ww - Switch between windows

ctrl + wq - Quit a window

ctrl + wv - Split windows vertically

Marking Commands

v - Starts visual mode, marks lines, and runs a command

V - Starts linewise visual mode

o - Moves to the other end of marked area

ctrl + v - Starts visual block mode

aw - Marks a word

Summary

What makes Vim so popular is that it’s incredibly functional without having to use a mouse. As you can see, there are tons of keyboard shortcuts that Vim offers. The list provided is just a small portion. Click here to download the Vim editor for free.

RELATED TAGS

vim
command
quit
exit
unix
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring