1. Why Copy/Cut/Paste is Important in Vi
In verification or RTL workflows, you frequently need to:
- Duplicate portions of code (e.g., testbench sequences)
- Move register blocks or module instantiations
- Extract error logs into another file
With Vi, you can perform all this without using a mouse, making your workflow much faster — especially when working over SSH or remote servers.
2. Understanding Yank (Copy), Delete (Cut), and Put (Paste)
| Command | Operation | Description |
| yy | Yank (copy) current line | |
| nyy | Yank n lines | |
| dd | Cut current line | |
| ndd | Cut n lines | |
| p | Paste text after cursor or line | |
| P | Paste text before cursor or line |
💡 Tip:
- The last deleted (d) or yanked (y) content is stored in a buffer.
- You can reuse it until you overwrite it with a new yank or delete.
3. Copying (Yanking) Text
| Command | Example | Action |
| yy | Copy current line | |
| 3yy | Copy next 3 lines | |
| :5,10y | Copy lines 5 to 10 | |
| yw | Copy one word | |
| y$ | Copy from cursor to end of line |
Example:
To copy the next 10 lines from an RTL file:
10yy
Then paste them anywhere using p or P.
4. Cutting (Deleting) Text
Vi’s delete commands also cut text into the same buffer used by yank.
| Command | Example | Description |
| dd | Delete (cut) current line | |
| 5dd | Delete next 5 lines | |
| dw | Delete one word | |
| d$ | Delete from cursor to end of line | |
| :10,20d | Delete lines 10 to 20 |
Example:
:50,60d
Deletes lines 50–60 — useful for removing extra debug prints from testbench logs.
5. Pasting (Putting) Text
| Command | Description |
| p | Paste after cursor |
| P | Paste before cursor |
Example:
5yy
:100
P
Copies 5 lines, jumps to line 100, and pastes them before that line.
6. Copying Between Files
You can copy specific lines from one file and paste them into another without leaving Vi.
Example:
:5,20y a
:e other_file.v
“ap
This sequence:
- Yanks lines 5–20 into register a
- Opens another file
- Pastes the copied lines from register a
This is great for transferring common code (like signal declarations or parameters) between modules.
7. Move (Cut and Paste) Lines Between Locations
You can move a block of lines using delete + paste.
Example:
:100,120d
:500
P
Moves lines 100–120 to before line 500 — helpful for reorganizing RTL or constraint sections.
8. Copy Lines to an External File
You can write selected lines into another file using:
:10,30w newfile.v
This writes lines 10–30 into a new file named newfile.v.
To append instead:
:10,30w >> newfile.v
💡 Perfect for extracting meaningful log sections from large simulation output files.
9. Real-World Use Case for VLSI Engineers
Scenario:
You’re reviewing a testbench file and want to:
- Copy stimulus code block from lines 200–250
- Paste it in another test sequence file
Commands:
:200,250y
:e tb_sequence_2.sv
P
Done — block copied, pasted, and ready for modification.
No external editor needed.
Summary
Copy, Cut, and Paste operations in Vi are essential for:
- Managing repetitive testbench code
- Moving module declarations
- Extracting logs efficiently
Once mastered, they replace the need for mouse-driven editing entirely — making Vi the fastest editing tool for Linux-based VLSI workflows.
