Common Vim commands - nus-cs2030/2324-s2 GitHub Wiki

Exit Vim

Remember to hit the Esc key to be in command mode

Method 1, save and exit Vim: shift + z + z

Method 2, save and exit Vim: wq!

Commonly used keyboard shortcuts

Insert Mode: i

Command Mode: Esc

Go to the beginning of the current line: 0

Go to the end of the current line: $

Navigate to a particular line: <line_num> + gg

Indent all code in file: gg=G

Auto-complete: CTRL + p

Undo: u

Redo: CTRL + r

Delete a single word: dw

Delete from cursor to the end of the line: d$

Delete the current line: dd

Delete 5 lines: 5dd

Delete a single character: x

Copy the current line: yy

Copy 5 lines: 5yy

Paste: p

Split the window horizontally: :sp or CTRL + w + s

Split the window vertically: :vspor CTRL + w + v

Navigate between split windows: CTRL + w x2

Navigate directionally between windows: CTRL + [h/j/k/l] or CTRL + [↑/↓/←/→]

Search: /<search-term>

Exit search: / + ESC x2

Search and replace: :%s/<search-term>/<replace-term/g

⚠️ **GitHub.com Fallback** ⚠️