Cheat Sheets Help

Vim

Basic Commands

Open a file in VIM

vim <file_name>

Exit VIM

  • In command mode: :q

  • Quit without saving: :q!

  • Save and quit: :wq

Save a file

:w

Save and quit VIM

:wq

Move cursor up, down, left, or right

  • Up: k

  • Down: j

  • Left: h

  • Right: l

Go to the beginning of the line

0

Go to the end of the line

$

Go to a specific line number

:<line_number>

Editing

Switch to insert mode (start editing)

i

Delete a character

x

Delete a word

dw

Delete an entire line

dd

Undo last change

u

Redo the last undone change

Ctrl + r

Copy & Paste

Copy (yank) a line

yy

Paste the copied line below the cursor

p

Paste the copied line above the cursor

P

Search & Replace

Search for a word

/<word>

Search and replace in the file

:%s/<old_word>/<new_word>/g

Move to the next occurrence of a search result

n

Move to the previous occurrence of a search result

N

Visual Mode

Select text to copy or delete

v

Select entire lines

V

Select a block of text

Ctrl + v

Miscellaneous

Open a new file

:e <new_file_name>

Close current file and open a new file

:e! <new_file_name>

View line numbers

:set number

Hide line numbers

:set nonumber
Last modified: 08 September 2024