Skip to content

Useful Vim Commands

Shamik edited this page Oct 16, 2022 · 8 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

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

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