Multiline Cursor Code Block Editing in Markdown with EtherPK

EtherPK (https://app.etherpk.com) keeps your code in your notes as ordinary Markdown using fenced back tick code blocks. This post demonstrates recent upgrades to fenced code block editing in EtherPK including multi-line / multi-cursor editing, line numbers and copy assistance.

Copy a block, or one line

Move the pointer over a block, or put the cursor in the block, and a Copy code button shows at the block's top right. It copies the code and leaves the fences out. A tick shows for a moment once the copy is made.

The Copy code button showing a tick after a block of four lines was copied

For one line, move the pointer onto its number. The number turns into a copy icon, and a click copies that line with its own indentation.

In the video both blocks sit under a bullet. In the file, that means every line of them starts with two spaces, so the block lines up with the bullet's text. A copy leaves those two spaces out, and a paste into another bullet's block puts them back, which is why the pasted lines land in the right place without any fixing up.

Several cursors (Multi-cursor editing)

If you've used Notepad++, the keys will be familiar.

  • Alt+Shift+Down and Alt+Shift+Up add a cursor on the next line.
  • Alt+Shift+Right and Alt+Shift+Left widen and narrow the selection on every line.
  • Hold Alt and drag to select a rectangle. Hold Ctrl (Cmd on a Mac) and click to add a cursor anywhere in the block.
  • Escape goes back to one cursor.

What you type goes in on every line. The first edit in the video renames a field on four lines of a table. The lines aren't the same length, so I don't count columns: Ctrl+Shift+Right selects the word after each cursor, and bed replaces all four. End then takes each cursor to the end of its own line, and the comment goes on wherever that is.

Four lines of a JavaScript table with a cursor at the end of each, after a field was renamed and a comment added on all four

The second edit is the one I use most. The lines are different lengths and I want a comment on each, lined up. An Alt drag down the block, to the right of the longest line, puts a cursor on every line, in a straight column past the end of the text:

Four short shell lines of different lengths, with a cursor on each in a straight column to the right of the longest line

Typing there fills the gap with spaces first, so the four comments start in the same column.

Once you press a plain arrow key, Home or End, each cursor moves on its own line from then on. Backspace, Delete, Tab and Enter work at every cursor too. The cursors stay inside the one block, and this needs a keyboard, so it isn't on a phone.

Still plain Markdown

None of this is stored anywhere but the text. A block under a bullet is this in the file, and nothing more:

- This evening
  ```sh
  water beans        # today
  feed hens          # today
  weed the long bed  # today
  dig                # today
  ```

So the same file opens in any other Markdown editor, and a coding agent that reads your notes folder sees the code as you wrote it.

The keys are listed in full in the code blocks docs.