From 1c6d9200521acb2329be55ab8bec3056deade66a Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Tue, 28 May 2024 13:24:16 -0500 Subject: feat(defaults): use vim.diagnostic.jump() for default mappings (#29066) This allows the mappings to work with a count and also enables new ]D and [D mappings to go to the last/first diagnostic in the buffer. --- runtime/lua/vim/_defaults.lua | 16 ++++++++++++---- 1 file changed, 12 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 5b964b84a0..26d8729029 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -180,12 +180,20 @@ do --- 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' }) + vim.diagnostic.jump({ count = vim.v.count1, float = false }) + end, { desc = 'Jump to the next diagnostic in the current buffer' }) vim.keymap.set('n', '[d', function() - vim.diagnostic.goto_prev({ float = false }) - end, { desc = 'Jump to the previous diagnostic' }) + vim.diagnostic.jump({ count = -vim.v.count1, float = false }) + end, { desc = 'Jump to the previous diagnostic in the current buffer' }) + + vim.keymap.set('n', ']D', function() + vim.diagnostic.jump({ count = math.huge, wrap = false, float = false }) + end, { desc = 'Jump to the last diagnostic in the current buffer' }) + + vim.keymap.set('n', '[D', function() + vim.diagnostic.jump({ count = -math.huge, wrap = false, float = false }) + end, { desc = 'Jump to the first diagnostic in the current buffer' }) vim.keymap.set('n', 'd', function() vim.diagnostic.open_float() -- cgit From efa45832ea02e777ce3f5556ef3cd959c164ec24 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Tue, 28 May 2024 14:54:50 -0500 Subject: feat: add "jump" options to vim.diagnostic.config() (#29067) Problem: There is no easy way to configure the behavior of the default diagnostic "jump" mappings. For example, some users way want to show the floating window, and some may not (likewise, some way want to only move between warnings/errors, or disable the "wrap" parameter). Solution: Add a "jump" table to vim.diagnostic.config() that sets default values for vim.diagnostic.jump(). Alternatives: Users can override the default mappings to use the exact options to vim.diagnostic.jump() that they want, but this has a couple issues: - While the default mappings are not complicated, they are also not trivial, so overriding them requires users to understand implementation details (specifically things like setting "count" properly). - If plugins want to change the default mappings, or configure the behavior in any way (e.g. floating window display), it becomes even harder for users to tweak specific behavior. vim.diagnostic.config() already works quite well as the "entry point" for tuning knobs with diagnostic UI elements, so this fits in nicely and composes well with existing mental models and idioms. --- runtime/lua/vim/_defaults.lua | 8 ++++---- 1 file changed, 4 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 26d8729029..79fe5a8513 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -180,19 +180,19 @@ do --- See |[d-default|, |]d-default|, and |CTRL-W_d-default|. do vim.keymap.set('n', ']d', function() - vim.diagnostic.jump({ count = vim.v.count1, float = false }) + vim.diagnostic.jump({ count = vim.v.count1 }) end, { desc = 'Jump to the next diagnostic in the current buffer' }) vim.keymap.set('n', '[d', function() - vim.diagnostic.jump({ count = -vim.v.count1, float = false }) + vim.diagnostic.jump({ count = -vim.v.count1 }) end, { desc = 'Jump to the previous diagnostic in the current buffer' }) vim.keymap.set('n', ']D', function() - vim.diagnostic.jump({ count = math.huge, wrap = false, float = false }) + vim.diagnostic.jump({ count = math.huge, wrap = false }) end, { desc = 'Jump to the last diagnostic in the current buffer' }) vim.keymap.set('n', '[D', function() - vim.diagnostic.jump({ count = -math.huge, wrap = false, float = false }) + vim.diagnostic.jump({ count = -math.huge, wrap = false }) end, { desc = 'Jump to the first diagnostic in the current buffer' }) vim.keymap.set('n', 'd', function() -- cgit From d7651b27d54a87c5783c0a579af11da9a16a39aa Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Wed, 5 Jun 2024 08:27:56 -0500 Subject: fix(tui): move $COLORTERM check to _defaults.lua (#29197) We currently check $COLORTERM in the TUI process to determine if the terminal supports 24 bit color (truecolor). If $COLORTERM is "truecolor" or "24bit" then we automatically assume that the terminal supports truecolor, but if $COLORTERM is set to any other value we still query the terminal. The `rgb` flag of the UI struct is a boolean which only indicates whether the UI supports truecolor, but does not have a 3rd state that we can use to represent "we don't know if the UI supports truecolor". We currently use `rgb=false` to represent this "we don't know" state, and we use XTGETTCAP and DECRQSS queries to determine at runtime if the terminal supports truecolor. However, if $COLORTERM is set to a value besides "truecolor" or "24bit" (e.g. "256" or "16) that is a clear indication that the terminal _does not_ support truecolor, so it is incorrect to treat `rgb=false` as "we don't know" in that case. Instead, in the TUI process we only check for the terminfo capabilities. This must be done in the TUI process because we do not have access to this information in the core Neovim process when `_defaults.lua` runs. If the TUI cannot determine truecolor support from terminfo alone, we set `rgb=false` to indicate "we don't know if the terminal supports truecolor yet, keep checking". When we get to `_defaults.lua`, we can then check $COLORTERM and only query the terminal if it is unset. This means that users can explicitly opt out of truecolor determination by setting `COLORTERM=256` (or similar) in their environment. --- runtime/lua/vim/_defaults.lua | 10 +++++++--- 1 file changed, 7 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 79fe5a8513..01dcd4bf74 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -470,10 +470,14 @@ do --- 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 + local colorterm = os.getenv('COLORTERM') + if tty.rgb or colorterm == 'truecolor' or colorterm == '24bit' then + -- The TUI was able to determine truecolor support or $COLORTERM explicitly indicates + -- truecolor support setoption('termguicolors', true) - else + elseif colorterm == nil or colorterm == '' then + -- Neither the TUI nor $COLORTERM indicate that truecolor is supported, so query the + -- terminal local caps = {} ---@type table require('vim.termcap').query({ 'Tc', 'RGB', 'setrgbf', 'setrgbb' }, function(cap, found) if not found then -- cgit From d38912b59f97a4da0a2d0a24af226e6dd27e9b2c Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 11 Jun 2024 11:10:34 -0500 Subject: refactor(terminal): move :terminal defaults to _defaults.lua --- runtime/lua/vim/_defaults.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 01dcd4bf74..f417bda3fb 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -282,6 +282,26 @@ do end, }) + vim.api.nvim_create_autocmd('TermOpen', { + group = nvim_terminal_augroup, + desc = 'Default settings for :terminal buffers', + callback = function() + vim.bo.modifiable = false + vim.bo.undolevels = -1 + vim.bo.scrollback = vim.o.scrollback < 0 and 10000 or math.max(1, vim.o.scrollback) + vim.bo.textwidth = 0 + vim.wo.wrap = false + vim.wo.list = false + + -- This is gross. Proper list options support when? + local winhl = vim.o.winhighlight + if winhl ~= '' then + winhl = winhl .. ',' + end + vim.wo.winhighlight = winhl .. 'StatusLine:StatusLineTerm,StatusLineNC:StatusLineTermNC' + end, + }) + vim.api.nvim_create_autocmd('CmdwinEnter', { pattern = '[:>]', desc = 'Limit syntax sync to maxlines=1 in the command window', -- cgit From 5def8714ad70e71e07773960269fff5c0c95e7ab Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Jun 2024 06:20:42 +0800 Subject: fix(terminal): set local values of window options (#29326) --- runtime/lua/vim/_defaults.lua | 6 +++--- 1 file changed, 3 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 f417bda3fb..8e4562c8ba 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -290,15 +290,15 @@ do vim.bo.undolevels = -1 vim.bo.scrollback = vim.o.scrollback < 0 and 10000 or math.max(1, vim.o.scrollback) vim.bo.textwidth = 0 - vim.wo.wrap = false - vim.wo.list = false + vim.wo[0][0].wrap = false + vim.wo[0][0].list = false -- This is gross. Proper list options support when? local winhl = vim.o.winhighlight if winhl ~= '' then winhl = winhl .. ',' end - vim.wo.winhighlight = winhl .. 'StatusLine:StatusLineTerm,StatusLineNC:StatusLineTermNC' + vim.wo[0][0].winhighlight = winhl .. 'StatusLine:StatusLineTerm,StatusLineNC:StatusLineTermNC' end, }) -- cgit From 61aabe0730b547b733faaf74ff181ec8c33f8b92 Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 14 Jun 2024 19:21:16 -0700 Subject: fix(defaults): default @/Q broken when 'ignorecase' is set (#29343) Problem: When 'ignorecase' is set, the default keymap Q and Q would exit visual mode. This issue was raised in #28287 and a fix was applied in #28289. However, `==` operator is subject to user `ignorecase` setting. Solution: Switching to `==#` operator would guarantee case sensitive comparison between visual mode and linewise visual mode. Co-authored-by: Kuanju Chen --- runtime/lua/vim/_defaults.lua | 4 ++-- 1 file changed, 2 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 8e4562c8ba..630f2219c7 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -85,13 +85,13 @@ do vim.keymap.set( 'x', 'Q', - "mode() == 'V' ? ':normal! @=reg_recorded()' : 'Q'", + "mode() ==# 'V' ? ':normal! @=reg_recorded()' : 'Q'", { silent = true, expr = true, desc = ':help v_Q-default' } ) vim.keymap.set( 'x', '@', - "mode() == 'V' ? ':normal! @'.getcharstr().'' : '@'", + "mode() ==# 'V' ? ':normal! @'.getcharstr().'' : '@'", { silent = true, expr = true, desc = ':help v_@-default' } ) -- cgit From 9762c5e3406cab8152d8dd161c0178965d841676 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Sat, 31 Aug 2024 19:56:20 -0500 Subject: feat(ui): gx: use url extmark attribute and tree-sitter directive (#30192) Use the "url" extmark attribute as well as the "url" tree-sitter metadata key to determine if the cursor is over something Nvim considers a URL. --- runtime/lua/vim/_defaults.lua | 8 +++++--- 1 file changed, 5 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 630f2219c7..38cfdbdd32 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -113,9 +113,11 @@ do local gx_desc = 'Opens filepath or URI under cursor with the system handler (file explorer, web browser, …)' vim.keymap.set({ 'n' }, 'gx', function() - local err = do_open(require('vim.ui')._get_url()) - if err then - vim.notify(err, vim.log.levels.ERROR) + for _, url in ipairs(require('vim.ui')._get_urls()) do + local err = do_open(url) + if err then + vim.notify(err, vim.log.levels.ERROR) + end end end, { desc = gx_desc }) vim.keymap.set({ 'x' }, 'gx', function() -- cgit From 76aa3e52be7a5a8b53b3775981c35313284230ac Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 5 Sep 2024 05:56:00 -0700 Subject: feat(defaults): popupmenu "Open in browser", "Go to definition" #30261 - Use the popup to expose more features such as LSP and gx. - Move the copy/paste items lower in the menu, they are lower priority. --- runtime/lua/vim/_defaults.lua | 56 ++++++++++++++++++++++++++++++++----------- 1 file changed, 42 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 38cfdbdd32..911cc13e74 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -213,20 +213,48 @@ end --- Default menus do --- Right click popup menu - -- TODO VimScript, no l10n - vim.cmd([[ - vnoremenu PopUp.Cut "+x - vnoremenu PopUp.Copy "+y - anoremenu PopUp.Paste "+gP - vnoremenu PopUp.Paste "+P - vnoremenu PopUp.Delete "_x - 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 - ]]) + local function def_menu(ctx) + vim.cmd([[ + anoremenu PopUp.Go\ to\ definition lua vim.lsp.buf.definition() + amenu PopUp.Open\ in\ web\ browser gx + anoremenu PopUp.Inspect Inspect + anoremenu PopUp.-1- + vnoremenu PopUp.Cut "+x + vnoremenu PopUp.Copy "+y + anoremenu PopUp.Paste "+gP + vnoremenu PopUp.Paste "+P + vnoremenu PopUp.Delete "_x + nnoremenu PopUp.Select\ All ggVG + vnoremenu PopUp.Select\ All gg0oG$ + inoremenu PopUp.Select\ All VG + anoremenu PopUp.-2- + anoremenu PopUp.How-to\ disable\ mouse help disable-mouse + + amenu disable PopUp.Go\ to\ definition + amenu disable PopUp.Open\ in\ web\ browser + ]]) + + if ctx == 'url' then + vim.cmd([[amenu enable PopUp.Open\ in\ web\ browser]]) + elseif ctx == 'lsp' then + vim.cmd([[anoremenu enable PopUp.Go\ to\ definition]]) + end + end + def_menu() + + local nvim_popupmenu_augroup = vim.api.nvim_create_augroup('nvim_popupmenu', {}) + vim.api.nvim_create_autocmd('MenuPopup', { + pattern = '*', + group = nvim_popupmenu_augroup, + desc = 'Mouse popup menu', + -- nested = true, + callback = function() + local urls = require('vim.ui')._get_urls() + local url = vim.startswith(urls[1], 'http') + local ctx = url and 'url' or (vim.lsp.get_clients({ bufnr = 0 })[1] and 'lsp' or nil) + def_menu(ctx) + end, + }) end --- Default autocommands. See |default-autocmds| -- cgit From f2173b1aa2bec63aa982794ffde806090ab5b680 Mon Sep 17 00:00:00 2001 From: Jaehwang Jung Date: Sat, 14 Sep 2024 18:18:38 +0900 Subject: fix(defaults): cannot remove "How-to disable mouse" menu item #30375 --- runtime/lua/vim/_defaults.lua | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 911cc13e74..723d425174 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -213,23 +213,25 @@ end --- Default menus do --- Right click popup menu - local function def_menu(ctx) + vim.cmd([[ + anoremenu PopUp.Go\ to\ definition lua vim.lsp.buf.definition() + amenu PopUp.Open\ in\ web\ browser gx + anoremenu PopUp.Inspect Inspect + anoremenu PopUp.-1- + vnoremenu PopUp.Cut "+x + vnoremenu PopUp.Copy "+y + anoremenu PopUp.Paste "+gP + vnoremenu PopUp.Paste "+P + vnoremenu PopUp.Delete "_x + nnoremenu PopUp.Select\ All ggVG + vnoremenu PopUp.Select\ All gg0oG$ + inoremenu PopUp.Select\ All VG + anoremenu PopUp.-2- + anoremenu PopUp.How-to\ disable\ mouse help disable-mouse + ]]) + + local function enable_ctx_menu(ctx) vim.cmd([[ - anoremenu PopUp.Go\ to\ definition lua vim.lsp.buf.definition() - amenu PopUp.Open\ in\ web\ browser gx - anoremenu PopUp.Inspect Inspect - anoremenu PopUp.-1- - vnoremenu PopUp.Cut "+x - vnoremenu PopUp.Copy "+y - anoremenu PopUp.Paste "+gP - vnoremenu PopUp.Paste "+P - vnoremenu PopUp.Delete "_x - nnoremenu PopUp.Select\ All ggVG - vnoremenu PopUp.Select\ All gg0oG$ - inoremenu PopUp.Select\ All VG - anoremenu PopUp.-2- - anoremenu PopUp.How-to\ disable\ mouse help disable-mouse - amenu disable PopUp.Go\ to\ definition amenu disable PopUp.Open\ in\ web\ browser ]]) @@ -240,7 +242,6 @@ do vim.cmd([[anoremenu enable PopUp.Go\ to\ definition]]) end end - def_menu() local nvim_popupmenu_augroup = vim.api.nvim_create_augroup('nvim_popupmenu', {}) vim.api.nvim_create_autocmd('MenuPopup', { @@ -252,7 +253,7 @@ do local urls = require('vim.ui')._get_urls() local url = vim.startswith(urls[1], 'http') local ctx = url and 'url' or (vim.lsp.get_clients({ bufnr = 0 })[1] and 'lsp' or nil) - def_menu(ctx) + enable_ctx_menu(ctx) end, }) end -- cgit From bb7604eddafb31cd38261a220243762ee013273a Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Tue, 1 Oct 2024 07:24:43 -0500 Subject: feat(defaults): add default unimpaired style mappings (#28525) --- runtime/lua/vim/_defaults.lua | 165 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) (limited to 'runtime/lua/vim/_defaults.lua') diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 723d425174..09670f4c32 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -208,6 +208,171 @@ do { remap = true, desc = 'Show diagnostics under the cursor' } ) end + + --- vim-unimpaired style mappings. See: https://github.com/tpope/vim-unimpaired + do + -- Quickfix mappings + vim.keymap.set('n', '[q', function() + vim.cmd.cprevious({ count = vim.v.count1 }) + end, { + desc = ':cprevious', + }) + + vim.keymap.set('n', ']q', function() + vim.cmd.cnext({ count = vim.v.count1 }) + end, { + desc = ':cnext', + }) + + vim.keymap.set('n', '[Q', function() + vim.cmd.crewind({ args = vim.v.count ~= 0 and { vim.v.count } or nil }) + end, { + desc = ':crewind', + }) + + vim.keymap.set('n', ']Q', function() + vim.cmd.clast({ args = vim.v.count ~= 0 and { vim.v.count } or nil }) + end, { + desc = ':clast', + }) + + vim.keymap.set('n', '[', function() + vim.cmd.cpfile({ count = vim.v.count1 }) + end, { + desc = ':cpfile', + }) + + vim.keymap.set('n', ']', function() + vim.cmd.cnfile({ count = vim.v.count1 }) + end, { + desc = ':cnfile', + }) + + -- Location list mappings + vim.keymap.set('n', '[l', function() + vim.cmd.lprevious({ count = vim.v.count1 }) + end, { + desc = ':lprevious', + }) + + vim.keymap.set('n', ']l', function() + vim.cmd.lnext({ count = vim.v.count1 }) + end, { + desc = ':lnext', + }) + + vim.keymap.set('n', '[L', function() + vim.cmd.lrewind({ args = vim.v.count ~= 0 and { vim.v.count } or nil }) + end, { + desc = ':lrewind', + }) + + vim.keymap.set('n', ']L', function() + vim.cmd.llast({ args = vim.v.count ~= 0 and { vim.v.count } or nil }) + end, { + desc = ':llast', + }) + + vim.keymap.set('n', '[', function() + vim.cmd.lpfile({ count = vim.v.count1 }) + end, { + desc = ':lpfile', + }) + + vim.keymap.set('n', ']', function() + vim.cmd.lnfile({ count = vim.v.count1 }) + end, { + desc = ':lnfile', + }) + + -- Argument list + vim.keymap.set('n', '[a', function() + vim.cmd.previous({ count = vim.v.count1 }) + end, { + desc = ':previous', + }) + + vim.keymap.set('n', ']a', function() + vim.cmd.next({ count = vim.v.count1 }) + end, { + desc = ':next', + }) + + vim.keymap.set('n', '[A', function() + if vim.v.count ~= 0 then + vim.cmd.argument({ count = vim.v.count }) + else + vim.cmd.rewind() + end + end, { + desc = ':rewind', + }) + + vim.keymap.set('n', ']A', function() + if vim.v.count ~= 0 then + vim.cmd.argument({ count = vim.v.count }) + else + vim.cmd.last() + end + end, { + desc = ':last', + }) + + -- Tags + vim.keymap.set('n', '[t', function() + vim.cmd.tprevious({ count = vim.v.count1 }) + end, { desc = ':tprevious' }) + + vim.keymap.set('n', ']t', function() + vim.cmd.tnext({ count = vim.v.count1 }) + end, { desc = ':tnext' }) + + vim.keymap.set('n', '[T', function() + vim.cmd.trewind({ count = vim.v.count ~= 0 and vim.v.count or nil }) + end, { desc = ':trewind' }) + + vim.keymap.set('n', ']T', function() + -- :tlast does not accept a count, so use :trewind if count given + if vim.v.count ~= 0 then + vim.cmd.trewind({ count = vim.v.count }) + else + vim.cmd.tlast() + end + end, { desc = ':tlast' }) + + vim.keymap.set('n', '[', function() + vim.cmd.ptprevious({ count = vim.v.count1 }) + end, { desc = ' :ptprevious' }) + + vim.keymap.set('n', ']', function() + vim.cmd.ptnext({ count = vim.v.count1 }) + end, { desc = ':ptnext' }) + + -- Buffers + vim.keymap.set('n', '[b', function() + vim.cmd.bprevious({ count = vim.v.count1 }) + end, { desc = ':bprevious' }) + + vim.keymap.set('n', ']b', function() + vim.cmd.bnext({ count = vim.v.count1 }) + end, { desc = ':bnext' }) + + vim.keymap.set('n', '[B', function() + if vim.v.count ~= 0 then + vim.cmd.buffer({ count = vim.v.count }) + else + vim.cmd.brewind() + end + end, { desc = ':brewind' }) + + vim.keymap.set('n', ']B', function() + if vim.v.count ~= 0 then + vim.cmd.buffer({ count = vim.v.count }) + else + vim.cmd.blast() + end + end, { desc = ':blast' }) + end end --- Default menus -- cgit From 4075e613b2d38ee77e8843e9db1bf9d42af0cd49 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 3 Oct 2024 10:57:54 +0800 Subject: fix(defaults): properly pass count to quickfix commands (#30632) --- runtime/lua/vim/_defaults.lua | 8 ++++---- 1 file changed, 4 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 09670f4c32..6dd1c938de 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -225,13 +225,13 @@ do }) vim.keymap.set('n', '[Q', function() - vim.cmd.crewind({ args = vim.v.count ~= 0 and { vim.v.count } or nil }) + vim.cmd.crewind({ count = vim.v.count ~= 0 and vim.v.count or nil }) end, { desc = ':crewind', }) vim.keymap.set('n', ']Q', function() - vim.cmd.clast({ args = vim.v.count ~= 0 and { vim.v.count } or nil }) + vim.cmd.clast({ count = vim.v.count ~= 0 and vim.v.count or nil }) end, { desc = ':clast', }) @@ -262,13 +262,13 @@ do }) vim.keymap.set('n', '[L', function() - vim.cmd.lrewind({ args = vim.v.count ~= 0 and { vim.v.count } or nil }) + vim.cmd.lrewind({ count = vim.v.count ~= 0 and vim.v.count or nil }) end, { desc = ':lrewind', }) vim.keymap.set('n', ']L', function() - vim.cmd.llast({ args = vim.v.count ~= 0 and { vim.v.count } or nil }) + vim.cmd.llast({ count = vim.v.count ~= 0 and vim.v.count or nil }) end, { desc = ':llast', }) -- cgit From 289380bc40c7932c0fdfb406ec37a68745ba1cc9 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:34:21 -0500 Subject: fix(defaults): use "range" instead of "count" for some mappings (#30642) Some commands don't accept "count" and only work with "range". It's not clear why. The issue is tracked at [1], but this is a workaround for now. [1]: https://github.com/neovim/neovim/issues/30641 --- runtime/lua/vim/_defaults.lua | 20 +++++++++++++------- 1 file changed, 13 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 6dd1c938de..6cad1dbca9 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -293,7 +293,8 @@ do }) vim.keymap.set('n', ']a', function() - vim.cmd.next({ count = vim.v.count1 }) + -- count doesn't work with :next, must use range. See #30641. + vim.cmd.next({ range = { vim.v.count1 } }) end, { desc = ':next', }) @@ -320,32 +321,37 @@ do -- Tags vim.keymap.set('n', '[t', function() - vim.cmd.tprevious({ count = vim.v.count1 }) + -- count doesn't work with :tprevious, must use range. See #30641. + vim.cmd.tprevious({ range = { vim.v.count1 } }) end, { desc = ':tprevious' }) vim.keymap.set('n', ']t', function() - vim.cmd.tnext({ count = vim.v.count1 }) + -- count doesn't work with :tnext, must use range. See #30641. + vim.cmd.tnext({ range = { vim.v.count1 } }) end, { desc = ':tnext' }) vim.keymap.set('n', '[T', function() - vim.cmd.trewind({ count = vim.v.count ~= 0 and vim.v.count or nil }) + -- count doesn't work with :trewind, must use range. See #30641. + vim.cmd.trewind({ range = vim.v.count ~= 0 and { vim.v.count } or nil }) end, { desc = ':trewind' }) vim.keymap.set('n', ']T', function() -- :tlast does not accept a count, so use :trewind if count given if vim.v.count ~= 0 then - vim.cmd.trewind({ count = vim.v.count }) + vim.cmd.trewind({ range = { vim.v.count } }) else vim.cmd.tlast() end end, { desc = ':tlast' }) vim.keymap.set('n', '[', function() - vim.cmd.ptprevious({ count = vim.v.count1 }) + -- count doesn't work with :ptprevious, must use range. See #30641. + vim.cmd.ptprevious({ range = { vim.v.count1 } }) end, { desc = ' :ptprevious' }) vim.keymap.set('n', ']', function() - vim.cmd.ptnext({ count = vim.v.count1 }) + -- count doesn't work with :ptnext, must use range. See #30641. + vim.cmd.ptnext({ range = { vim.v.count1 } }) end, { desc = ':ptnext' }) -- Buffers -- cgit