User:Guywan/Scripts/InsertShortcuts

Insert Shortcuts
Do you spend a lot of time wrapping text in formatting, tags, or templates? Unless you're a WikiGnome, this is probably tiring. Insert Shortcuts is what you need! This script maps the insertion of user-defined text to through  ( through  on Mac). It is only usable while source editing. Bold and italics are defined by default, and are mapped to and, respectively ( and  on Mac).

This script will insert text into the edit area based on specially defined rules. If you are not selecting anything, the script will expand your selection to the word at the caret position. Before using the script, you must define your tags at Special:MyPage/InsertShortcutsSettings.js. It's a JS file so only you can edit it. Ignore the warnings when saving.

Here is an example tag definition file:



_ \n_\n&lt;/pre>

The tags are numbered starting at 1 from the top. The  (underscore) defines where the text you are selecting goes, and the   expands to an actual 'newline'.


 * The vertical bar | denotes the caret position.

If you want the tag definition to span multiple lines (in the definition file), you can escape newlines with a backslash, like so: 

When you insert this tag, it will become:. If you want it to span multiple lines in the definition file and in the edit area when it is inserted, you need to use, like so: 

The 'tag' definitions can take any one of these forms:
 * – Asymmetric wrap.
 * – Prepend.
 * – Append.
 * – Symmetric wrap.
 * – Effectively replaces your selection.
 * – Take my word for it, this does nothing. Seriously.

Cross-wiki support
If you are using this script on multiple projects and would like to load tag settings from a specific project, there are two options available.

You can redirect the tag parser to a different project via the  directive. As an example, see v:User:Guywan/InsertShortcutsSettings.js, where I  to English Wikipedia. Double redirects won't work.

Examples:

Notice that you only specify the first part of the domain, without. The page should contain no other text except the  directive and the project indentifier.

You can set the  attribute where you are importing the script.

Examples:

This works very similarly to the  directive, except that you only need to create an   page on the project you are loading from.

Installation
To use this script, add the following to your  (or other):