# \[Hotkeys\] Assigning "longer sequence of the key combinations"

**URL:** <https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346>\
**Category:** Help\
**Created:** [February 8, 2025, 6:38pm UTC](https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346 "2025-02-08T18:38:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![DiCaver](https://forum.obsidian.md/user_avatar/forum.obsidian.md/dicaver/32/70059_2.png) [@DiCaver](https://forum.obsidian.md/u/DiCaver)\
**Post date:** [February 8, 2025, 6:38pm UTC](https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346/1 "2025-02-08T18:38:37Z")

</div>

### What I’m trying to do

Assign a “longer sequence of the key combinations”. Straightforward question:

**How can I assign this sequence to some key combination?** `Ctrl + E` + `Ctrl + Home` + `Ctrl + E` + `Ctrl + Home` (Windows)

I don’t have a separate heading for the note title, so it bothers me when I click `Ctrl + Home` that it doesn’t jump to the top of the note but to the top of the editing area. Which I understand, but I still want to go with my way 🙂

### Things I have tried

I tried a few plugins that promised to assign multiple key combinations, but none worked, or I didn’t know how.

So, I’m looking for ideas, plugins, or a solution. If not, I’ll suggest a feature request, which is an option to enable/disable this 😜

Cheers, Marko 🤓

---

<div class="post-metadata">

**Author:** ![Yurcee](https://forum.obsidian.md/user_avatar/forum.obsidian.md/yurcee/32/53074_2.png) [@Yurcee](https://forum.obsidian.md/u/Yurcee)\
**Post date:** [February 8, 2025, 6:47pm UTC](https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346/2 "2025-02-08T18:47:18Z")

</div>

Make a Templater or other js script joining `app.commands.executeCommandById()` instances. But you’d need to await them or separate them with sleep so they don’t get executed at the same time.  
Then you’d bind CTRL+HOME to this command.

---

<div class="post-metadata">

**Author:** ![DiCaver](https://forum.obsidian.md/user_avatar/forum.obsidian.md/dicaver/32/70059_2.png) [@DiCaver](https://forum.obsidian.md/u/DiCaver)\
**Post date:** [February 8, 2025, 8:01pm UTC](https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346/3 "2025-02-08T20:01:26Z")

</div>

Not sure how to achieve this.

 ![image](https://forum.obsidian.md/uploads/default/original/3X/4/1/417c5645ed04fa579df75393c269ebc947e2bc51.png)

I made a user script, but I don’t know how to bind a key. I tried to call this function in one template, but it also created a new note. Or I’m barking into the wrong part of Templater 🙂

Still new in Templater … ok, also in Obsidian 😄

Cheers, Marko 🤓

---

<div class="post-metadata">

**Author:** ![Yurcee](https://forum.obsidian.md/user_avatar/forum.obsidian.md/yurcee/32/53074_2.png) [@Yurcee](https://forum.obsidian.md/u/Yurcee)\
**Post date:** [February 8, 2025, 8:25pm UTC](https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346/4 "2025-02-08T20:25:20Z")

</div>

You are not showing what you cooked up, either.

Then you need to register the Templater file – if you picked Templater (but I meant .md script not .js) – in this section:

 ![{0A421C7B-67F2-4C96-8BEA-9FAE897409F2}](https://forum.obsidian.md/uploads/default/original/3X/5/f/5f2632f7c0a9e22bc5b1b4ecd0dfed3a75a2f5e4.png)

---

<div class="post-metadata">

**Author:** ![Yurcee](https://forum.obsidian.md/user_avatar/forum.obsidian.md/yurcee/32/53074_2.png) [@Yurcee](https://forum.obsidian.md/u/Yurcee)\
**Post date:** [February 8, 2025, 9:24pm UTC](https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346/5 "2025-02-08T21:24:36Z")

</div>

Okay, so the duplication of CTRL+E + CTRL+HOME is necessitated because you cannot go home in Reading mode, correct?  
Then I don’t know…do you have Properties set to Visible? (I don’t.) Do you want to look at that if you do have it set to Visible…?

Then…even if you have a top level heading, you cannot (normally) go higher than the top of the editor, below the YAML (but as I said, I have Properties hidden and I’m mostly in Live Preview).  
So if you absolutely must go to the very first line, that would be line zero that you can get to in Source Mode.

Using [CodeScript Toolkit plugin](https://forum.obsidian.md/t/plugin-codescript-toolkit/94399) (as my go-to plugin to make scripts, as I explained in that thread), I created a script that switches to source mode to be able to go to the absolute top possible and then switches to Reading mode (if that’s what’s required or you want editing mode?):

```auto
import { App, Plugin } from "obsidian";

const gotoFirstLine = async (app: App): Promise<void> => {
    const leaf = app.workspace.activeLeaf;
    if (!leaf) return;

    // Switch to source mode first
    const viewState = leaf.getViewState();
    viewState.state.mode = "source";
    viewState.state.source = true;
    await leaf.setViewState(viewState);

    // Wait for the state to fully apply
    await new Promise((resolve) => setTimeout(resolve, 100));

    // Get editor and move cursor to line 0
    const editor = leaf.view?.editor;
    if (editor) {
        editor.setCursor({ line: 0, ch: 0 });
    }

    // Switch to reading mode
    viewState.state.mode = "preview";
    await leaf.setViewState(viewState);
};

export class GotofirstlinePlugin extends Plugin {
    async onload() {
        this.addCommand({
            id: "go-to-first-line",
            name: "Go to first line",
            callback: async () => await gotoFirstLine(this.app),
        });
    }
}

// This function will work on both desktop and mobile
export async function invoke(app: App): Promise<void> {
    return gotoFirstLine(app);
}

```

Save this as `Go to First Line.ts` in the folder where you will store your CodeScript ts (TypeScript) files.

 ![{017F6DC5-EA56-4421-B76F-AADE06AE3ABA}](https://forum.obsidian.md/uploads/default/original/3X/d/8/d8ceffe1aaff63e895f730acbdf0788f9b5f72ec.png)

You can bind a hotkey of your choice to this script:

 ![{746BA371-D981-4F58-BBED-AC7BAFF331C2}](https://forum.obsidian.md/uploads/default/original/3X/a/4/a4d9611a1f61a8250bb6c10ad385a7531a6a1c22.png)

---

<div class="post-metadata">

**Author:** ![DiCaver](https://forum.obsidian.md/user_avatar/forum.obsidian.md/dicaver/32/70059_2.png) [@DiCaver](https://forum.obsidian.md/u/DiCaver)\
**Post date:** [February 9, 2025, 7:44pm UTC](https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346/6 "2025-02-09T19:44:14Z")

</div>

@Yurcee, sorry for “disappearing”, but we probably have a time difference, and today I had a family trip 🙂

Last night, I was tired, and yes, it was not enough or clear what and how I wanted. But actually, your previous post put me on the right path. Didn’t know about this plugin. Now, I was playing for an hour to figure it out.

Your script is working! But, due to a lack of information from my side, not as I wanted. I wanted this - “jump under the title” in Editing mode.

This is the TS that works for me now:

```ts
import { App, Editor } from "obsidian";

export async function customCtrlHome(app: App): Promise<void> {
  const activeLeaf = app.workspace.activeLeaf;
  if (!activeLeaf) {
    alert("activeLeaf not found!");
    return;
  }

  // Get the active editor
  const editor = activeLeaf.view?.editor as Editor;
  if (!editor) {
    alert("Editor not found!");
    return;
  }

  // Ensure the cursor is placed at the start
  editor.setCursor({ line: 0, ch: 0 });

  // Scroll slightly above the first line to reveal the title
  editor.scrollIntoView(
    { from: { line: 0, ch: 0 }, to: { line: 3, ch: 0 } },
    true
  );
}

// Register the function
export async function invoke(app: App): Promise<void> {
  return customCtrlHome(app);
}

```

The original script had 20 more lines 😄 as I was jumping on the top, at the beginning and so on. Then I found `scrollIntoView()`, which does exactly what I wanted. But before that, I `setCursor()` at the beginning of the note.

I marked your suggestion for the script as a solution, as … in my opinion … is the solution. The rest was to find which script 🙂

Thanks for all your effort, and take care!

Cheers, Marko 🤓

---

<div class="post-metadata">

**Author:** ![Yurcee](https://forum.obsidian.md/user_avatar/forum.obsidian.md/yurcee/32/53074_2.png) [@Yurcee](https://forum.obsidian.md/u/Yurcee)\
**Post date:** [February 9, 2025, 8:14pm UTC](https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346/7 "2025-02-09T20:14:20Z")

</div>

> [@DiCaver](#):
>
> have a time difference

I don’t think so. I am on original Kornel David’s time, you are on Luka’s.

> [@DiCaver](#):
>
> I had a family trip

Approved!

> [@DiCaver](#):
>
> I found `scrollIntoView()`, which does exactly what I wanted.

I had an idea you’d be acing this. That’s why I added my bit.  
Next time you’ll be all over Share&Showcase with .ts files. → Money. 😛

---

<div class="post-metadata">

**Author:** ![DiCaver](https://forum.obsidian.md/user_avatar/forum.obsidian.md/dicaver/32/70059_2.png) [@DiCaver](https://forum.obsidian.md/u/DiCaver)\
**Post date:** [February 9, 2025, 8:23pm UTC](https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346/8 "2025-02-09T20:23:01Z")

</div>

> [@Yurcee](#):
>
> I am on original Kornel David’s time, you are on Luka’s.

OK, this is one of the best replies I ever heard! 😄 👌

---

<div class="post-metadata">

**Author:** ![Yurcee](https://forum.obsidian.md/user_avatar/forum.obsidian.md/yurcee/32/53074_2.png) [@Yurcee](https://forum.obsidian.md/u/Yurcee)\
**Post date:** [February 9, 2025, 8:27pm UTC](https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346/9 "2025-02-09T20:27:23Z")

</div>

> **[Dávid Kornél és Doncic – új sorozatot indít a Sport TV, Scherer Péter mesél...](https://telex.hu/sport/2024/11/03/david-kornel-doncic-rodman-sorozat-sport-tv)**
>
> Rodman, Curry, LeBron James karrierjét is láthatjuk a tízrészes műsorban.

---

<div class="post-metadata">

**Author:** ![DiCaver](https://forum.obsidian.md/user_avatar/forum.obsidian.md/dicaver/32/70059_2.png) [@DiCaver](https://forum.obsidian.md/u/DiCaver)\
**Post date:** [February 10, 2025, 5:35am UTC](https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346/10 "2025-02-10T05:35:55Z")

</div>

What kiddo he was, and look him now!

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [March 10, 2025, 5:36am UTC](https://forum.obsidian.md/t/hotkeys-assigning-longer-sequence-of-the-key-combinations/96346/11 "2025-03-10T05:36:24Z")

</div>

Closed on March 10, 2025, 5:36am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
