Post 7: General and Advanced Commands in Vi Editor


 

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

CommandDescription
:n1,n2 t n3Copy (transfer) lines from range n1–n2 to after line n3
:n1,n2 m n3Move 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

CommandDescription
:n1,n2 w filenameWrite lines n1–n2 into a file
:n1,n2 w >> filenameAppend lines n1–n2 into a file
:r filenameRead 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

CommandFunction
Ctrl + lRefresh screen (redraw)
^gDisplay file name, line number, and status
:set nuShow line numbers
:set nonuHide line numbers
:set listShow hidden characters (tabs, EOLs)
:set nolistHide 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.

CommandDescription
:set allShow all options
:set optionEnable an option
:set nooptionDisable an option
:set option?Display current value of an option
:setDisplay 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

OptionPurpose
set nuShow line numbers
set aiAuto-indent code
set icCase-insensitive search
set ts=5Set tab spacing
set nobackupPrevent backup file creation
set ignorecaseIgnore case during search

💡 Tip:

Enable these in your ~/.vimrc or .exrc file for automatic configuration every time Vi starts.


 

7. Useful Information Commands

CommandDescription
:scriptnamesLists all scripts loaded by Vim (includes .vimrc)
:echo $MYVIMRCShows the location of your .vimrc file
:e $MYVIMRCOpens your Vim configuration file
:versionDisplays 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

CommandDescription
: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

CommandFunction
:%!sortSort entire file
:%!uniqRemove duplicate lines
:%!grep patternFilter lines matching pattern
:%!awk ‘{print $1}’Run shell command inside Vi
:shTemporarily 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.


Leave a Comment

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

Scroll to Top