Skip to content

Live templates

Writing the same skeleton again and again (an always_ff with its reset, a UVM phase, a `uvm_info call) is slow and invites typos. A live template is a short abbreviation that expands into such a skeleton. Type an abbreviation and press Tab to insert a block of code. The editor then moves through the parts you usually change (names, clock, reset, conditions); press Tab to accept each one and Enter to finish. Code | Insert Live Template (⌘J / Ctrl+J) lists the templates that fit where the caret is.

Open the sample project and wait until indexing has finished (the progress bar at the bottom right disappears). Each insertion leaves the editor in template mode (the parts to fill in are highlighted). To undo one, press Escape, then ⌘Z (macOS) / Ctrl+Z (Windows/Linux) until the abbreviation you typed is gone too, before the next step.

  1. Open rtl/counter.sv, put the caret (the text cursor) at the end of the line assign done = is_done(state); and press Enter.
  2. Type acomb and press Tab. An always_comb begin … end block is inserted below the assign line, with the caret inside it. Undo it.
  3. On the empty line you pressed Enter for, choose Code | Insert Live Template (⌘J / Ctrl+J). The list shows only module-level templates (see the RTL and generate and Assertions and coverage tables below), for example aff, gfor and ap; there is no build or uinfo. Press Escape to close it.
  4. Open uvm/my_pkg.sv, put the caret at the end of the line virtual task run_phase(uvm_phase phase); in my_driver, press Enter, type uinfo and press Tab. This line is inserted: `uvm_info(get_type_name(), $sformatf("%0d", value), UVM_MEDIUM). Undo it.
  5. In my_agent, put the caret after the endfunction of build_phase, press Enter, type connect and press Tab. A connect_phase function is inserted, with its super.connect_phase(phase); call. Undo it.

Each insertion is code that parses without errors. When you are done, the files are unchanged: undo until the editor tab no longer shows a modified marker. If a step inserts nothing, see If it doesn’t work.

Each template is offered only where its code belongs: design units and UVM classes at file level or in a package, processes, generate constructs and assertions in a module, interface or program, members and UVM phases in a class, and statements in procedural code (initial, always, functions and tasks). Nothing is offered elsewhere — inside a covergroup, struct, port list, comment or string, and not right after code that has a syntax error (the place around the caret is not known then). Statement templates are offered between the statements of a block; a single statement directly under if (…) or a case label without begin gets no template. Every template expands to code that parses without errors, in .sv, .svh and .v files, and is laid out by Reformat Code with your indent size.

acomb, then Tab — in a module
always_comb begin
end

Templates for UVM classes take the class name from the file name (my_driver.sv → class my_driver); members such as newc and cutils use the name of the class you are in. You can change and add templates in Settings | Editor | Live Templates, group SystemVerilog.

Abbreviation Inserts Where
module Module with parameters and ANSI ports File level or package
interface Interface with a clocking block and a modport File level or package
package Package File level or package
program Program File level or package
class Class with a constructor File level or package, Module, interface or program, Class body
vclass Virtual (abstract) class File level or package, Module, interface or program, Class body
iclass Interface class File level or package, Module, interface or program, Class body
guard Include guard for a header file File level or package
imp Wildcard package import File level or package, Module, interface or program
Abbreviation Inserts Where
tenum Enum typedef File level or package, Module, interface or program, Class body
tstruct Packed struct typedef File level or package, Module, interface or program, Class body
func Function File level or package, Module, interface or program, Class body
task Task File level or package, Module, interface or program, Class body
lp Local parameter File level or package, Module, interface or program, Class body
Abbreviation Inserts Where
aff always_ff with asynchronous active-low reset Module, interface or program
affs always_ff with synchronous reset Module, interface or program
acomb always_comb block Module, interface or program
alatch always_latch block Module, interface or program
asg Continuous assignment Module, interface or program
init initial block Module, interface or program
gfor Generate for loop Module, interface or program
gif Generate if / else Module, interface or program
inst Module instance with named port connections Module, interface or program
clk Clocking block Module, interface or program
mp Modport Interface
Abbreviation Inserts Where
prop Property declaration Module, interface or program
seq Sequence declaration Module, interface or program
ap Concurrent assertion Module, interface or program
asm Assumption Module, interface or program
cp Cover property Module, interface or program
cg Covergroup with a coverpoint Module, interface or program, Class body
Abbreviation Inserts Where
if if block Statements
ife if / else block Statements
case case with default Statements
ucase unique case with default Statements
casez casez with default Statements
for for loop Statements
foreach foreach loop Statements
while while loop Statements
dowhile do / while loop Statements
repeat repeat loop Statements
forever forever loop Statements
fork fork / join Statements
forkn fork / join_none Statements
forka fork / join_any Statements
be begin / end block Statements
disp $display with format Statements
ia Immediate assertion Statements
Abbreviation Inserts Where
uinfo `uvm_info Statements
uwarn `uvm_warning Statements
uerr `uvm_error Statements
ufatal `uvm_fatal Statements
cfgget uvm_config_db get with a fatal error Statements
cfgset uvm_config_db set Statements
create Factory create Statements
raise Raise and drop an objection Statements
rnd randomize with an error check Statements
start Start a sequence on a sequencer Statements
Abbreviation Inserts Where
new Constructor Class body
newc UVM component constructor Class body
newo UVM object constructor Class body
vfunc Virtual function Class body
vtask Virtual task Class body
cons Constraint block Class body
cutils `uvm_component_utils for this class Class body
outils `uvm_object_utils for this class Class body
build UVM build_phase Class body
connect UVM connect_phase Class body
run UVM run_phase Class body
report UVM report_phase Class body
Abbreviation Inserts Where
uitem UVM sequence item File level or package
useq UVM sequence File level or package
udrv UVM driver File level or package
umon UVM monitor with an analysis port File level or package
uagent UVM agent (driver, sequencer, monitor) File level or package
uenv UVM environment File level or package
usb UVM scoreboard with an analysis import File level or package
utest UVM test File level or package
ucomp UVM component File level or package
uobj UVM object File level or package
You see Likely cause What to do
Tab inserts a tab instead of the template The abbreviation is not complete, or the caret is not at the end of it Retype the abbreviation on an empty line and press Tab right after it
The template is not offered in the ⌘J list The place does not fit it (for example acomb inside a class, or a statement under if without begin) See the Where column in Templates
A completion popup is open and Tab picks a suggestion Code completion took the keypress Press Escape, then Tab again, or use ⌘J / Ctrl+J and pick the template
Nothing is offered at all The caret is in a comment, a string, a covergroup or a struct, or the code before it has a syntax error Move the caret to an empty line between statements or declarations