astronaut

How to use NvimTree Keybindings in Zed

How to use NvimTree Keybindings in Zed

October 18, 2024 2 min read
Zed + NvimTree

What is Zed?

Zed is a new code editor designed to prioritize speed, collaboration, and customization. Built with the modern developer in mind, Zed provides a minimalistic yet powerful interface. It supports efficient workflows through features like collaborative editing, built-in terminal, and an easily configurable keybinding system.

Overview of NvimTree and Why It Matters

NvimTree is a file explorer for Neovim that enhances file navigation through keybindings modeled after Vim's motion mechanics. Many developers prefer NvimTree due to its efficiency and the way it integrates seamlessly with Vim's workflow. Using similar keybindings in Zed can make the transition between these tools more natural, saving time and reducing friction for Vim users.

Setting Up Keybindings in Zed

To configure NvimTree-like keybindings in Zed, you need to create or modify the configuration file for keybindings. Zed uses a JSON-like format for defining these keybindings, which allows you to map keys to specific actions within the editor's project panel.

Setting up NvimTree Keybindings in Zed

  1. Open the Configuration File:
    • Press Ctrl+K followed by Ctrl+S to open the keybinding configuration file in Zed.
    • Alternatively you can open the keybinding configuration file located under ~/.config/zed/keymap.json
  2. Add NvimTree-Like Keybindings:
    • Copy and paste the following configuration (Source: GitHub):
{
    "context": "ProjectPanel && not_editing",
    "bindings": {
        "h": "project_panel::CollapseSelectedEntry",
        "l": "project_panel::ExpandSelectedEntry",
        "j": "menu::SelectNext",
        "k": "menu::SelectPrev",
        "o": "menu::Confirm",
        "r": "project_panel::Rename",
        "z c": "project_panel::CollapseSelectedEntry",
        "z o": "project_panel::ExpandSelectedEntry",
        "shift-o": "project_panel::RevealInFinder",
        "x": "project_panel::Cut",
        "c": "project_panel::Copy",
        "p": "project_panel::Paste",
        "d": "project_panel::Delete",
        "a": "project_panel::NewFile",
        "shift-a": "project_panel::NewDirectory",
        "shift-y": "project_panel::CopyRelativePath",
        "g y": "project_panel::CopyPath"
    }
}

This maps keys for expanding (l), collapsing (h), navigating (j, k), and file operations (o, r, d), closely resembling NvimTree’s behavior.

Keybinding Functions

  • Collapse/Expand (h, l, z c, z o)
  • Navigate (j, k)
  • File Operations:
    • o: Open
    • r: Rename
    • a: New File
    • shift-a: New Directory
    • x, c, p, d: Cut, Copy, Paste, Delete
  • Path Operations:
    • shift-y: Copy Relative Path
    • g y: Copy Full Path

Conclusion

Setting up NvimTree-like keybindings in Zed enhances your coding efficiency by leveraging familiar shortcuts. Adjust and test configurations as needed to create a seamless experience.

Share this content: