Is there any way to make the line where the cursor is located back to the center/top of the screen?

Use the following QuickAdd user script!

  1. Create recenter.js in your vault.
// recenter.js
module.exports = ({ app }) => {
    const editor = app.workspace.activeEditor?.editor;
    if (!editor) return;
    editor.scrollIntoView(
        {
            from: editor.getCursor('from'),
            to: editor.getCursor('to')
        },
        true
    );
}
  1. Create a Macro choice using this user script (detailed instruction here):

Don’t forget to click the thunder icon to make this macro runnable as a standalone command:

  1. Set a hotkey for this macro.

You can find more information about the Editor interface of the Obsidian API here:

5 Likes