#AIX #unix #linux #sed #grep #ubuntu #debian #nano #text #texteditor #notepad
### **VIM / VI Cheat Sheet**
#### **Modes in VIM**
- **`ESC`** → Switch to **Command mode**
- **`i`** → Switch to **Insert mode**
- **`I`** → Move to the beginning of the line and enter Insert mode
- **`o`** → Open a new line **below** and enter Insert mode
#### **Visual Mode**
- **`v`** → Enter **Visual mode** (select characters)
- **`V`** → Enter **Visual Line mode** (select full lines)
- **`CTRL+V`** → Enter **Visual Block mode** (select columns)
- **`3V`** → Select **3 lines**, then **`d`** to delete
#### **Navigation**
- **`1G`** → Go to the **first line**
- **`G`** → Go to the **last line**
- **`gg`** → Go to the **first line**
- **`:24`** → Go to **line 24**
- **`w`** → Move forward **word by word**
- **`W`** → Move forward to the **next space**
- **`b`** → Move **backward word by word**
- **`B`** → Move **backward to the previous space**
- **`j`** → Move **down** one line (**`5j`** moves 5 lines down)
- **`k`** → Move **up** one line (**`5k`** moves 5 lines up)
- **`h`** → Move **left** (**`5h`** moves 5 positions left)
- **`l`** → Move **right** (**`5l`** moves 5 positions right)
- **`0`** or **`^`** → Move to the **beginning of the line**
#### **Editing**
- **`dd`** → Delete **the entire line**
- **`dw`** → Delete **one word**
- **`dj`** → Delete **the next line**
- **`dk`** → Delete **the previous line**
- **`D`** → Delete **everything to the right of the cursor**
- **`C`** → Same as `D`, but enters **Insert mode**
- **`cw`** → Change **the current word**
- **`r`** → Replace **a single character** (**`3rX`** replaces 3 characters with `X`)
- **`x`** → Delete **the character under the cursor** (**`10x`** deletes 10 characters)
- **`~`** → Swap **case** of the letter under the cursor (**`5~`** swaps case of the next 5 letters)
#### **Jumping Inside Code**
- **`}`** → Jump to **the end of a block of code**
- **`%`** → Jump between **matching `()` or `{}`**
- **`d%`** → Delete **everything inside `()` or `{}`**
- **`ct)`** → Delete **up to `)` and enter Insert mode**
- **`dt)`** → Delete **up to `)` and stay in Command mode**
#### **Search & Replace**
- **`*`** → Find the next occurrence of the word under the cursor
- **`t!`** → Jump **before** the next `!`
- **`f!`** → Jump **on** the next `!`
- **`;`** → Repeat the last **search movement**
- **`.`** → Repeat the last **command** (redo)
#### **Undo & Redo**
- **`u`** → Undo the last action (press multiple times to keep undoing)
- **`.`** → Redo **the last action**
#### **Copy, Cut & Paste**
- **`SHIFT+V`** → Enter **Visual Line mode**
- **`y`** → **Yank (copy)** selected text
- **`p`** → **Paste** yanked text
- **`d`** → **Cut** selected text
- **`>`** → **Indent** selected lines (**`3>`** indents 3 times)
#### **Macros in VIM**
- **Recording a Macro:**
sh
KopiërenBewerken
`q<w> # Start recording in register <w> [commands] q # Stop recording`
- **Playing a Macro:**
- `@w` → Run macro stored in register `w`
- `20@w` → Run the macro **20 times**
This should give you a solid foundation for working efficiently in **VIM/VI**! 🚀
[Vim Tutorial for Beginners](https://www.youtube.com/watch?v=RZ4p-saaQkc)
Zie ook [[VI Search and Replace ( CTRL-H)]]