Block travel shortcut?

is there any extension like “block travel”? its essential for me in all text editors. allows you to jump to the next whitespace link with just a ctrl-arrow

otherwise you have to move line by line aaaagh!

or is there a way to customize and extend / add your own like this?

example for VScode, but now it’s built in like emacs, vim etc

and while we’re at it moving the current line up or down with option-arrow. being able to reorder lists and lines from the keyboard is a godsend.

I keep trying to use obsidian and then realize what a caveman experience it is for text editing compared to an actual coder editor that I drop it again.

It’s nice for writing long chunks of text though, maybe?

Fortunately, you can define hotkeys for this…and this time you don’t need an extra plugin! :slight_smile:

1 Like

nice, thanks for single line move. But i still yearn for block-travel!

Yeah, I looked and looked (and looked some more), even scouring plugins, but couldn’t find anything that moved block by block. There were a few plugins that added code editor style hotkeys, but not that particular one. :frowning:

So here are two customs commands which seems to do the trick. I’ve installed them into my test vault using the User Plugins plugin, and have each of the code blocks in their own snippet code block in the settings:

Previous block command

plugin.addCommand({
    name: 'Prev block',
    id: "prev-block",
    callback: () => {

// RESTARTS INDENTATION LEVELS

const activeFile = app.workspace.getActiveFile()  
const activeView = app.workspace.activeLeaf.view
if ( ! activeView ) {
  console.warn("No active view!")
} else {

  const editor = activeView.editor
  const currLine = editor.getCursor().line

  let candLine = currLine // Holds the possible end line
  const lastLine = editor.lastLine()

  let foundEmptyBlock = false

  // console.log("\n\nNew run with active view: ", activeView, currLine)
  
  while (!foundEmptyBlock ) {
    candLine -= 1
    if (candLine < 0) {
      candLine = 0
      break;
    }
    const line = editor.getLine(candLine)
    // console.log(currLine, candLine, line)
    foundEmptyBlock = line == '' || candLine < 0
  }
  editor.setCursor(candLine, 0)
}

// Next line ends addCommand and the callback
} });

Next block command

plugin.addCommand({
    name: 'Next block',
    id: "next-block",
    callback: () => {

// RESTARTS INDENTATION LEVELS

const activeFile = app.workspace.getActiveFile()  
const activeView = app.workspace.activeLeaf.view
if ( ! activeView ) {
  console.warn("No active view!")
} else {

  const editor = activeView.editor
  const currLine = editor.getCursor().line

  let candLine = currLine // Holds the possible end line
  const lastLine = editor.lastLine()

  let foundEmptyBlock = false

  // console.log("\n\nNew run with active view: ", activeView, currLine)
  
  while (!foundEmptyBlock ) {
    candLine += 1
    if (candLine > lastLine) {
      candLine = lastLine;
      break;
    }
    const line = editor.getLine(candLine)
    // console.log(currLine, candLine, line)
    foundEmptyBlock = line == '' 
  }
  editor.setCursor(candLine, 0)
}

// Next line ends addCommand and the callback
} }); 

And now after assign some hotkeys to the newly created User plugins: Next block and User plugins: Prev block I can skip back and forth on the empty blocks.

Caveat: These commands as they stand now can’t be used to extend the selection.

If you change any of the snippet code from the settings of User Plugins, remember to hit the > on the left of that block, and be sure to have the Console pane of Developers tool open to catch any potential error message after changing your code.

Other than that, happy traversal up and down between blocks! :smiley:

1 Like