Ctrl-J / Ctrl-K Hotkey for navigation within command palette and quick switcher

1. Have you searched for an existing request?

like this:

2. Use case or problem

for workaround of wrong operatoin, I use some commands without shortcut key. so, I use command palette, and need to move right hand for taking a command.

3. Proposed solution

I hope:
ctrl+j: move down in command palette
ctrl+k: move up in commadn palette
enter: to use the command
ctrl+[: dismiss

with these shotcut key, I’m sure to feel so happy.
my hands, too.

4. Current workaround (optional)

move my right hand to arrow keys.

5. Related feature requests (optional)

16 Likes

I didn’t know I wanted this!

3 Likes

In a obsidian, I hope to any operation without mouse, with arrow keys a little.
I imagine my operations for vim-mode, and know others imagine them for emacs-mode.
so, It would be imagined what hot-key is changed to.

I was about to make a separate post, but I think I can tag it here cos it seems similar.

I’ve wanted to have ctrl+j/k in the popup for link suggestions in addition to the palette. It’s pretty standard in Vim, Spacemacs and VSCodeVim as well.

So I guess it’s a related feature request? Enter and ctrl+[ work the same way too.

2 Likes

I really hope this feature will come soon. I use CTRL-J and CTRL-K everywhere I can to scroll in suggestions.

4 Likes

Fully agree. Probably should be customized depending on your preferences (Emacs style or vim style).

Personally, I always try Ctrl-J and Ctrl-K every time I open the command palette, before realizing I cannot do that.

2 Likes

I use Karabiner to map ctrl-n and ctrl-p to down and up arrows respectively. In Karabiner, you can set the mapping only while Obsidian is active.

If any one wants to try, here is mapping in my karabiner.json.

2 Likes

I’d love to see this!

Any update? Obsidian v0.15.6 already supports using “ctrl-n/p” to navigate, will “ctrl-j/k” to be possible?

I made it work by calling this JS code at obsidian startup. You can do this with various plugins or by making your own plugin.


    document.addEventListener('keydown',(e) =>{
        if (e.code == "KeyN" && e.ctrlKey && !e.shiftKey && !e.metaKey){
            document.dispatchEvent(new KeyboardEvent("keydown",{"key":"ArrowDown","code":"ArrowDown"}))
        }
    });

    document.addEventListener('keydown',(e) =>{
        if (e.code == "KeyP" && e.ctrlKey && !e.shiftKey && !e.metaKey){
            document.dispatchEvent(new KeyboardEvent("keydown",{"key":"ArrowUp","code":"ArrowUp"}))
        }
    });

This code listens for Ctrl+N and Ctrl+P key press events and creates a new ArrowDown/ArrowUp event.

It could be made more specific by attaching the event listener to the specific DOM elements where you want this functionality.

Just building off of anotherroot’s response you can check to see what the active element is, not sure if you can add the listener to the suggester element since it doesn’t exist when obsidian is first loaded.

I also added e.preventDefault() so my other hotkeys weren’t trying to run and swapped metaKey and ctrlKey since I’m on mac.

document.addEventListener('keydown',(e) =>{
	if (document.activeElement && document.activeElement.hasClass('prompt-input') && e.code == "KeyJ" && e.metaKey && !e.shiftKey && !e.ctrlKey){
		e.preventDefault();
		document.dispatchEvent(new KeyboardEvent("keydown",{"key":"ArrowDown","code":"ArrowDown"}))
	}
});
document.addEventListener('keydown',(e) =>{
	if (document.activeElement && document.activeElement.hasClass('prompt-input') && e.code == "KeyK" && e.metaKey && !e.shiftKey && !e.ctrlKey){
		e.preventDefault();
		document.dispatchEvent(new KeyboardEvent("keydown",{"key":"ArrowUp","code":"ArrowUp"}))
	}
});

@nick_s where do you place the code snippet?

I managed to make it work by creating a plugin using this guide: Create your first plugin | Obsidian Plugin Developer Docs.

I then replaced main.ts with the contents below: