From 4ee9e58056a9d17ce921d8cc6dfd6d3305a40f69 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 28 Mar 2024 07:39:36 +0800 Subject: feat(tui): query extended underline support using DECRQSS (#28052) --- runtime/lua/vim/_defaults.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 91baee1a1e..6223082622 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -384,13 +384,13 @@ if tty then -- attributes, so there should be no attributes in the list. local attrs = vim.split(decrqss, ';') if #attrs ~= 1 and (#attrs ~= 2 or attrs[1] ~= '0') then - return true + return false end -- The returned SGR sequence should begin with 48:2 local sgr = attrs[#attrs]:match('^48:2:([%d:]+)$') if not sgr then - return true + return false end -- The remaining elements of the SGR sequence should be the 3 colors @@ -422,7 +422,8 @@ if tty then if os.getenv('TMUX') then decrqss = string.format('\027Ptmux;%s\027\\', decrqss:gsub('\027', '\027\027')) end - io.stdout:write(string.format('\027[48;2;%d;%d;%dm%s', r, g, b, decrqss)) + -- Reset attributes first, as other code may have set attributes. + io.stdout:write(string.format('\027[0m\027[48;2;%d;%d;%dm%s', r, g, b, decrqss)) timer:start(1000, 0, function() -- Delete the autocommand if no response was received -- cgit From 9711370c26453f3a966b9306111939b144248b41 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 Apr 2024 18:08:54 +0800 Subject: feat(defaults): add :Inspect to right-click menu (#28181) Ref #21393 - Move default user commands to _defaults.lua as that now contains all kinds of defaults rather than just default mappings and menus. - Remove the :aunmenu as there are no menus when _defaults.lua is run. --- runtime/lua/vim/_defaults.lua | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 6223082622..0798ca8d16 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -1,3 +1,31 @@ +--- Default user commands +do + vim.api.nvim_create_user_command('Inspect', function(cmd) + if cmd.bang then + vim.print(vim.inspect_pos()) + else + vim.show_pos() + end + end, { desc = 'Inspect highlights and extmarks at the cursor', bang = true }) + + vim.api.nvim_create_user_command('InspectTree', function(cmd) + if cmd.mods ~= '' or cmd.count ~= 0 then + local count = cmd.count ~= 0 and cmd.count or '' + local new = cmd.mods ~= '' and 'new' or 'vnew' + + vim.treesitter.inspect_tree({ + command = ('%s %s%s'):format(cmd.mods, count, new), + }) + else + vim.treesitter.inspect_tree() + end + end, { desc = 'Inspect treesitter language tree for buffer', count = true }) + + vim.api.nvim_create_user_command('EditQuery', function(cmd) + vim.treesitter.query.edit(cmd.fargs[1]) + end, { desc = 'Edit treesitter query', nargs = '?' }) +end + --- Default mappings do --- Default maps for * and # in visual mode. @@ -93,7 +121,6 @@ do --- Right click popup menu -- TODO VimScript, no l10n vim.cmd([[ - aunmenu * vnoremenu PopUp.Cut "+x vnoremenu PopUp.Copy "+y anoremenu PopUp.Paste "+gP @@ -102,6 +129,7 @@ do nnoremenu PopUp.Select\ All ggVG vnoremenu PopUp.Select\ All gg0oG$ inoremenu PopUp.Select\ All VG + anoremenu PopUp.Inspect Inspect anoremenu PopUp.-1- anoremenu PopUp.How-to\ disable\ mouse help disable-mouse ]]) -- cgit From 73de98256cf3932dca156fbfd0c82c1cc10d487e Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Thu, 4 Apr 2024 18:10:12 +0300 Subject: feat(comment): add built-in commenting Design - Enable commenting support only through `gc` mappings for simplicity. No ability to configure, no Lua module, no user commands. Yet. - Overall implementation is a simplified version of 'mini.comment' module of 'echasnovski/mini.nvim' adapted to be a better suit for core. It basically means reducing code paths which use only specific fixed set of plugin config. All used options are default except `pad_comment_parts = false`. This means that 'commentstring' option is used as is without forcing single space inner padding. As 'tpope/vim-commentary' was considered for inclusion earlier, here is a quick summary of how this commit differs from it: - **User-facing features**. Both implement similar user-facing mappings. This commit does not include `gcu` which is essentially a `gcgc`. There are no commands, events, or configuration in this commit. - **Size**. Both have reasonably comparable number of lines of code, while this commit has more comments in tricky areas. - **Maintainability**. This commit has (purely subjectively) better readability, tests, and Lua types. - **Configurability**. This commit has no user configuration, while 'vim-commentary' has some (partially as a counter-measure to possibly modifying 'commentstring' option). - **Extra features**: - This commit supports tree-sitter by computing `'commentstring'` option under cursor, which can matter in presence of tree-sitter injected languages. - This commit comments blank lines while 'tpope/vim-commentary' does not. At the same time, blank lines are not taken into account when deciding the toggle action. - This commit has much better speed on larger chunks of lines (like above 1000). This is thanks to using `nvim_buf_set_lines()` to set all new lines at once, and not with `vim.fn.setline()`. --- runtime/lua/vim/_defaults.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 0798ca8d16..90d05f67a5 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -114,6 +114,24 @@ do do_open(table.concat(vim.iter(lines):map(vim.trim):totable())) end, { desc = gx_desc }) end + + --- Default maps for built-in commenting + do + local operator_rhs = function() + return require('vim._comment').operator() + end + vim.keymap.set({ 'n', 'x' }, 'gc', operator_rhs, { expr = true, desc = 'Toggle comment' }) + + local line_rhs = function() + return require('vim._comment').operator() .. '_' + end + vim.keymap.set('n', 'gcc', line_rhs, { expr = true, desc = 'Toggle comment line' }) + + local textobject_rhs = function() + require('vim._comment').textobject() + end + vim.keymap.set({ 'o' }, 'gc', textobject_rhs, { desc = 'Comment textobject' }) + end end --- Default menus -- cgit From 8cca7871555e15f53de3dc4325c8d0203a78622a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 12 Apr 2024 09:16:13 +0800 Subject: test: macros in Visual mode without default mappings (#28288) --- runtime/lua/vim/_defaults.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 90d05f67a5..2f02c2b389 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -93,6 +93,7 @@ do "':normal! @'.getcharstr().''", { silent = true, expr = true, desc = ':help v_@-default' } ) + --- Map |gx| to call |vim.ui.open| on the identifier under the cursor do local function do_open(uri) -- cgit From 328a2373514a880ea80bed53d63de76e2dea2a9c Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Sat, 13 Apr 2024 20:41:59 +0900 Subject: fix(defaults): auto-close terminal for &shell with args (#28276) Problem: The `:terminal` auto-close logic does not support `&shell` that has arguments, e.g., `/bin/bash -O globstar`. Solution: Join `argv` and match `&shell`. This is not perfect since `&shell` may contain irregular spaces and quotes, but it seems to be good enough. --- runtime/lua/vim/_defaults.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 2f02c2b389..2afcc185e5 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -175,7 +175,7 @@ do end local info = vim.api.nvim_get_chan_info(vim.bo[args.buf].channel) local argv = info.argv or {} - if #argv == 1 and argv[1] == vim.o.shell then + if table.concat(argv, ' ') == vim.o.shell then vim.api.nvim_buf_delete(args.buf, { force = true }) end end, -- cgit From aa1d0ac095dcc08b6069d716222739e83cbe051f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 15 Apr 2024 03:43:33 +0800 Subject: fix(defaults): only repeat macro for each selected line if linewise (#28289) As mentioned in #28287, repeating a macro for each selected line doesn't really make sense in non-linewise Visual mode. Fix #28287 --- runtime/lua/vim/_defaults.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 2afcc185e5..533ebbc7c3 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -78,19 +78,20 @@ do --- See |&-default| vim.keymap.set('n', '&', ':&&', { desc = ':help &-default' }) - --- Use Q in visual mode to execute a macro on each line of the selection. #21422 + --- Use Q in Visual mode to execute a macro on each line of the selection. #21422 + --- This only make sense in linewise Visual mode. #28287 --- --- Applies to @x and includes @@ too. vim.keymap.set( 'x', 'Q', - ':normal! @=reg_recorded()', - { silent = true, desc = ':help v_Q-default' } + "mode() == 'V' ? ':normal! @=reg_recorded()' : 'Q'", + { silent = true, expr = true, desc = ':help v_Q-default' } ) vim.keymap.set( 'x', '@', - "':normal! @'.getcharstr().''", + "mode() == 'V' ? ':normal! @'.getcharstr().'' : '@'", { silent = true, expr = true, desc = ':help v_@-default' } ) -- cgit From 57adf8c6e01d9395eb52fe03571c535571efdc4b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 15 Apr 2024 04:33:09 -0700 Subject: fix(vim.ui): open() may wait indefinitely #28325 Problem: vim.ui.open "locks up" Nvim if the spawned process does not terminate. #27986 Solution: - Change `vim.ui.open()`: - Do not call `wait()`. - Return a `SystemObj`. The caller can decide if it wants to `wait()`. - Change `gx` to `wait()` only a short time. - Allows `gx` to show a message if the command fails, without the risk of waiting forever. --- runtime/lua/vim/_defaults.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 533ebbc7c3..5ada64a358 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -95,10 +95,19 @@ do { silent = true, expr = true, desc = ':help v_@-default' } ) - --- Map |gx| to call |vim.ui.open| on the identifier under the cursor + --- Map |gx| to call |vim.ui.open| on the at cursor. do local function do_open(uri) - local _, err = vim.ui.open(uri) + local cmd, err = vim.ui.open(uri) + local rv = cmd and cmd:wait(1000) or nil + if cmd and rv and rv.code ~= 0 then + err = ('vim.ui.open: command %s (%d): %s'):format( + (rv.code == 124 and 'timeout' or 'failed'), + rv.code, + vim.inspect(cmd.cmd) + ) + end + if err then vim.notify(err, vim.log.levels.ERROR) end -- cgit From 20b38677c22b0ff19ea54396c7718b5a8f410ed4 Mon Sep 17 00:00:00 2001 From: Luna Saphie Mittelbach Date: Sun, 14 Apr 2024 12:54:10 +0200 Subject: feat(defaults): use ripgrep (rg) for 'grepprg' if available --- runtime/lua/vim/_defaults.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 5ada64a358..68ad95b725 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -496,3 +496,11 @@ if tty then end end end + +--- Default 'grepprg' to ripgrep if available. +if vim.fn.executable('rg') == 1 then + -- Match :grep default, otherwise rg searches cwd by default + -- Use -uuu to make ripgrep not do its default filtering + vim.o.grepprg = 'rg --vimgrep -uuu $* ' .. (vim.fn.has('unix') == 1 and '/dev/null' or 'nul') + vim.o.grepformat = '%f:%l:%c:%m' +end -- cgit From e0d92b9cc20b58179599f53dfa74ca821935a539 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 25 Apr 2024 04:15:58 -0700 Subject: fix(vim.ui)!: change open() to return pcall-like values #28502 Problem: `vim.ui.open` unnecessarily invents a different success/failure convention. Its return type was changed in 57adf8c6e01d, so we might as well change it to have a more conventional form. Solution: Change the signature to use the `pcall` convention of `status, result`. --- runtime/lua/vim/_defaults.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 68ad95b725..419a29a5c6 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -98,18 +98,19 @@ do --- Map |gx| to call |vim.ui.open| on the at cursor. do local function do_open(uri) - local cmd, err = vim.ui.open(uri) - local rv = cmd and cmd:wait(1000) or nil - if cmd and rv and rv.code ~= 0 then - err = ('vim.ui.open: command %s (%d): %s'):format( + local ok, cmd_or_err = vim.ui.open(uri) + local rv = ok and (cmd_or_err --[[@as vim.SystemObj]]):wait(1000) or nil + if rv and rv.code ~= 0 then + ok = false + cmd_or_err = ('vim.ui.open: command %s (%d): %s'):format( (rv.code == 124 and 'timeout' or 'failed'), rv.code, - vim.inspect(cmd.cmd) + vim.inspect(cmd_or_err.cmd) ) end - if err then - vim.notify(err, vim.log.levels.ERROR) + if not ok then + vim.notify(cmd_or_err --[[@as string]], vim.log.levels.ERROR) end end -- cgit From b8273c9a339626078d49e706d882878090b07d42 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 26 Apr 2024 14:07:47 +0100 Subject: fix: lua annotations --- runtime/lua/vim/_defaults.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 419a29a5c6..25bef2352c 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -196,6 +196,7 @@ do group = nvim_terminal_augroup, desc = 'Respond to OSC foreground/background color requests', callback = function(args) + --- @type integer local channel = vim.bo[args.buf].channel if channel == 0 then return @@ -270,6 +271,7 @@ if tty then -- Wait until Nvim is finished starting to set the option to ensure the -- OptionSet event fires. if vim.v.vim_did_enter == 1 then + --- @diagnostic disable-next-line:no-unknown vim.o[option] = value else vim.api.nvim_create_autocmd('VimEnter', { -- cgit From 688860741589b4583129e426f4df0523f9213275 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:12:49 -0500 Subject: feat(lsp): add more LSP defaults (#28500) - crn for rename - crr for code actions - gr for references - (in Insert mode) for signature help --- runtime/lua/vim/_defaults.lua | 450 ++++++++++++++++++++++-------------------- 1 file changed, 239 insertions(+), 211 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 25bef2352c..b1cd4f6ec6 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -144,6 +144,31 @@ do end vim.keymap.set({ 'o' }, 'gc', textobject_rhs, { desc = 'Comment textobject' }) end + + --- Default maps for LSP functions. + --- + --- These are mapped unconditionally to avoid confusion. If no server is attached, or if a server + --- does not support a capability, an error message is displayed rather than exhibiting different + --- behavior. + --- + --- See |gr-default|, |crn|, |crr|, |i_CTRL-S|. + do + vim.keymap.set('n', 'crn', function() + vim.lsp.buf.rename() + end, { desc = 'vim.lsp.buf.rename()' }) + + vim.keymap.set({ 'n', 'v' }, 'crr', function() + vim.lsp.buf.code_action() + end, { desc = 'vim.lsp.buf.code_action()' }) + + vim.keymap.set('n', 'gr', function() + vim.lsp.buf.references() + end, { desc = 'vim.lsp.buf.references()' }) + + vim.keymap.set('i', '', function() + vim.lsp.buf.signature_help() + end, { desc = 'vim.lsp.buf.signature_help()' }) + end end --- Default menus @@ -243,230 +268,140 @@ do vim.notify(('W325: Ignoring swapfile from Nvim process %d'):format(info.pid)) end, }) -end - --- Only do the following when the TUI is attached -local tty = nil -for _, ui in ipairs(vim.api.nvim_list_uis()) do - if ui.chan == 1 and ui.stdout_tty then - tty = ui - break - end -end - -if tty then - local group = vim.api.nvim_create_augroup('nvim_tty', {}) - --- Set an option after startup (so that OptionSet is fired), but only if not - --- already set by the user. - --- - --- @param option string Option name - --- @param value any Option value - local function setoption(option, value) - if vim.api.nvim_get_option_info2(option, {}).was_set then - -- Don't do anything if option is already set - return - end - - -- Wait until Nvim is finished starting to set the option to ensure the - -- OptionSet event fires. - if vim.v.vim_did_enter == 1 then - --- @diagnostic disable-next-line:no-unknown - vim.o[option] = value - else - vim.api.nvim_create_autocmd('VimEnter', { - group = group, - once = true, - nested = true, - callback = function() - setoption(option, value) - end, - }) + -- Only do the following when the TUI is attached + local tty = nil + for _, ui in ipairs(vim.api.nvim_list_uis()) do + if ui.chan == 1 and ui.stdout_tty then + tty = ui + break end end - --- Guess value of 'background' based on terminal color. - --- - --- We write Operating System Command (OSC) 11 to the terminal to request the - --- terminal's background color. We then wait for a response. If the response - --- matches `rgba:RRRR/GGGG/BBBB/AAAA` where R, G, B, and A are hex digits, then - --- compute the luminance[1] of the RGB color and classify it as light/dark - --- accordingly. Note that the color components may have anywhere from one to - --- four hex digits, and require scaling accordingly as values out of 4, 8, 12, - --- or 16 bits. Also note the A(lpha) component is optional, and is parsed but - --- ignored in the calculations. - --- - --- [1] https://en.wikipedia.org/wiki/Luma_%28video%29 - do - --- Parse a string of hex characters as a color. - --- - --- The string can contain 1 to 4 hex characters. The returned value is - --- between 0.0 and 1.0 (inclusive) representing the intensity of the color. - --- - --- For instance, if only a single hex char "a" is used, then this function - --- returns 0.625 (10 / 16), while a value of "aa" would return 0.664 (170 / - --- 256). + if tty then + local group = vim.api.nvim_create_augroup('nvim_tty', {}) + + --- Set an option after startup (so that OptionSet is fired), but only if not + --- already set by the user. --- - --- @param c string Color as a string of hex chars - --- @return number? Intensity of the color - local function parsecolor(c) - if #c == 0 or #c > 4 then - return nil + --- @param option string Option name + --- @param value any Option value + local function setoption(option, value) + if vim.api.nvim_get_option_info2(option, {}).was_set then + -- Don't do anything if option is already set + return end - local val = tonumber(c, 16) - if not val then - return nil + -- Wait until Nvim is finished starting to set the option to ensure the + -- OptionSet event fires. + if vim.v.vim_did_enter == 1 then + --- @diagnostic disable-next-line:no-unknown + vim.o[option] = value + else + vim.api.nvim_create_autocmd('VimEnter', { + group = group, + once = true, + nested = true, + callback = function() + setoption(option, value) + end, + }) end - - local max = tonumber(string.rep('f', #c), 16) - return val / max end - --- Parse an OSC 11 response - --- - --- Either of the two formats below are accepted: + --- Guess value of 'background' based on terminal color. --- - --- OSC 11 ; rgb:// + --- We write Operating System Command (OSC) 11 to the terminal to request the + --- terminal's background color. We then wait for a response. If the response + --- matches `rgba:RRRR/GGGG/BBBB/AAAA` where R, G, B, and A are hex digits, then + --- compute the luminance[1] of the RGB color and classify it as light/dark + --- accordingly. Note that the color components may have anywhere from one to + --- four hex digits, and require scaling accordingly as values out of 4, 8, 12, + --- or 16 bits. Also note the A(lpha) component is optional, and is parsed but + --- ignored in the calculations. --- - --- or - --- - --- OSC 11 ; rgba:/// - --- - --- where - --- - --- , , , := h | hh | hhh | hhhh - --- - --- The alpha component is ignored, if present. - --- - --- @param resp string OSC 11 response - --- @return string? Red component - --- @return string? Green component - --- @return string? Blue component - local function parseosc11(resp) - local r, g, b - r, g, b = resp:match('^\027%]11;rgb:(%x+)/(%x+)/(%x+)$') - if not r and not g and not b then - local a - r, g, b, a = resp:match('^\027%]11;rgba:(%x+)/(%x+)/(%x+)/(%x+)$') - if not a or #a > 4 then - return nil, nil, nil + --- [1] https://en.wikipedia.org/wiki/Luma_%28video%29 + do + --- Parse a string of hex characters as a color. + --- + --- The string can contain 1 to 4 hex characters. The returned value is + --- between 0.0 and 1.0 (inclusive) representing the intensity of the color. + --- + --- For instance, if only a single hex char "a" is used, then this function + --- returns 0.625 (10 / 16), while a value of "aa" would return 0.664 (170 / + --- 256). + --- + --- @param c string Color as a string of hex chars + --- @return number? Intensity of the color + local function parsecolor(c) + if #c == 0 or #c > 4 then + return nil end - end - - if r and g and b and #r <= 4 and #g <= 4 and #b <= 4 then - return r, g, b - end - return nil, nil, nil - end - - local timer = assert(vim.uv.new_timer()) - - local id = vim.api.nvim_create_autocmd('TermResponse', { - group = group, - nested = true, - callback = function(args) - local resp = args.data ---@type string - local r, g, b = parseosc11(resp) - if r and g and b then - local rr = parsecolor(r) - local gg = parsecolor(g) - local bb = parsecolor(b) - - if rr and gg and bb then - local luminance = (0.299 * rr) + (0.587 * gg) + (0.114 * bb) - local bg = luminance < 0.5 and 'dark' or 'light' - setoption('background', bg) - end - - return true + local val = tonumber(c, 16) + if not val then + return nil end - end, - }) - - io.stdout:write('\027]11;?\007') - - timer:start(1000, 0, function() - -- Delete the autocommand if no response was received - vim.schedule(function() - -- Suppress error if autocommand has already been deleted - pcall(vim.api.nvim_del_autocmd, id) - end) - if not timer:is_closing() then - timer:close() + local max = tonumber(string.rep('f', #c), 16) + return val / max end - end) - end - --- If the TUI (term_has_truecolor) was able to determine that the host - --- terminal supports truecolor, enable 'termguicolors'. Otherwise, query the - --- terminal (using both XTGETTCAP and SGR + DECRQSS). If the terminal's - --- response indicates that it does support truecolor enable 'termguicolors', - --- but only if the user has not already disabled it. - do - if tty.rgb then - -- The TUI was able to determine truecolor support - setoption('termguicolors', true) - else - local caps = {} ---@type table - require('vim.termcap').query({ 'Tc', 'RGB', 'setrgbf', 'setrgbb' }, function(cap, found) - if not found then - return + --- Parse an OSC 11 response + --- + --- Either of the two formats below are accepted: + --- + --- OSC 11 ; rgb:// + --- + --- or + --- + --- OSC 11 ; rgba:/// + --- + --- where + --- + --- , , , := h | hh | hhh | hhhh + --- + --- The alpha component is ignored, if present. + --- + --- @param resp string OSC 11 response + --- @return string? Red component + --- @return string? Green component + --- @return string? Blue component + local function parseosc11(resp) + local r, g, b + r, g, b = resp:match('^\027%]11;rgb:(%x+)/(%x+)/(%x+)$') + if not r and not g and not b then + local a + r, g, b, a = resp:match('^\027%]11;rgba:(%x+)/(%x+)/(%x+)/(%x+)$') + if not a or #a > 4 then + return nil, nil, nil + end end - caps[cap] = true - if caps.Tc or caps.RGB or (caps.setrgbf and caps.setrgbb) then - setoption('termguicolors', true) + if r and g and b and #r <= 4 and #g <= 4 and #b <= 4 then + return r, g, b end - end) - local timer = assert(vim.uv.new_timer()) + return nil, nil, nil + end - -- Arbitrary colors to set in the SGR sequence - local r = 1 - local g = 2 - local b = 3 + local timer = assert(vim.uv.new_timer()) local id = vim.api.nvim_create_autocmd('TermResponse', { group = group, nested = true, callback = function(args) local resp = args.data ---@type string - local decrqss = resp:match('^\027P1%$r([%d;:]+)m$') - - if decrqss then - -- The DECRQSS SGR response first contains attributes separated by - -- semicolons, followed by the SGR itself with parameters separated - -- by colons. Some terminals include "0" in the attribute list - -- unconditionally; others do not. Our SGR sequence did not set any - -- attributes, so there should be no attributes in the list. - local attrs = vim.split(decrqss, ';') - if #attrs ~= 1 and (#attrs ~= 2 or attrs[1] ~= '0') then - return false - end - - -- The returned SGR sequence should begin with 48:2 - local sgr = attrs[#attrs]:match('^48:2:([%d:]+)$') - if not sgr then - return false - end - - -- The remaining elements of the SGR sequence should be the 3 colors - -- we set. Some terminals also include an additional parameter - -- (which can even be empty!), so handle those cases as well - local params = vim.split(sgr, ':') - if #params ~= 3 and (#params ~= 4 or (params[1] ~= '' and params[1] ~= '1')) then - return true - end - - if - tonumber(params[#params - 2]) == r - and tonumber(params[#params - 1]) == g - and tonumber(params[#params]) == b - then - setoption('termguicolors', true) + local r, g, b = parseosc11(resp) + if r and g and b then + local rr = parsecolor(r) + local gg = parsecolor(g) + local bb = parsecolor(b) + + if rr and gg and bb then + local luminance = (0.299 * rr) + (0.587 * gg) + (0.114 * bb) + local bg = luminance < 0.5 and 'dark' or 'light' + setoption('background', bg) end return true @@ -474,16 +409,7 @@ if tty then end, }) - -- Write SGR followed by DECRQSS. This sets the background color then - -- immediately asks the terminal what the background color is. If the - -- terminal responds to the DECRQSS with the same SGR sequence that we - -- sent then the terminal supports truecolor. - local decrqss = '\027P$qm\027\\' - if os.getenv('TMUX') then - decrqss = string.format('\027Ptmux;%s\027\\', decrqss:gsub('\027', '\027\027')) - end - -- Reset attributes first, as other code may have set attributes. - io.stdout:write(string.format('\027[0m\027[48;2;%d;%d;%dm%s', r, g, b, decrqss)) + io.stdout:write('\027]11;?\007') timer:start(1000, 0, function() -- Delete the autocommand if no response was received @@ -497,13 +423,115 @@ if tty then end end) end + + --- If the TUI (term_has_truecolor) was able to determine that the host + --- terminal supports truecolor, enable 'termguicolors'. Otherwise, query the + --- terminal (using both XTGETTCAP and SGR + DECRQSS). If the terminal's + --- response indicates that it does support truecolor enable 'termguicolors', + --- but only if the user has not already disabled it. + do + if tty.rgb then + -- The TUI was able to determine truecolor support + setoption('termguicolors', true) + else + local caps = {} ---@type table + require('vim.termcap').query({ 'Tc', 'RGB', 'setrgbf', 'setrgbb' }, function(cap, found) + if not found then + return + end + + caps[cap] = true + if caps.Tc or caps.RGB or (caps.setrgbf and caps.setrgbb) then + setoption('termguicolors', true) + end + end) + + local timer = assert(vim.uv.new_timer()) + + -- Arbitrary colors to set in the SGR sequence + local r = 1 + local g = 2 + local b = 3 + + local id = vim.api.nvim_create_autocmd('TermResponse', { + group = group, + nested = true, + callback = function(args) + local resp = args.data ---@type string + local decrqss = resp:match('^\027P1%$r([%d;:]+)m$') + + if decrqss then + -- The DECRQSS SGR response first contains attributes separated by + -- semicolons, followed by the SGR itself with parameters separated + -- by colons. Some terminals include "0" in the attribute list + -- unconditionally; others do not. Our SGR sequence did not set any + -- attributes, so there should be no attributes in the list. + local attrs = vim.split(decrqss, ';') + if #attrs ~= 1 and (#attrs ~= 2 or attrs[1] ~= '0') then + return false + end + + -- The returned SGR sequence should begin with 48:2 + local sgr = attrs[#attrs]:match('^48:2:([%d:]+)$') + if not sgr then + return false + end + + -- The remaining elements of the SGR sequence should be the 3 colors + -- we set. Some terminals also include an additional parameter + -- (which can even be empty!), so handle those cases as well + local params = vim.split(sgr, ':') + if #params ~= 3 and (#params ~= 4 or (params[1] ~= '' and params[1] ~= '1')) then + return true + end + + if + tonumber(params[#params - 2]) == r + and tonumber(params[#params - 1]) == g + and tonumber(params[#params]) == b + then + setoption('termguicolors', true) + end + + return true + end + end, + }) + + -- Write SGR followed by DECRQSS. This sets the background color then + -- immediately asks the terminal what the background color is. If the + -- terminal responds to the DECRQSS with the same SGR sequence that we + -- sent then the terminal supports truecolor. + local decrqss = '\027P$qm\027\\' + if os.getenv('TMUX') then + decrqss = string.format('\027Ptmux;%s\027\\', decrqss:gsub('\027', '\027\027')) + end + -- Reset attributes first, as other code may have set attributes. + io.stdout:write(string.format('\027[0m\027[48;2;%d;%d;%dm%s', r, g, b, decrqss)) + + timer:start(1000, 0, function() + -- Delete the autocommand if no response was received + vim.schedule(function() + -- Suppress error if autocommand has already been deleted + pcall(vim.api.nvim_del_autocmd, id) + end) + + if not timer:is_closing() then + timer:close() + end + end) + end + end end end ---- Default 'grepprg' to ripgrep if available. -if vim.fn.executable('rg') == 1 then - -- Match :grep default, otherwise rg searches cwd by default - -- Use -uuu to make ripgrep not do its default filtering - vim.o.grepprg = 'rg --vimgrep -uuu $* ' .. (vim.fn.has('unix') == 1 and '/dev/null' or 'nul') - vim.o.grepformat = '%f:%l:%c:%m' +--- Default options +do + --- Default 'grepprg' to ripgrep if available. + if vim.fn.executable('rg') == 1 then + -- Match :grep default, otherwise rg searches cwd by default + -- Use -uuu to make ripgrep not do its default filtering + vim.o.grepprg = 'rg --vimgrep -uuu $* ' .. (vim.fn.has('unix') == 1 and '/dev/null' or 'nul') + vim.o.grepformat = '%f:%l:%c:%m' + end end -- cgit From 73034611c25d16df5e87c8afb2d339a03a91bd0d Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:16:12 -0500 Subject: feat(diagnostic): add default mappings for diagnostics (#16230) --- runtime/lua/vim/_defaults.lua | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index b1cd4f6ec6..98dfbf3225 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -127,7 +127,9 @@ do end, { desc = gx_desc }) end - --- Default maps for built-in commenting + --- Default maps for built-in commenting. + --- + --- See |gc-default| and |gcc-default|. do local operator_rhs = function() return require('vim._comment').operator() @@ -169,6 +171,35 @@ do 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 d to open a floating window + --- for the diagnostic under the cursor. + --- + --- See |[d-default|, |]d-default|, and |CTRL-W_d-default|. + do + vim.keymap.set('n', ']d', function() + vim.diagnostic.goto_next({ float = false }) + end, { + desc = 'Jump to the next diagnostic with the highest severity', + }) + + vim.keymap.set('n', '[d', function() + vim.diagnostic.goto_prev({ float = false }) + end, { + desc = 'Jump to the previous diagnostic with the highest severity', + }) + + vim.keymap.set('n', 'd', function() + vim.diagnostic.open_float({ border = 'rounded' }) + end, { + desc = 'Open a floating window showing diagnostics under the cursor', + }) + + vim.keymap.set('n', '', 'd', { + remap = true, + desc = 'Open a floating window showing diagnostics under the cursor', + }) + end end --- Default menus -- cgit From 83635e4e3db9a99c128e84e79deb590da354215d Mon Sep 17 00:00:00 2001 From: glepnir Date: Sun, 28 Apr 2024 23:15:10 +0800 Subject: fix(diagnostic): get border from config (#28531) Co-authored-by: Justin M. Keyes Co-authored-by: Gregory Anders --- runtime/lua/vim/_defaults.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 98dfbf3225..e9575c0e1e 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -190,7 +190,7 @@ do }) vim.keymap.set('n', 'd', function() - vim.diagnostic.open_float({ border = 'rounded' }) + vim.diagnostic.open_float() end, { desc = 'Open a floating window showing diagnostics under the cursor', }) -- cgit From 513fc461957f370f9e89b3cfd56cb03a816d6941 Mon Sep 17 00:00:00 2001 From: Luna Saphie Mittelbach Date: Sun, 28 Apr 2024 18:00:48 +0200 Subject: feat(defaults): improve :grep defaults #28545 Based on feedback from #28324, pass -H and -I to regular grep (available on all platforms officially supported by Neovim), and only pass -uu to ripgrep. This makes :grep ignore binary files by default in both cases. --- runtime/lua/vim/_defaults.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index e9575c0e1e..7166f7a23c 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -560,9 +560,8 @@ end do --- Default 'grepprg' to ripgrep if available. if vim.fn.executable('rg') == 1 then - -- Match :grep default, otherwise rg searches cwd by default - -- Use -uuu to make ripgrep not do its default filtering - vim.o.grepprg = 'rg --vimgrep -uuu $* ' .. (vim.fn.has('unix') == 1 and '/dev/null' or 'nul') + -- Use -uu to make ripgrep not check ignore files/skip dot-files + vim.o.grepprg = 'rg --vimgrep -uu ' vim.o.grepformat = '%f:%l:%c:%m' end end -- cgit From 61063653b06bfccac083c0105ecd0c433b3bb8f7 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 28 Apr 2024 09:02:18 -0700 Subject: feat(defaults): visual CTRL-R for LSP mappings #28537 Problem: The new LSP "refactor menu" keybinding "crr" is also defined in visual mode, which overlaps with the builtin "c". Solution: Use CTRL-R instead of "crr" for visual mode. fix #28528 --- runtime/lua/vim/_defaults.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 7166f7a23c..1094f22793 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -159,9 +159,14 @@ do vim.lsp.buf.rename() end, { desc = 'vim.lsp.buf.rename()' }) - vim.keymap.set({ 'n', 'v' }, 'crr', function() - vim.lsp.buf.code_action() - end, { desc = 'vim.lsp.buf.code_action()' }) + local function map_codeaction(mode, lhs) + vim.keymap.set(mode, lhs, function() + vim.lsp.buf.code_action() + end, { desc = 'vim.lsp.buf.code_action()' }) + end + map_codeaction('n', 'crr') + map_codeaction('x', 'r') + map_codeaction('x', '') vim.keymap.set('n', 'gr', function() vim.lsp.buf.references() -- cgit From 71cf75f96a67aeb79ac3af6aa829bac81bd2d33d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 30 Apr 2024 04:30:21 -0700 Subject: docs: misc #24163 - Also delete old perl scripts which are not used since 8+ years ago. fix #23251 fix #27367 ref https://github.com/neovim/neovim/issues/2252#issuecomment-1902662577 Helped-by: Daniel Kongsgaard Co-authored-by: Kevin Pham --- runtime/lua/vim/_defaults.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 1094f22793..29f8e71264 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -255,7 +255,7 @@ do vim.api.nvim_create_autocmd('TermRequest', { group = nvim_terminal_augroup, - desc = 'Respond to OSC foreground/background color requests', + desc = 'Handles OSC foreground/background color requests', callback = function(args) --- @type integer local channel = vim.bo[args.buf].channel -- cgit From 40ce8577977fcdce8ad76863c70eb522e4cefd4d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 3 May 2024 03:20:03 -0700 Subject: fix(vim.ui)!: change open() to return `result|nil, errmsg|nil` #28612 reverts e0d92b9cc20b58179599f53dfa74ca821935a539 #28502 Problem: `vim.ui.open()` has a `pcall()` like signature, under the assumption that this is the Lua idiom for returning result-or-error. However, the `result|nil, errmsg|nil` pattern: - has precedent in: - `io.open` - `vim.uv` (`:help luv-error-handling`) - has these advantages: - Can be used with `assert()`: ``` local result, err = assert(foobar()) ``` - Allows LuaLS to infer the type of `result`: ``` local result, err = foobar() if err then ... elseif result then ... end ``` Solution: - Revert to the `result|nil, errmsg|nil` pattern. - Document the pattern in our guidelines. --- runtime/lua/vim/_defaults.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 29f8e71264..6d31a3ea93 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -98,19 +98,18 @@ do --- Map |gx| to call |vim.ui.open| on the at cursor. do local function do_open(uri) - local ok, cmd_or_err = vim.ui.open(uri) - local rv = ok and (cmd_or_err --[[@as vim.SystemObj]]):wait(1000) or nil - if rv and rv.code ~= 0 then - ok = false - cmd_or_err = ('vim.ui.open: command %s (%d): %s'):format( + local cmd, err = vim.ui.open(uri) + local rv = cmd and cmd:wait(1000) or nil + if cmd and rv and rv.code ~= 0 then + err = ('vim.ui.open: command %s (%d): %s'):format( (rv.code == 124 and 'timeout' or 'failed'), rv.code, - vim.inspect(cmd_or_err.cmd) + vim.inspect(cmd.cmd) ) end - if not ok then - vim.notify(cmd_or_err --[[@as string]], vim.log.levels.ERROR) + if err then + vim.notify(err, vim.log.levels.ERROR) end end -- cgit From 5e98439f6d8c3a4d2da9a295e522e96c9cdaf891 Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Sun, 5 May 2024 17:45:47 +0300 Subject: fix(defaults): diagnostic mappings descriptions #28646 --- runtime/lua/vim/_defaults.lua | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 6d31a3ea93..bd1afd0beb 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -183,26 +183,22 @@ do do vim.keymap.set('n', ']d', function() vim.diagnostic.goto_next({ float = false }) - end, { - desc = 'Jump to the next diagnostic with the highest severity', - }) + end, { desc = 'Jump to the next diagnostic' }) vim.keymap.set('n', '[d', function() vim.diagnostic.goto_prev({ float = false }) - end, { - desc = 'Jump to the previous diagnostic with the highest severity', - }) + end, { desc = 'Jump to the previous diagnostic' }) vim.keymap.set('n', 'd', function() vim.diagnostic.open_float() - end, { - desc = 'Open a floating window showing diagnostics under the cursor', - }) - - vim.keymap.set('n', '', 'd', { - remap = true, - desc = 'Open a floating window showing diagnostics under the cursor', - }) + end, { desc = 'Show diagnostics under the cursor' }) + + vim.keymap.set( + 'n', + '', + 'd', + { remap = true, desc = 'Show diagnostics under the cursor' } + ) end end -- cgit From bb032d952bfc692062fceb764ff2742c5bdd3324 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Mon, 6 May 2024 08:13:50 -0500 Subject: revert: default LSP mappings (#28649) Revert the default LSP mappings before the 0.10 release as these might need some further consideration. In particular, it's not clear if "c" prefixed maps in Normal mode are acceptable as defaults since they interfere with text objects or operator ranges. We will re-introduce default mappings at the beginning of the 0.11 release cycle, this reversion is only for the imminent 0.10 release. --- runtime/lua/vim/_defaults.lua | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index bd1afd0beb..4684902410 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -146,36 +146,6 @@ do vim.keymap.set({ 'o' }, 'gc', textobject_rhs, { desc = 'Comment textobject' }) end - --- Default maps for LSP functions. - --- - --- These are mapped unconditionally to avoid confusion. If no server is attached, or if a server - --- does not support a capability, an error message is displayed rather than exhibiting different - --- behavior. - --- - --- See |gr-default|, |crn|, |crr|, |i_CTRL-S|. - do - vim.keymap.set('n', 'crn', function() - vim.lsp.buf.rename() - end, { desc = 'vim.lsp.buf.rename()' }) - - local function map_codeaction(mode, lhs) - vim.keymap.set(mode, lhs, function() - vim.lsp.buf.code_action() - end, { desc = 'vim.lsp.buf.code_action()' }) - end - map_codeaction('n', 'crr') - map_codeaction('x', 'r') - map_codeaction('x', '') - - vim.keymap.set('n', 'gr', function() - vim.lsp.buf.references() - end, { desc = 'vim.lsp.buf.references()' }) - - vim.keymap.set('i', '', 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 d to open a floating window --- for the diagnostic under the cursor. --- -- cgit From f864b68c5b0fe1482249167712cd16ff2b50ec45 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 3 May 2024 20:32:06 +0200 Subject: feat: allow gx to function for markdown links In other words, `gx` works regardless of where it was used in `[...](https://...)`. This only works on markdown buffers. Co-authored-by: ribru17 --- runtime/lua/vim/_defaults.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 4684902410..ede634636e 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -107,22 +107,25 @@ do vim.inspect(cmd.cmd) ) end - - if err then - vim.notify(err, vim.log.levels.ERROR) - end + return err end local gx_desc = 'Opens filepath or URI under cursor with the system handler (file explorer, web browser, …)' vim.keymap.set({ 'n' }, 'gx', function() - do_open(vim.fn.expand('')) + local err = do_open(require('vim.ui')._get_url()) + if err then + vim.notify(err, vim.log.levels.ERROR) + end end, { desc = gx_desc }) vim.keymap.set({ 'x' }, 'gx', function() local lines = vim.fn.getregion(vim.fn.getpos('.'), vim.fn.getpos('v'), { type = vim.fn.mode() }) -- Trim whitespace on each line and concatenate. - do_open(table.concat(vim.iter(lines):map(vim.trim):totable())) + local err = do_open(table.concat(vim.iter(lines):map(vim.trim):totable())) + if err then + vim.notify(err, vim.log.levels.ERROR) + end end, { desc = gx_desc }) end -- cgit From e71713ba2b5cb4e3b725d162b2dd43e35975eead Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Fri, 24 May 2024 10:44:02 -0500 Subject: fix: show swapfile warning as a warning (#28971) The new default SwapExists autocommand displays warning text (W325) but does not use the WarningMsg highlight group as other warnings do. Use the WARN log level when displaying this warning. --- runtime/lua/vim/_defaults.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index ede634636e..7015d376ae 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -269,7 +269,10 @@ do return end vim.v.swapchoice = 'e' -- Choose "(E)dit". - vim.notify(('W325: Ignoring swapfile from Nvim process %d'):format(info.pid)) + vim.notify( + ('W325: Ignoring swapfile from Nvim process %d'):format(info.pid), + vim.log.levels.WARN + ) end, }) -- cgit From 2c6b6358722b2df9160c3739b0cea07e8779513f Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Fri, 24 May 2024 11:33:49 -0500 Subject: feat(defaults): add LSP default mappings (again) (#28650) --- runtime/lua/vim/_defaults.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'runtime/lua/vim/_defaults.lua') 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', '', 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 d to open a floating window --- for the diagnostic under the cursor. --- -- cgit