aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_defaults.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-11-19 22:57:13 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-11-19 22:57:13 +0000
commit9be89f131f87608f224f0ee06d199fcd09d32176 (patch)
tree11022dcfa9e08cb4ac5581b16734196128688d48 /runtime/lua/vim/_defaults.lua
parentff7ed8f586589d620a806c3758fac4a47a8e7e15 (diff)
parent88085c2e80a7e3ac29aabb6b5420377eed99b8b6 (diff)
downloadrneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.gz
rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.bz2
rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'runtime/lua/vim/_defaults.lua')
-rw-r--r--runtime/lua/vim/_defaults.lua264
1 files changed, 249 insertions, 15 deletions
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua
index 5b964b84a0..6cad1dbca9 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! @<C-R>=reg_recorded()<CR><CR>' : 'Q'",
+ "mode() ==# 'V' ? ':normal! @<C-R>=reg_recorded()<CR><CR>' : 'Q'",
{ silent = true, expr = true, desc = ':help v_Q-default' }
)
vim.keymap.set(
'x',
'@',
- "mode() == 'V' ? ':normal! @'.getcharstr().'<CR>' : '@'",
+ "mode() ==# 'V' ? ':normal! @'.getcharstr().'<CR>' : '@'",
{ silent = true, expr = true, desc = ':help v_@-default' }
)
@@ -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()
@@ -180,12 +182,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 })
+ 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 })
+ 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 })
+ 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 })
+ end, { desc = 'Jump to the first diagnostic in the current buffer' })
vim.keymap.set('n', '<C-W>d', function()
vim.diagnostic.open_float()
@@ -198,13 +208,187 @@ 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({ count = vim.v.count ~= 0 and vim.v.count or nil })
+ end, {
+ desc = ':crewind',
+ })
+
+ vim.keymap.set('n', ']Q', function()
+ vim.cmd.clast({ count = vim.v.count ~= 0 and vim.v.count or nil })
+ end, {
+ desc = ':clast',
+ })
+
+ vim.keymap.set('n', '[<C-Q>', function()
+ vim.cmd.cpfile({ count = vim.v.count1 })
+ end, {
+ desc = ':cpfile',
+ })
+
+ vim.keymap.set('n', ']<C-Q>', 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({ count = vim.v.count ~= 0 and vim.v.count or nil })
+ end, {
+ desc = ':lrewind',
+ })
+
+ vim.keymap.set('n', ']L', function()
+ vim.cmd.llast({ count = vim.v.count ~= 0 and vim.v.count or nil })
+ end, {
+ desc = ':llast',
+ })
+
+ vim.keymap.set('n', '[<C-L>', function()
+ vim.cmd.lpfile({ count = vim.v.count1 })
+ end, {
+ desc = ':lpfile',
+ })
+
+ vim.keymap.set('n', ']<C-L>', 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()
+ -- count doesn't work with :next, must use range. See #30641.
+ vim.cmd.next({ range = { 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()
+ -- 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()
+ -- 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()
+ -- 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({ range = { vim.v.count } })
+ else
+ vim.cmd.tlast()
+ end
+ end, { desc = ':tlast' })
+
+ vim.keymap.set('n', '[<C-T>', function()
+ -- 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', ']<C-T>', function()
+ -- count doesn't work with :ptnext, must use range. See #30641.
+ vim.cmd.ptnext({ range = { 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
do
--- Right click popup menu
- -- TODO VimScript, no l10n
vim.cmd([[
+ anoremenu PopUp.Go\ to\ definition <Cmd>lua vim.lsp.buf.definition()<CR>
+ amenu PopUp.Open\ in\ web\ browser gx
+ anoremenu PopUp.Inspect <Cmd>Inspect<CR>
+ anoremenu PopUp.-1- <Nop>
vnoremenu PopUp.Cut "+x
vnoremenu PopUp.Copy "+y
anoremenu PopUp.Paste "+gP
@@ -213,10 +397,36 @@ do
nnoremenu PopUp.Select\ All ggVG
vnoremenu PopUp.Select\ All gg0oG$
inoremenu PopUp.Select\ All <C-Home><C-O>VG
- anoremenu PopUp.Inspect <Cmd>Inspect<CR>
- anoremenu PopUp.-1- <Nop>
+ anoremenu PopUp.-2- <Nop>
anoremenu PopUp.How-to\ disable\ mouse <Cmd>help disable-mouse<CR>
]])
+
+ local function enable_ctx_menu(ctx)
+ vim.cmd([[
+ 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
+
+ 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)
+ enable_ctx_menu(ctx)
+ end,
+ })
end
--- Default autocommands. See |default-autocmds|
@@ -274,6 +484,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[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[0][0].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',
@@ -462,10 +692,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<string, boolean>
require('vim.termcap').query({ 'Tc', 'RGB', 'setrgbf', 'setrgbb' }, function(cap, found)
if not found then