zed icon indicating copy to clipboard operation
zed copied to clipboard

[vim] I usually use ctrl-y when I do autocomplete on Neovim, but I don't think it's possible to do it on zed.

Open YoungHaKim7 opened this issue 1 year ago • 3 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

Hello, I'm trying to map the project panel back to Vim key binding, but I usually use ctrl-y when I do autocomplete on Neovim, but I don't think it's possible to do it on zed.

  • keymap.json add
// CofirmComletion
{
    "context": "Editor && VimWaiting",
    "bindings": {
      "ctrl-y": "vim::Tab",
      "ctrl-y": "editor::ConfirmCompletion"
    }
}

my neovim cmp setting

cmp.setup({
  -- VsnipOpen , add more Rust Snippets
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },
  -- prefill with our custom snippets
  formatting = {
    format = lspkind.cmp_format({
      mode = 'symbol_text', -- show only symbol annotations
      maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)

      -- The function below will be called before any actual modifications from lspkind
      -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
      before = function (entry, vim_item)
        -- Get the full snippet (and only keep first line)
				local word = entry:get_insert_text()
				if entry.completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet then
					word = vim.lsp.util.parse_snippet(word)
				end
				word = str.oneline(word)

				-- concatenates the string
				-- local max = 50
				-- if string.len(word) >= max then
				-- 	local before = string.sub(word, 1, math.floor((max - 3) / 2))
				-- 	word = before .. "..."
				-- end

				if
					entry.completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet
					and string.sub(vim_item.abbr, -1, -1) == "~"
				then
					word = word .. "~"
				end
				vim_item.abbr = word

				return vim_item
      end
    })
  },
  mapping = {
    ["<C-d>"] = cmp.mapping.scroll_docs(-4),
    ["<C-u>"] = cmp.mapping.scroll_docs(4),
    ["<C-Space>"] = cmp.mapping.complete(),
    ["<C-e>"] = cmp.mapping.close(),
    ["<CR>"] = cmp.mapping.confirm({ select = true }),
    ["<C-y>"] = cmp.mapping.confirm({ select = true }),
    ["<Tab>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "s" }),
    ["<C-n>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "s" }),
    ["<S-Tab>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "s" }),
    ["<C-p>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "s" }),
  },
  sources = {
    { name = "nvim_lsp" },
    { name = "vsnip" },
    { name = "buffer" },
    { name = 'path' },
    { name = 'cmdline' }
  },
})
  • I want this function.
   ["<C-y>"] = cmp.mapping.confirm({ select = true }),
  • my keymap.json
[
  {
    "context": "Editor && VimControl && !VimWaiting && !menu",
    "bindings": {
      // put key-bindings here if you want them to work in normal & visual mode
    }
  },
  {
    "context": "Editor && vim_mode == normal && !VimWaiting && !menu",
    "bindings": {
      // put key-bindings here if you want them to work only in normal mode
      // ~~~~~~~ Normal Mode
      // Doc hover
      "K": "editor::Hover",
      // buffer :bn :bp
      "L": "pane::ActivateNextItem",
      "H": "pane::ActivatePrevItem",
      // quick fix
      "space g a": "editor::ToggleCodeActions",
      "] d": "editor::GoToDiagnostic",
      "[ d": "editor::GoToPrevDiagnostic",
      "g m": "editor::ExpandMacroRecursively",
      // LSP rename    "ga" multi cursor
      "space r": "editor::Rename",
      // symbol search   "gs"
      "space o": "project_symbols::Toggle",
      // NERDTree
      "space e": "project_panel::ToggleFocus",
      "space x": "workspace::CloseAllDocks",
      // Terminal Pannel(shell)
      "space s h": "terminal_panel::ToggleFocus",
      // trouble toggle
      "space t": "diagnostics::Deploy"
    }
  },
  {
    "context": "Editor && vim_mode == visual && !VimWaiting && !menu",
    "bindings": {
      // visual, visual line & visual block modes
      // ~~~~~~ Visual Mode
      "K": "editor::MoveLineUp",
      "J": "editor::MoveLineDown",
      "space g c": "editor::ToggleComments"
    }
  },
  {
    "context": "Editor && vim_mode == insert && !menu",
    "bindings": {
      // put key-bindings here if you want them to work in insert mode
      // ~~~~~~ Insert Mode
      "j k": ["vim::SwitchMode", "Normal"]
    }
  },
  {
    "context": "ProjectPanel",
    "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"
    }
  }
]

Environment

Zed: v0.124.8 (Zed) OS: macOS 14.2.1 23C71 arm64 Memory: 16 GiB Architecture: aarch64(M1 macPro)

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.

No response

YoungHaKim7 avatar Mar 02 '24 10:03 YoungHaKim7

Really would love to have the ability to remap the copilot accept key, as I also have it remapped to <C-j>, as I sometimes accepted suggestions I didn't mean to. Hopefully this could be added soon 🙏

raphaelluethy avatar Apr 14 '24 21:04 raphaelluethy

Does this work for you?

{
  "context": "Editor && showing_completions",
  "bindings": {
    "ctrl-y": "editor::ConfirmCompletion"
  }
}

olrtg avatar Apr 16 '24 14:04 olrtg

Does this work for you?

{
  "context": "Editor && showing_completions",
  "bindings": {
    "ctrl-y": "editor::ConfirmCompletion"
  }
}

For me it didn't on the latest Preview version. Also I would need the option to unbind tab, as this is just as important for my usecase

raphaelluethy avatar Apr 17 '24 00:04 raphaelluethy

thank you.

[
  {
    "context": "Editor && VimControl && !VimWaiting && !menu",
    "bindings": {
      // put key-bindings here if you want them to work in normal & visual mode
    }
  },
  {
    "context": "Editor && vim_mode == normal && !VimWaiting && !menu",
    "bindings": {
      // put key-bindings here if you want them to work only in normal mode
      // ~~~~~~~ Normal Mode
      // Doc hover
      "K": "editor::Hover",
      // buffer :bn :bp
      "L": "pane::ActivateNextItem",
      "H": "pane::ActivatePrevItem",
      // quick fix
      "space g a": "editor::ToggleCodeActions",
      "] d": "editor::GoToDiagnostic",
      "[ d": "editor::GoToPrevDiagnostic",
      "g m": "editor::ExpandMacroRecursively",
      // LSP rename    "ga" multi cursor
      "space r": "editor::Rename",
      // symbol search   "gs"
      "space o": "project_symbols::Toggle",
      // NERDTree
      "space e": "project_panel::ToggleFocus",
      "space x": "workspace::CloseAllDocks",
      // Terminal Pannel(shell)
      "space s h": "terminal_panel::ToggleFocus",
      // trouble toggle
      "space t": "diagnostics::Deploy"
    }
  },
  {
    "context": "Editor && vim_mode == visual && !VimWaiting && !menu",
    "bindings": {
      // visual, visual line & visual block modes
      // ~~~~~~ Visual Mode
      "K": "editor::MoveLineUp",
      "J": "editor::MoveLineDown",
      "space g c": "editor::ToggleComments"
    }
  },
  {
    "context": "Editor && vim_mode == insert && !menu",
    "bindings": {
      // put key-bindings here if you want them to work in insert mode
      // ~~~~~~ Insert Mode
      "j k": ["vim::SwitchMode", "Normal"]
    }
  },
  {
    "context": "Editor && showing_completions",
    "bindings": {
      "ctrl-y": "editor::ConfirmCompletion"
    }
  },
  {
    "context": "Editor && vim_mode == insert && menu",
    "bindings": {
      // put key-bindings here if you want them to work in insert mode
      // ~~~~~~ Insert Mode
      "j k": ["vim::SwitchMode", "Normal"]
    }
  },
  {
    "context": "ProjectPanel",
    "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"
    }
  }
]

YoungHaKim7 avatar Apr 23 '24 10:04 YoungHaKim7

@YoungHaKim7 did you manage to unbind tab from autocompleting? Edit: also the bind still does not work for me, do I need to open a new issue?

raphaelluethy avatar Apr 23 '24 13:04 raphaelluethy

  • https://github.com/YoungHaKim7/rust_vim_setting/tree/main/11_Zed_Editor

  • keymap.json

  {
    "context": "Editor && showing_completions",
    "bindings": {
      "ctrl-y": "editor::ConfirmCompletion"
    }
  },

It works very well when you apply json in the key map like this.

  • setting.json
// Zed settings
//
// For information on how to configure Zed, see the Zed
// documentation: https://zed.dev/docs/configuring-zed
//
// To see all of Zed's default settings without changing your
// custom settings, run the `open default settings` command
// from the command palette or from `Zed` application menu.
{
  "theme": "Tokyo Night gy InlayHint red",
  "ui_font_family": "Hack Nerd Font Mono",
  "vim_mode": true,
  "ui_font_size": 22,
  "buffer_font_size": 22,
  // Set the buffer's line height.
  // May take 3 values:
  //  1. Use a line height that's comfortable for reading (1.618)
  //"line_height": "comfortable",
  //  2. Use a standard line height, (1.3)
  //"line_height": "standard",
  //  3. Use a custom line height
  "line_height": {
    "custom": 1.0
  },
  "relative_line_numbers": true,
  // disable cursor blink
  // "cursor_blink": false,
  "inlay_hints": {
    // Global switch to toggle hints on and off, switched off by default.
    "enabled": true,
    // Toggle certain types of hints on and off, all switched on by default.
    "show_type_hints": true,
    "show_parameter_hints": true,
    // Corresponds to null/None LSP hint type value.
    "show_other_hints": true
  },
  "project_panel": {
    // Default width of the project panel.
    "default_width": 240,
    // Where to dock project panel. Can be 'left' or 'right'.
    "dock": "right",
    // Whether to show file icons in the project panel.
    "file_icons": true,
    // Whether to show folder icons or chevrons for directories in the project panel.
    "folder_icons": true,
    // Whether to show the git status in the project panel.
    "git_status": true,
    // Amount of indentation for nested items.
    "indent_size": 20,
    // Whether to reveal it in the project panel automatically,
    // when a corresponding project entry becomes active.
    // Gitignored entries are never auto revealed.
    "auto_reveal_entries": true
  },
  "prettier": {
    // Use regular Prettier json configuration:
    // "trailingComma": "es5",
    // "tabWidth": 4,
    // "semi": false,
    // "singleQuote": true
  },
  // LSP Specific settings.
  "lsp": {
    // Specify the LSP name as a key here.
    "rust-analyzer": {
      //     //These initialization options are merged into Zed's defaults
      "initialization_options": {
        "checkOnSave": {
          "command": "clippy"
        }
      }
      // }
    }
  }
}

YoungHaKim7 avatar Apr 25 '24 08:04 YoungHaKim7

I haven't tested the tab, so I'll test it..

YoungHaKim7 avatar Apr 26 '24 07:04 YoungHaKim7

Tab and c-y work well.

The TAB is the default key, so you don't have to set it up separately.

https://github.com/zed-industries/zed/assets/67513038/ad8f6233-1343-43d3-b5ca-27cd772056a2

YoungHaKim7 avatar Apr 26 '24 10:04 YoungHaKim7

@YoungHaKim7 Thanks a lot for clarifying!

raphaelluethy avatar Apr 26 '24 11:04 raphaelluethy