aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2024-05-24 11:33:49 -0500
committerGitHub <noreply@github.com>2024-05-24 11:33:49 -0500
commit2c6b6358722b2df9160c3739b0cea07e8779513f (patch)
tree017a917df879890f441e7fabc00db1fc94339ae9
parent206f8f24a2470f961cfe7e7c177443c0f199231c (diff)
downloadrneovim-2c6b6358722b2df9160c3739b0cea07e8779513f.tar.gz
rneovim-2c6b6358722b2df9160c3739b0cea07e8779513f.tar.bz2
rneovim-2c6b6358722b2df9160c3739b0cea07e8779513f.zip
feat(defaults): add LSP default mappings (again) (#28650)
-rw-r--r--runtime/doc/change.txt7
-rw-r--r--runtime/doc/lsp.txt13
-rw-r--r--runtime/doc/news.txt6
-rw-r--r--runtime/doc/vim_diff.txt5
-rw-r--r--runtime/lua/vim/_defaults.lua25
5 files changed, 52 insertions, 4 deletions
diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt
index 09db651614..9ff16165d7 100644
--- a/runtime/doc/change.txt
+++ b/runtime/doc/change.txt
@@ -281,6 +281,13 @@ gr{char} Replace the virtual characters under the cursor with
that have a special meaning in Insert mode, such as
most CTRL-keys, cannot be used.
+ *gr-default*
+ Nvim creates default mappings with "gr" as a prefix,
+ which may inhibit the behavior of |gr|. Use the
+ following to restore the builtin behavior: >
+ nnoremap <nowait> gr gr
+<
+
*digraph-arg*
The argument for Normal mode commands like |r| and |t| is a single character.
When 'cpo' doesn't contain the 'D' flag, this character can also be entered
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 5729531b30..ba5dd5fbef 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -61,6 +61,16 @@ options are not restored when the LSP client is stopped or detached.
- |K| is mapped to |vim.lsp.buf.hover()| unless |'keywordprg'| is customized or
a custom keymap for `K` exists.
+ *grr* *gra* *grn* *i_CTRL-S*
+Some keymaps are created unconditionally when Nvim starts:
+- "grn" is mapped in Normal mode to |vim.lsp.buf.rename()|
+- "gra" is mapped in Normal and Visual mode to |vim.lsp.buf.code_action()|
+- "grr" is mapped in Normal mode to |vim.lsp.buf.references()|
+- CTRL-S is mapped in Insert mode to |vim.lsp.buf.signature_help()|
+
+If not wanted, these keymaps can be removed at any time using
+|vim.keymap.del()| or |:unmap| (see also |gr-default|).
+
*lsp-defaults-disable*
To override the above defaults, set or unset the options on |LspAttach|: >lua
@@ -80,9 +90,6 @@ Example: >lua
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
- if client.supports_method('textDocument/rename') then
- -- Create a keymap for vim.lsp.buf.rename()
- end
if client.supports_method('textDocument/implementation') then
-- Create a keymap for vim.lsp.buf.implementation
end
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 03f6f7f8fd..708e127136 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -79,7 +79,11 @@ API
DEFAULTS
-• TODO
+• Keymaps:
+ - |grn| in Normal mode maps to |vim.lsp.buf.rename()|
+ - |grr| in Normal mode maps to |vim.lsp.buf.references()|
+ - |gra| in Normal and Visual mode maps to |vim.lsp.buf.code_action()|
+ - CTRL-S in Insert mode maps to |vim.lsp.buf.signature_help()|
EDITOR
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 15134531e1..5d894bb5e1 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -138,6 +138,11 @@ of these in your config by simply removing the mapping, e.g. ":unmap Y".
- * |v_star-default|
- gc |gc-default| |v_gc-default| |o_gc-default|
- gcc |gcc-default|
+- gr prefix |gr-default|
+ - |grn|
+ - |grr|
+ - |gra|
+- <C-S> |i_CTRL-S|
- ]d |]d-default|
- [d |[d-default|
- <C-W>d |CTRL-W_d-default|
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua
index 7015d376ae..5b964b84a0 100644
--- a/runtime/lua/vim/_defaults.lua
+++ b/runtime/lua/vim/_defaults.lua
@@ -149,6 +149,31 @@ do
vim.keymap.set({ 'o' }, 'gc', textobject_rhs, { desc = 'Comment textobject' })
end
+ --- Default maps for LSP functions.
+ ---
+ --- These are mapped unconditionally to avoid different behavior depending on whether an LSP
+ --- client is attached. If no client is attached, or if a server does not support a capability, an
+ --- error message is displayed rather than exhibiting different behavior.
+ ---
+ --- See |grr|, |grn|, |gra|, |i_CTRL-S|.
+ do
+ vim.keymap.set('n', 'grn', function()
+ vim.lsp.buf.rename()
+ end, { desc = 'vim.lsp.buf.rename()' })
+
+ vim.keymap.set({ 'n', 'x' }, 'gra', function()
+ vim.lsp.buf.code_action()
+ end, { desc = 'vim.lsp.buf.code_action()' })
+
+ vim.keymap.set('n', 'grr', function()
+ vim.lsp.buf.references()
+ end, { desc = 'vim.lsp.buf.references()' })
+
+ vim.keymap.set('i', '<C-S>', function()
+ vim.lsp.buf.signature_help()
+ end, { desc = 'vim.lsp.buf.signature_help()' })
+ end
+
--- Map [d and ]d to move to the previous/next diagnostic. Map <C-W>d to open a floating window
--- for the diagnostic under the cursor.
---