1. Why Advanced Commands Matter
Once you’re comfortable editing files in Vi, the next step is efficiency.
These advanced commands let you:
- Copy text between files
- Move large code blocks
- Read or write external data
- Control how Vi behaves
Perfect for engineers working on multi-file RTL projects, testbench automation, or configuration management.
2. Transfer and Move Lines Between Locations
| Command | Description |
| :n1,n2 t n3 | Copy (transfer) lines from range n1–n2 to after line n3 |
| :n1,n2 m n3 | Move lines from range n1–n2 to after line n3 |
Examples:
:10,20t50
Copies lines 10–20 and pastes them after line 50.
:100,150m200
Moves lines 100–150 to after line 200 — useful for rearranging RTL modules or constraint sections.
3. Write or Append Lines to Another File
| Command | Description |
| :n1,n2 w filename | Write lines n1–n2 into a file |
| :n1,n2 w >> filename | Append lines n1–n2 into a file |
| :r filename | Read and insert content of another file |
Examples:
:50,80w buffer.v
Writes lines 50–80 into a new file buffer.v.
:r header.v
Inserts contents of header.v into the current file — ideal for importing parameter definitions.
4. Screen and Display Commands
| Command | Function |
| Ctrl + l | Refresh screen (redraw) |
| ^g | Display file name, line number, and status |
| :set nu | Show line numbers |
| :set nonu | Hide line numbers |
| :set list | Show hidden characters (tabs, EOLs) |
| :set nolist | Hide hidden characters |
Example:
:set nu
:set list
Shows line numbers and invisible characters — useful when debugging formatting issues in scripts.
5. Setting and Modifying Options
Vi supports customizable settings using the :set command.
| Command | Description |
| :set all | Show all options |
| :set option | Enable an option |
| :set nooption | Disable an option |
| :set option? | Display current value of an option |
| :set | Display modified options |
Example:
:set ai
:set ts=4
:set ic
Enables auto-indent, sets tab width to 4, and makes searches case-insensitive.
6. Commonly Used Options for VLSI Workflows
| Option | Purpose |
| set nu | Show line numbers |
| set ai | Auto-indent code |
| set ic | Case-insensitive search |
| set ts=5 | Set tab spacing |
| set nobackup | Prevent backup file creation |
| set ignorecase | Ignore case during search |
💡 Tip:
Enable these in your ~/.vimrc or .exrc file for automatic configuration every time Vi starts.
7. Useful Information Commands
| Command | Description |
| :scriptnames | Lists all scripts loaded by Vim (includes .vimrc) |
| :echo $MYVIMRC | Shows the location of your .vimrc file |
| :e $MYVIMRC | Opens your Vim configuration file |
| :version | Displays Vim version and features |
Example:
:e $MYVIMRC
Opens your configuration file for quick editing — ideal for customizing behavior (tabs, indent, colors).
8. Refresh and Reopen Files
| Command | Description |
| :e! | Reload the current file, discarding unsaved changes |
| :w! | Force write a read-only file |
| :q! | Quit without saving changes |
| 😡 | Save and quit (same as :wq) |
Example:
:w! /etc/udev/rules.conf
Saves a system file opened as read-only — helpful when editing permission-protected files.
9. Real-World Use Cases for VLSI Engineers
Case 1: Merge Constraint Sections
:100,150w constraints_part1.sdc
:e full_constraints.sdc
:r constraints_part1.sdc
Quickly merges SDC fragments into one master file.
Case 2: Copy Common HDL Templates
:1,50t$
Copies top module template (lines 1–50) to end of file.
Case 3: Append Error Log Snippets
:/error
:.,.+20w >> error_summary.log
Writes 20 lines after each “error” occurrence to a summary log.
10. Extra Power Commands
| Command | Function |
| :%!sort | Sort entire file |
| :%!uniq | Remove duplicate lines |
| :%!grep pattern | Filter lines matching pattern |
| :%!awk ‘{print $1}’ | Run shell command inside Vi |
| :sh | Temporarily open a shell (type exit to return) |
💡 Use these carefully — they let you process large text files directly from Vi without leaving your editor.
Summary
These advanced Vi commands make you fully independent inside the terminal.
You can:
- Move or merge text between files
- Control Vi’s behavior with :set options
- Automate repetitive editing tasks
- Even execute shell operations from within Vi
They’re a must-have for engineers managing multi-file design and verification environments.
