Skip to content

feat(commands): quick jump#2004

Merged
pynappo merged 8 commits into
nvim-neo-tree:mainfrom
stupidbullet:feat/quick_jump
May 20, 2026
Merged

feat(commands): quick jump#2004
pynappo merged 8 commits into
nvim-neo-tree:mainfrom
stupidbullet:feat/quick_jump

Conversation

@stupidbullet

Copy link
Copy Markdown
Contributor

Command quick_jump can dynamically compute, assign and render hotkeys for jumping to a specific node, while also monitoring key inputs to handle jump/toggle/cancel actions.

A default leader key for this function ; has been added in defaults.lua now, but no description has been written in doc.

When neo-tree is focused, pressing ; re-renders all icons and displays maps that can be used to jump to/toggle nodes.

Besides, it is possible to bind this action to a global hotkey, for example:

    local manager = require("neo-tree.sources.manager")
    local commands = require("neo-tree.sources.common.commands")

    for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
      local state = manager.get_state_for_window(win)
      if state and state.tree then
        vim.api.nvim_set_current_win(win)
        commands.quick_jump(state)
        return
      end
    end

This searches for neo-tree window, focuses it, then triggers the function.
It may be helpful to embed it as actions (like focus, show).

@pynappo pynappo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool idea. not totally sure if it has to be in neo-tree but will suggest improvements nonetheless

Comment thread lua/neo-tree/sources/common/commands.lua Outdated
Comment thread lua/neo-tree/utils/init.lua Outdated
Comment thread lua/neo-tree/utils/init.lua Outdated
@stupidbullet

Copy link
Copy Markdown
Contributor Author

Thanks a lot for your helpful advice, especially for someone new to plugin development :-)

I had barely considered customizability, but this part has been added into the code in the newest commit.

Now it is possible to write different post-jump callback for each sources, as well as jump labels.
However, I decided to keep the builtin open-or-toggle node function, it was my original intention for writing this feature.
Besides, perhaps it is the key to distinguishing the built-in jump from other jump plugins. Of course, we can also use a slightly more complex function to implement the same callback with other plugins (as long as they support it), but having a slightly more advanced built-in advanced function might be a reason people choose to use it.

Rendering is also a point. Most jump plugins attends to overlap its hotkeys among the original word, and it is sometimes inconvenient that I cannot read the filename. Replacing the icon was easily implemented internally, and it perfectly solved this problem.

@stupidbullet

Copy link
Copy Markdown
Contributor Author

Also, hotkeys will no longer be exhausted now.

Comment thread lua/neo-tree/sources/common/commands.lua Outdated
Comment thread lua/neo-tree/defaults.lua Outdated
Comment thread lua/neo-tree/utils/init.lua Outdated
---@param ch string
---@param depth integer
---@return table<neotree.FileNode, string> candidate
M.get_candidate = function(node2key, ch, depth)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem too highly specific to belong to utils. I would keep all of these functions in sources/common/commands.lua or somewhere like sources/common/lib/jump.lua if you want a separate file

@stupidbullet stupidbullet Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a separate file is better, as commands is long enough now and these helpers also are not used anywhere else.

stupidbullet and others added 4 commits May 20, 2026 02:26
on_jump: Now it is possible to use the on_jump field in the config to
set a custom post-jump callback for each source.

jump_labels: Hotkeys will generated according to the priority of the
jump labels in the config. Hotkeys will no longer be exhausted.
Use node as keys in the node-name mapping to avoid name collisions.
Co-authored-by: pynappo <lehtien.david@gmail.com>
@pynappo pynappo force-pushed the feat/quick_jump branch from 1e30753 to 431a738 Compare May 20, 2026 09:28
@pynappo pynappo merged commit 8f858a7 into nvim-neo-tree:main May 20, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants