diff --git a/init.lua b/init.lua index b98ffc6198a..60cc33cd53a 100644 --- a/init.lua +++ b/init.lua @@ -102,7 +102,8 @@ vim.g.have_nerd_font = false vim.o.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! --- vim.o.relativenumber = true + +vim.opt.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.o.mouse = 'a' @@ -198,6 +199,7 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the left wind vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) +vim.keymap.set('n', 'e', ':Explor', { desc = 'Open [E]xplor' }) -- NOTE: Some terminals have colliding keymaps or are not able to send distinct keycodes -- vim.keymap.set("n", "", "H", { desc = "Move window to the left" }) @@ -255,7 +257,6 @@ require('lazy').setup({ -- -- Use `opts = {}` to automatically pass options to a plugin's `setup()` function, forcing the plugin to be loaded. -- - -- Alternatively, use `config = function() ... end` for full control over the configuration. -- If you prefer to call `setup` explicitly, use: -- { @@ -271,6 +272,37 @@ require('lazy').setup({ -- options to `gitsigns.nvim`. -- -- See `:help gitsigns` to understand what the configuration keys do + { + 'zbirenbaum/copilot.lua', + cmd = 'Copilot', + build = ':Copilot auth', + event = 'BufReadPost', + opts = { + suggestion = { + enabled = not vim.g.ai_cmp, + auto_trigger = true, + hide_during_completion = vim.g.ai_cmp, + keymap = { + accept = false, -- handled by nvim-cmp / blink.cmp + next = '', + prev = '', + }, + }, + panel = { enabled = false }, + filetypes = { + markdown = true, + help = true, + }, + }, + }, + { + 'karb94/neoscroll.nvim', + opts = {}, + }, + { + 'nvim-tree/nvim-tree.lua', + }, + { -- Adds git related signs to the gutter, as well as utilities for managing changes 'lewis6991/gitsigns.nvim', opts = { @@ -493,6 +525,7 @@ require('lazy').setup({ 'saghen/blink.cmp', }, config = function() + require('lspconfig').lua_ls.setup {} -- Brief aside: **What is LSP?** -- -- LSP is an initialism you've probably heard, but might not understand what it is. @@ -718,6 +751,32 @@ require('lazy').setup({ 'stylua', -- Used to format Lua code }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } + require('neoscroll').setup { + mappings = { -- Keys to be mapped to their corresponding default scrolling animation + '', + '', + '', + '', + '', + '', + 'zt', + 'zz', + 'zb', + }, + hide_cursor = true, -- Hide cursor while scrolling + stop_eof = true, -- Stop at when scrolling downwards + respect_scrolloff = false, -- Stop scrolling when the cursor reaches the scrolloff margin of the file + cursor_scrolls_alone = true, -- The cursor will keep on scrolling even if the window cannot scroll further + duration_multiplier = 1.0, -- Global duration multiplier + easing = 'linear', -- Default easing function + pre_hook = nil, -- Function to run before the scrolling animation starts + post_hook = nil, -- Function to run after the scrolling animation ends + performance_mode = false, -- Disable "Performance Mode" on all buffers. + ignored_events = { -- Events ignored while scrolling + 'WinScrolled', + 'CursorMoved', + }, + } require('mason-lspconfig').setup { ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) @@ -826,6 +885,91 @@ require('lazy').setup({ -- you will need to read `:help ins-completion` -- -- No, but seriously. Please read `:help ins-completion`, it is really good! + + mapping = cmp.mapping.preset.insert { + -- Select the [n]ext item + [''] = cmp.mapping.select_next_item(), + -- Select the [p]revious item + [''] = cmp.mapping.select_prev_item(), + + -- Scroll the documentation window [b]ack / [f]orward + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + + -- Accept ([y]es) the completion. + -- This will auto-import if your LSP supports it. + -- This will expand snippets if the LSP sent a snippet. + [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping(function(fallback) + local fallback_key = vim.api.nvim_replace_termcodes('', true, true, true) + local resolved_key = vim.fn['copilot#Accept'](fallback) + if fallback_key == resolved_key then + cmp.confirm { select = true } + else + vim.api.nvim_feedkeys(resolved_key, 'n', true) + end + end), + -- If you prefer more traditional completion keymaps, + -- you can uncomment the following lines + --[''] = cmp.mapping.confirm { select = true }, + --[''] = cmp.mapping.select_next_item(), + --[''] = cmp.mapping.select_prev_item(), + + -- Manually trigger a completion from nvim-cmp. + -- Generally you don't need this, because nvim-cmp will display + -- completions whenever it has completion options available. + [''] = cmp.mapping.complete {}, + [''] = cmp.mapping(function(fallback) + local copilot = require 'copilot.suggestion' + if copilot.is_visible() then + copilot.accept() + elseif cmp.visible() then + local entry = cmp.get_selected_entry() + if not entry then + cmp.select_next_item { behavior = cmp.SelectBehavior.Select } + else + cmp.confirm() + end + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + -- Think of as moving to the right of your snippet expansion. + -- So if you have a snippet that's like: + -- function $name($args) + -- $body + -- end + -- + -- will move you to the right of each of the expansion locations. + -- is similar, except moving you backwards. + [''] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { 'i', 's' }), + + -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: + -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps + }, + sources = { + { + name = 'lazydev', + -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it + group_index = 0, + }, + { name = 'copilot' }, + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'path' }, + { name = 'nvim_lsp_signature_help' }, + -- -- All presets have the following mappings: -- /: move to right/left of your snippet expansion @@ -857,6 +1001,7 @@ require('lazy').setup({ default = { 'lsp', 'path', 'snippets', 'lazydev' }, providers = { lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 }, + }, },