Post 2: Insert and Edit Commands in Vi Editor


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:

CommandAction
iInsert text before the cursor
IInsert text at the beginning of the current line
aAppend text after the cursor
AAppend text at the end of the current line
oOpen a new line below the current line
OOpen 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

CommandDescription
xDelete a single character
nxDelete n characters
dwDelete a word
ndwDelete n words
ddDelete current line
nddDelete n lines
:n1,n2 dDelete lines from n1 to n2
DDelete 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

CommandAction
cwChange a word
ncwChange n words
ccChange entire line
CChange from cursor to end of line
rReplace a single character
nrReplace n characters
RReplace continuously until you press Esc

Example:

To replace “AXI” with “PCIe”:

  1. Place cursor on “A”
  2. Type cw
  3. Type PCIe
  4. Press Esc

4. Undo and Redo Edits

CommandFunction
uUndo last change
UUndo all changes made on the current line
Ctrl + rRedo 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

TaskCommandExample
Delete from cursor to endDClean comments quickly
Delete previous worddbRemove identifier parts
Delete to start of lined0Remove unwanted spacing
Replace till ESCRModify 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:

  1. Use /signal_old to search
  2. Then cw → signal_new → n to move to next
  3. 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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top