Skip to content

SkepticMystic/advanced-cursors

Repository files navigation

Advanced Cursors

Advanced Cursors adds new commands to Obsidian which let you take more advantage of multiple cursors.

This plugin pairs really well with @spslater's Cursor Position plugin

Commands

Move to next instance of current selection

This command takes the text you currently have selected (or selects the word under the cursor if nothing is selected), and moves the cursor to the next instance of that same text.

If no next instance is found, it will loop back to the beginning of the note.

Add next instance of current selection to selections

This command does mostly the same as the previous, except it keeps your previous cursor selections in place. Similarly, if no next instance is found, it will loop back to the beginning of the note.

This does the same thing as Ctrl + d in VS Code.

Move to previous instance of current selection

Same as Move to next instance of current selection, except going backwards.

Add previous instance of current selection to selections

Same as Add next instance of current selection to selections, except going backwards.

Copy Line Up/Down

This command copies the currently selected lines up or down depending on which option you choose.

Like Alt + Shift + ↑/↓ in VS Code.

Inserting incrementing value at eachc ursor

Running this command opens a modal which lets you choose a start number, and an increment inc. On submitting, Advanced Cursors will overwrite each of your current selections with an incrementing value starting from start and incrementing by inc each cursor.

Both start and inc can be arbitray real numbers. The resulting number will be rounded to 4 decimals.

Open Regex match modal

This command allows even more fine-grained control of where you place the cursor.

When you open the modal, you will see a text input field, and submit button, and an option to toggle Regex.

image

Enter a search query into the input field, and Advanced Cursors will place a cursor at each place in the current document that matches the query.

Toggle Regex? for the query to be treated as a regex, or a string literal.

You can now also use Saved Queries to quickly run queries.

Saved Queries

In the settings tab of Advanced Cursors, you will see an interface allowing you to Add New Query. This allows you to set up a query (regex or literal) to quickly access from the Match Modal, or run as an Obsidian command from the command palette.

In the Add New Query modal, you have 4 options:

  1. The name of the query,
  2. The actual query itself,
  3. Any regex flags to apply to the query (if it is a regex),
    • The g flag is automatically added, but it won't break if you add it yourself.
  4. A toggle to say if the query should be interpretted as a regex or literal string.

image

Running Saved Queries

After adding a query, it will appear in a list of saved queries in settings:

image

In the Match Modal (Simply click the query to run it):

image

As well as in the command palette:

image

Query Examples

The following is a list of queries created by users of the plugin:

Unfinished Tasks

/^- \[ ] .*$/m

Completed Tasks

/^- \[x] .*$/m

Bullet List followed by Numbered List

/^- +[\d\w][\.\)] /m

Matches a bullet point followed by a numbered bullet:

  • - 1.
  • - 1)
  • - a.
  • - a)

Having both is usually redundant, so this allows you to remove one or the other.

Disjoint Bullet Items

/\n\n>? ?[-\d]+\.?/

If you prefer bullet points to not have an extra line between them, use this to find offending bullet points.

- 1

- 2

- 3

Select Sentences

/\b.*?\.(?=\s|$)/m

Select the shortest string between a word boundary \b and a fullstop \.

DOIs

/10\.[^\s]+\/[^\s]*\w/

URLs

/\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|(([^\s()<>]+|(([^\s()<>]+)))))+(?:(([^\s()<>]+|(([^\s()<>]+))))|[^\s`!()[]{};:'".,<>?«»“”‘’]))/

Copy DEVONthink Link to Clipboard

/\[Line\s\d{1,2}\]\(x-devonthink-item:\/\/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}\?line=\d{1,2}\)/
  • Look for all DT links in the note and copy then to clipboard;
  • Delete \(x-devonthink-item:\/\/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}\?line=\d{1,2}\)
  • Paste in the end of the note.

Capture all Highlights

/==.*?==/

Capture a Specific HTML Tag

/(?<=id="green">).*?(?=\<)/

Navigation Queries

Navigate between Headers

/^#+.*?$/m

Navigate between Backlinks (do not include block refs)

/(?<=\[\[)(?!.*#\^).*(?=\]\])/

Navigate to a specific tag

/#Tag/