Skip to content

Useful Vim Commands

shamik edited this page Apr 25, 2024 · 6 revisions

Vim Commands

Best way to learn Vim

Execute the following in your bash vimtutor

Three modes in Vim

  1. Command - press Esc on keyboad
  2. Edit - press i
  3. View - press v

Moving cursor to the beginning of the line

^

Moving cursor to the end of the line

$

Appending at the cursor location

a

To select a text

v

To select an entire line

V

Copy a selection of text

y

Copy the entire line of the cursor

yy

copy everything right of the cursor

y$

copy everything left of the cursor

y^

Delete an entire line

dd

Delete a single word

dw

Delete the word on which the cursor is on

daw

Delete a single character

x

Undo(command mode)

u

Redo(command mode)

Ctrl + r

To copy to system clipboard

  1. Command Mode
  2. Select the relevant text with cursor Ctrl + Shift + C

Paste an entire line or a selection of text

p

To paste from system clipboard

  1. Command Mode Ctrl + Shift + V

To search for a pattern

/<pattern> Use n to move to the next item found

To find and replace

General pattern:[range]s/{pattern}/{string}/[flags]. E.g. search in the entire file, confirm before replacing, and case insensitive search(by default it's case sensitive search)

:%s/foo/bar/ci

To save changes

:w

To quit without saving your changes

!q

To quit with saving changes

:wq

To just quit

q

Clone this wiki locally