1. Entering Insert Mode
Vi starts in Normal Mode.
To type or modify text, you must switch to Insert Mode using any of the following commands:
| Command | Action |
| i | Insert text before the cursor |
| I | Insert text at the beginning of the current line |
| a | Append text after the cursor |
| A | Append text at the end of the current line |
| o | Open a new line below the current line |
| O | Open a new line above the current line |
👉 Example:
To add a new Verilog signal below the current line:
o
logic [7:0] data_reg;
Press Esc when done to return to Normal Mode.
2. Deleting Text Efficiently
| Command | Description |
| x | Delete a single character |
| nx | Delete n characters |
| dw | Delete a word |
| ndw | Delete n words |
| dd | Delete current line |
| ndd | Delete n lines |
| :n1,n2 d | Delete lines from n1 to n2 |
| D | Delete from cursor to end of line |
💡 Example:
:10,20 d
Deletes all lines from 10 to 20 — useful when cleaning large config or log files.
3. Changing (Replacing) Text
| Command | Action |
| cw | Change a word |
| ncw | Change n words |
| cc | Change entire line |
| C | Change from cursor to end of line |
| r | Replace a single character |
| nr | Replace n characters |
| R | Replace continuously until you press Esc |
Example:
To replace “AXI” with “PCIe”:
- Place cursor on “A”
- Type cw
- Type PCIe
- Press Esc
4. Undo and Redo Edits
| Command | Function |
| u | Undo last change |
| U | Undo all changes made on the current line |
| Ctrl + r | Redo undone change |
👉 Use these when editing HDL or script files — a lifesaver during long debugging sessions.
5. Combining Delete and Insert
Vi’s c (change) commands delete text and immediately place you in insert mode.
For example:
- cw → delete one word, start typing new one
- cc → delete entire line, start typing replacement
Use case:
When editing a timing constraint file:
:set nu
:25
ccset_input_delay -clock clk 5
This changes line 25 in one go.
6. Editing Tricks for VLSI Engineers
| Task | Command | Example |
| Delete from cursor to end | D | Clean comments quickly |
| Delete previous word | db | Remove identifier parts |
| Delete to start of line | d0 | Remove unwanted spacing |
| Replace till ESC | R | Modify long parameter lines |
7. Real-World Use Case
Imagine editing a testbench where you need to change 10 signal names.
Instead of doing it manually:
- Use /signal_old to search
- Then cw → signal_new → n to move to next
- Repeat quickly for all signals
This makes large HDL edits very fast and keyboard-only.
Summary
Editing mastery = Productivity boost.
With these commands, you can:
- Insert text smartly
- Delete or replace content precisely
- Undo or redo instantly
- Edit multiple lines in seconds
Once you combine these with navigation and search commands (covered next), you’ll handle any file like a pro inside Linux terminals.
