EditHelp

Summary: Keyboard shortcuts & automatic insertion of wiki markups
Version: pmwiki-2.5.9
Prerequisites: JavaScript, recent browser
Status: Experimental
Maintainer: Petko
License: Attribution (standalone), GPLv2 (core)
Categories: Editing, PHP55, PHP72
Users: (view / edit)
Discussion: EditHelp-Talk

Automatic insertion of start-of-line wiki markups, brackets, keyboard shortcuts.

Description

Start-of-line markup auto-insertion

When a user writes wiki markup, a bulleted list is entered with the sign * before the line. When the user presses "Enter/Return", the script will examine the line and if it starts with *, it will automatically insert a * before the new line, similar to how office suites insert list items. This way the user needs to simply type the text of the new list item.

In a similar fashion, the following start-of-line markups are recognized and re-inserted automatically when the user presses "Enter":

  • *, **, ***, ... unordered/bulleted list
  • #, ##, ###, ... numbered list
  • : : definition list
  •   (space) preformatted text
  • ->, -->, -<, --<, ... indented and hanging text
  • || simple table row
  • Additionally, it inserts the characters "-" (minus) and ">" (greater than, quote) on the new line if the current line starts with them.

Press Enter a second time to remove the auto-inserted markup (if there is nothing on the line).

The above automatic insertions are particularly useful on touch screen devices where it is more difficult to type punctuation.

Demo: the recipe is enabled on any page on pmwiki.org, you can test it for example in Main.WikiSandbox.

These edit help functions were first written for a "Structured sections editor" recipe in February 2016 (currently abandoned), but felt so natural and easy to use (a user described them as "exhilarating/addictive"), that I decided to port them to the regular PmWiki text editor. Enjoy!

Keyboard shortcuts

As of 2026-04-17 I recommend testing shortcuts with the pre-release, or here on pmwiki.org, as work is ongoing with fast changes.

Additionally, the following keyboard shortcuts might be appreciated by advanced editors with full keyboards:

DescriptionInserts*GNU/Linux, WindowsMacOS X
Bold text (see Talk page)'''...'''Ctrl+BCmd+B
Cycle** Italics, bold, bold-italic, code''...'', '''...''', '''''...''''', @@...@@Ctrl+ICmd+I
Cycle** Links (press multiple times as needed)
(if links are selected, removes double brackets)
[[...]], [[#...]], [[!...]], [[~...]],
[[(Attach:)...]], [[(mailto:)...]]...
Ctrl+KCmd+K
Cycle** WikiStyle%%...%%, %rfloat%...%%, %note%...%%,
>><<...>><<, >>frame<<...>><<
Ctrl+Shift+SCmd+Shift+S
Cycle** Directive/MarkupExpression (:...:), {(...)}Ctrl+Shift+DCmd+Shift+D
Cycle** Variable (Page, Text, Template) {*$...}, {*$:...}, {$...}, {$:...},
{$$...}, {=$...}, {=$:...}
Ctrl+Shift+VCmd+Shift+V
Cycle** Escape text/code sequences@@...@@, [=...=], [@...@],
%hlt%[@...@]%%, %pmhlt%[@...@]%%
Ctrl+ECmd+E
Non-breakable space
(if text is selected, toggles space-&nbsp; in it)
&nbsp;Ctrl+SpaceCmd+Space
Author signature~~~~Ctrl+Shift+EnterCmd+Shift+Enter
Line break "clear both"[[<<]]Ctrl+EnterCmd+Enter
Line break
(if text is selected, toggles \\ on-off)
\\Shift+EnterShift+Enter
Join lines
(also removes end-of line backslashes \\)
(selection or next line)Ctrl+JCmd+J
Cycle** lower/Title/UPPER case(selection)Ctrl+Shift+LCmd+Shift+L
Delete lines(selected lines)Ctrl+Shift+JCmd+Shift+J
Move lines up(selected lines)Ctrl+Shift+ArrowUpCmd+Shift+ArrowUp
Move lines down(selected lines)Ctrl+Shift+ArrowDownCmd+Shift+ArrowDown
Jump to previous !!Heading-Ctrl+ArrowUpCmd+ArrowUp
Jump to next !!Heading-Ctrl+ArrowDownCmd+ArrowDown
Jump to previous [[#anchor]]-Alt+ArrowUpOption+ArrowUp
Jump to next [[#anchor]]-Alt+ArrowDownOption+ArrowDown

[*] Here "..." means the cursor or the selected text.
[**] Cycle = Press multiple times until you reach the desired result. Press Ctrl+Z to cycle back to the previous insertion.

Eventually these will be configurable both per wiki and per-user.

Auto-Brackets

# enable start-of-line auto-insert, keyboard shortcuts
$EnableEditAutoText = 1;

# if NO text is selected, when typing opening bracket,
# insert opening and closing brackets around the cursor (optional):
$EditAutoBrackets['cursor'] = '"{[('; # insert "", {}, [], or ()

# if text IS selected, when typing opening bracket, wrap the
# selected text in the opening and closing brackets (optional):
$EditAutoBrackets['selection'] = '\'`~"{[(-+@^%_=<>';

If $EditAutoBrackets['cursor'] is enabled, typing an opening character automatically inserts the corresponding closing character after the cursor.

If $EditAutoBrackets['selection'] is enabled and text is selected, typing the opening character wraps the selection with the opening and closing characters.

The opening and closing characters are the same, except for these:

  ( inserts ()
  [ inserts []
  { inserts {}
  < inserts <> (useful for HTML)
  > inserts >< (useful for WikiStyles)

Eventually these will be configurable both per wiki and per-user.

Installation

For PmWiki 2.2.119 or newer, add to config.php:
$EnableEditAutoText = 1;

Since PmWiki 2.4.0, you can enable auto-brackets:
$EditAutoBrackets = array('('=>')', '['=>']', '{'=>'}', '"'=>'"');
Since PmWiki 2.5.9, auto-brackets definitions changed, see above.

Older PmWiki versions (only an older version is available):

  1. Place edithelp.js in your pmwiki/pub directory.
  2. Add to local/(farm)config.php such a line:
      if($action == 'edit') 
        $HTMLFooterFmt['edithelp'] = '<script type="text/javascript" src="$FarmPubDirUrl/edithelp.js"></script>';

Note, only start-of-line markup insertion is supported.

Notes

  • A recent browser with JavaScript enabled is needed for the recipe to work.
  • The recipe is likely incompatible with CodeMirror or with any of the WYSIWYG attempts.

Change log / Release notes

  • 20191003 added to PmWiki 2.2.119. For subsequent updates please see ChangeLog.
  • 20160317 First public release, ready to be tested.

See also

  • PmSyntax (Syntax highlighting for the PmWiki documentation and edit form) is compatible with this recipe.
  • The CodeMirror recipe also provides automatic insertion of list items, and more. Unfortunately, select-copy and middle-click-paste does not work with it so I cannot use it.
  • Worse (is better) Simple WYSIWYG editing for PmWiki
  • JsEditToolbar toolbar for the edit form with regex find & replace tools

Contributors

Recipe written and maintained by Petko.

Comments

See discussion at EditHelp-Talk

User notes : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.