Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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. #8707

Closed
1 task done
YoungHaKim7 opened this issue Mar 2, 2024 · 12 comments
Labels
autocompletions Feedback for code completions in the editor bug [core label] keymap / key binding Feedback for keyboard shortcuts, key mapping, etc vim

Comments

@YoungHaKim7
Copy link

Check for existing issues

  • 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 YoungHaKim7 added admin read Pending admin review bug [core label] triage Maintainer needs to classify the issue labels Mar 2, 2024
YoungHaKim7 added a commit to YoungHaKim7/rust_vim_setting that referenced this issue Mar 2, 2024
@Moshyfawn Moshyfawn added vim keymap / key binding Feedback for keyboard shortcuts, key mapping, etc autocompletions Feedback for code completions in the editor and removed triage Maintainer needs to classify the issue labels Mar 2, 2024
@JosephTLyons JosephTLyons removed the admin read Pending admin review label Mar 4, 2024
@raphaelluethy
Copy link
Contributor

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

@olrtg
Copy link
Contributor

olrtg commented Apr 16, 2024

Does this work for you?

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

@raphaelluethy
Copy link
Contributor

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

@YoungHaKim7
Copy link
Author

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"
    }
  }
]

@raphaelluethy
Copy link
Contributor

raphaelluethy commented Apr 23, 2024

@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?

@YoungHaKim7
Copy link
Author

YoungHaKim7 commented Apr 25, 2024

  {
    "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
Copy link
Author

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

@YoungHaKim7
Copy link
Author

YoungHaKim7 commented Apr 26, 2024

Tab and c-y work well.

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

test02.-.SD.480p.mp4

@raphaelluethy
Copy link
Contributor

@YoungHaKim7 Thanks a lot for clarifying!

YoungHaKim7 added a commit to YoungHaKim7/rust_vim_setting that referenced this issue Apr 28, 2024
ctlr+y 자동완성 질문해서 해결함(추가로 세팅해서 해결)
  - 결국 물어봄 ㅠㅠ(해결완료)
    - zed-industries/zed#8707
@leo91000
Copy link

leo91000 commented Sep 2, 2024

I have set this in my config :

  {
    "context": "Editor && showing_completions",
    "bindings": {
      "alt-l": "editor::ConfirmCompletion"
    }
  }

But when copilot suggest code, pressing Alt + L doesn't do anything, and Tab still works.

Does anyone have a similar issue ?

@elitan
Copy link

elitan commented Nov 24, 2024

This one worked for me:

  {
    "context": "Editor && inline_completion && !showing_completions",
    "bindings": {
      "tab": "editor::Tab",
      "cmd-enter": "editor::AcceptInlineCompletion"
    }
  }

I use cmd + enter to accept inline completion.

@kurt-rhee
Copy link

this didn't work for me using supermaven

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autocompletions Feedback for code completions in the editor bug [core label] keymap / key binding Feedback for keyboard shortcuts, key mapping, etc vim
Projects
None yet
Development

No branches or pull requests

8 participants