Add a user defined vi editor command:
This will make it so that when the user types :Legend in normal mode, a block of text is added under the cursor.
Step 1: Put this line into a file named ~/legend_header.txt`
this text will be added
Step 2: Put this command into your ~/.vimrc file (if the file doesn't exist, create it):
"The following command puts the contents of ~/legend_header.txt
"under the cursor when the user types ":Legend" in normal mode.
command Legend :r ~/legend_header.txt
Step 3: Restart vi for the changes to take effect. You're done.
Test it
Step 1: Open a new file in vi. Be in the default "normal mode" in vi. Type :Legend
Step 2: The contents of ~/legend_header.txt should be added where the cursor is.
command!. – phyatt Jan 12 '17 at 20:00command!is also useful when defining an autocommand (i.e. a file type specific command) otherwise errorE174: Command already exists: add ! to replace itwill appear each time you pressctrl-oto jump back to a previous position or when viewing a git diff for example. – Paul Rougieux Jun 16 '20 at 10:13:DoThingthat has different behaviour for:DoThingand for:DoThing!with the exclamation mark? – minseong Feb 16 '24 at 15:42