Vim (Cheat Sheet)
Vim (Cheat Sheet)

Basic Movement Commands (Normal Mode)
| Command | Description |
| ------- | ------------------------------------------ |
| h l | Move cursor left and right |
| j k | Move cursor down and up |
| gg | Go to the beginning of the file |
| G | Go to the end of the file |
| w | Move to the beginning of the next word |
| b | Move to the beginning of the previous word |
Inserting and Changing Text
| Command | Description |
| ------------------- | ------------------------------------------ |
| i <text> Esc | Insert text at the cursor position |
| cw <new_word> Esc | Change the word to the right of the cursor |
| x | Delete the character under the cursor |
| dw | Delete a word from the cursor position |
| dd | Delete the entire line |
| u | Undo the last action |
| Ctrl + r | Redo the undone action |
Saving and Exiting Files
| Command | Description |
| -------------------- | ------------------- |
| :w | Save the file |
| :q | Quit |
| :wq or :x or ZZ | Save and quit |
| :q! | Quit without saving |
Copying and Pasting
| Command | Description |
| ------- | -------------------------- |
| <n>yy | Yank (copy) n lines |
| <n>yl | Yank (copy) n characters |
| p | Paste after the cursor |
| P | Paste before the cursor |
Searching and Clearing Highlights
| Command | Description |
| ------- | --------------------------- |
| /word | Search downward for "word" |
| ?word | Search upward for "word" |
| n / N | Go to next / previous match |
| :noh | Clear search highlights |
Substitution (Text Replacement)
| Command | Description |
| ----------------------- | --------------------------------------- |
| :s/old/new/ | Replace first match in the current line |
| :s/old/new/g | Replace all matches in the current line |
| :%s/old/new/g | Replace all matches in the whole file |
| :1,37s/test/example/g | Replace matches between lines 1 to 37 |
Selecting, Copying, and Pasting the Whole File
To select the entire file:
ggVG
gg→ Go to the top of the fileV→ Enter line-wise visual modeG→ Select to the bottom of the file
:%yank
To copy:
y
This copies the entire selection in visual mode (yank).
To paste inside Vim:
- Move to the desired position
- Use:
p→ Paste after the cursorP→ Paste before the cursor
Extra: Clearing File Content
To empty a file named deneme.txt, run:
:> deneme.txt
This command clears the content of deneme.txt.
← PostgreSQL Blog