diff options
Diffstat (limited to 'runtime/lua/vim/_defaults.lua')
-rw-r--r-- | runtime/lua/vim/_defaults.lua | 160 |
1 files changed, 79 insertions, 81 deletions
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua index 6cad1dbca9..06f6ed6829 100644 --- a/runtime/lua/vim/_defaults.lua +++ b/runtime/lua/vim/_defaults.lua @@ -157,7 +157,7 @@ do --- 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|. + --- See |grr|, |grn|, |gra|, |gri|, |gO|, |i_CTRL-S|. do vim.keymap.set('n', 'grn', function() vim.lsp.buf.rename() @@ -171,7 +171,15 @@ do vim.lsp.buf.references() end, { desc = 'vim.lsp.buf.references()' }) - vim.keymap.set('i', '<C-S>', function() + vim.keymap.set('n', 'gri', function() + vim.lsp.buf.implementation() + end, { desc = 'vim.lsp.buf.implementation()' }) + + vim.keymap.set('n', 'gO', function() + vim.lsp.buf.document_symbol() + end, { desc = 'vim.lsp.buf.document_symbol()' }) + + vim.keymap.set({ 'i', 's' }, '<C-S>', function() vim.lsp.buf.signature_help() end, { desc = 'vim.lsp.buf.signature_help()' }) end @@ -211,173 +219,163 @@ do --- vim-unimpaired style mappings. See: https://github.com/tpope/vim-unimpaired do + --- Execute a command and print errors without a stacktrace. + --- @param opts table Arguments to |nvim_cmd()| + local function cmd(opts) + local _, err = pcall(vim.api.nvim_cmd, opts, {}) + if err then + vim.api.nvim_err_writeln(err:sub(#'Vim:' + 1)) + end + end + -- Quickfix mappings vim.keymap.set('n', '[q', function() - vim.cmd.cprevious({ count = vim.v.count1 }) - end, { - desc = ':cprevious', - }) + cmd({ 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', - }) + cmd({ 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', - }) + cmd({ 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', - }) + cmd({ 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', - }) + cmd({ 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', - }) + cmd({ 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', - }) + cmd({ 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', - }) + cmd({ 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', - }) + cmd({ 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', - }) + cmd({ 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', - }) + cmd({ 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', - }) + cmd({ 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', - }) + cmd({ 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', - }) + cmd({ 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 }) + cmd({ cmd = 'argument', count = vim.v.count }) else - vim.cmd.rewind() + cmd({ cmd = 'rewind' }) end - end, { - desc = ':rewind', - }) + end, { desc = ':rewind' }) vim.keymap.set('n', ']A', function() if vim.v.count ~= 0 then - vim.cmd.argument({ count = vim.v.count }) + cmd({ cmd = 'argument', count = vim.v.count }) else - vim.cmd.last() + cmd({ cmd = 'last' }) end - end, { - desc = ':last', - }) + 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 } }) + cmd({ 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 } }) + cmd({ 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 }) + cmd({ 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 } }) + cmd({ cmd = 'trewind', range = { vim.v.count } }) else - vim.cmd.tlast() + cmd({ 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 } }) + cmd({ 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 } }) + cmd({ cmd = 'ptnext', range = { vim.v.count1 } }) end, { desc = ':ptnext' }) -- Buffers vim.keymap.set('n', '[b', function() - vim.cmd.bprevious({ count = vim.v.count1 }) + cmd({ cmd = 'bprevious', count = vim.v.count1 }) end, { desc = ':bprevious' }) vim.keymap.set('n', ']b', function() - vim.cmd.bnext({ count = vim.v.count1 }) + cmd({ 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 }) + cmd({ cmd = 'buffer', count = vim.v.count }) else - vim.cmd.brewind() + cmd({ 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 }) + cmd({ cmd = 'buffer', count = vim.v.count }) else - vim.cmd.blast() + cmd({ cmd = 'blast' }) end end, { desc = ':blast' }) + + -- Add empty lines + vim.keymap.set('n', '[<Space>', function() + -- TODO: update once it is possible to assign a Lua function to options #25672 + vim.go.operatorfunc = "v:lua.require'vim._buf'.space_above" + return 'g@l' + end, { expr = true, desc = 'Add empty line above cursor' }) + + vim.keymap.set('n', ']<Space>', function() + -- TODO: update once it is possible to assign a Lua function to options #25672 + vim.go.operatorfunc = "v:lua.require'vim._buf'.space_below" + return 'g@l' + end, { expr = true, desc = 'Add empty line below cursor' }) end end |