From 5bc29f77a48b8e46513c982362a55884e7f65238 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Mon, 8 Jul 2024 13:42:25 +0300 Subject: Neovim: worked more on completions, and changed a few other things in keymaps and options --- .config/nvim/lua/autocmds.lua | 19 ++++++++------- .config/nvim/lua/custom/completion.lua | 44 +++++++--------------------------- .config/nvim/lua/custom/lsp.lua | 24 ++++++++++--------- .config/nvim/lua/keymaps.lua | 26 +++++++++++++------- .config/nvim/lua/options.lua | 16 +++++++------ 5 files changed, 58 insertions(+), 71 deletions(-) (limited to '.config/nvim/lua') diff --git a/.config/nvim/lua/autocmds.lua b/.config/nvim/lua/autocmds.lua index 82f1107..5272029 100644 --- a/.config/nvim/lua/autocmds.lua +++ b/.config/nvim/lua/autocmds.lua @@ -6,12 +6,13 @@ vim.api.nvim_create_autocmd('TextYankPost', { end, }) -vim.api.nvim_create_autocmd('FileType', { - group = vim.api.nvim_create_augroup('disable-auto-comment', { clear = true }), - pattern = '*', - callback = function() - -- c - autowrap using textwidth | r - enter in insert mode | o - o/O in normal mode - -- vim.opt.formatoptions:remove({ 'c', 'r', 'o' }) - vim.cmd('set formatoptions-=co') - end, -}) +-- vim.api.nvim_create_autocmd('FileType', { +-- group = vim.api.nvim_create_augroup('disable-auto-comment', { clear = true }), +-- pattern = '*', +-- callback = function() +-- -- c - autowrap using textwidth | r - enter in insert mode | o - o/O in normal mode +-- -- vim.opt.formatoptions:remove({ 'c', 'r', 'o' }) +-- vim.opt.formatoptions:remove('o') +-- -- vim.cmd('set formatoptions-=o') +-- end, +-- }) diff --git a/.config/nvim/lua/custom/completion.lua b/.config/nvim/lua/custom/completion.lua index 50df64b..80c9531 100644 --- a/.config/nvim/lua/custom/completion.lua +++ b/.config/nvim/lua/custom/completion.lua @@ -7,7 +7,7 @@ cmp.event:on('confirm_done', require('nvim-autopairs.completion.cmp').on_confirm -- Helper functions local function tab(is_forward) - cmp.mapping(function(fallback) + return cmp.mapping(function(fallback) local jump_amount = is_forward and 1 or -1 if cmp.visible() then local behaviour = cmp.SelectBehavior.Select @@ -21,8 +21,6 @@ local function tab(is_forward) end, { 'i', 's' }) end -local function enter() end - local function is_enabled() local context = require('cmp.config.context') @@ -43,6 +41,7 @@ cmp.setup({ { name = 'lazydev', group_index = 0 }, -- for lazydev.nvim { name = 'path' }, -- for filesystem }), + snippet = { expand = function(args) luasnip.lsp_expand(args.body) @@ -54,46 +53,19 @@ cmp.setup({ documentation = cmp.config.window.bordered(), }, mapping = cmp.mapping.preset.insert({ - -- TODO: Make good keybindings [''] = tab(true), [''] = tab(false), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - if luasnip.expandable() then - luasnip.expand() - else - cmp.confirm({ select = true }) - end - else - fallback() - end - end), - + [''] = cmp.mapping.complete(), -- invoke completion + [''] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Insert }), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.abort(), -- NOTE: Select makes it so it doesn't put the text in the buffer (like Insert or defualt does) -- Ex: typing "p" and then select "private" will not write "private" in your buffer, but keep it "p" -- Only after accepting the suggestion then it'll become "private" [''] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), [''] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), - - [''] = cmp.mapping( - cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Insert }), - { 'i', 'c' } - ), - - [''] = cmp.mapping.complete(), -- invoke completion - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - - -- [''] = cmp.mapping.abort(), - -- [''] = cmp.mapping.confirm({ select = true }), - -- [''] = cmp.mapping( - -- cmp.mapping.confirm({ - -- behavior = cmp.ConfirmBehavior.Insert, - -- select = true, - -- }), - -- { 'i', 'c' } - -- ), }), }) -print('Sourced lsp.lua') +print('Sourced completion.lua') diff --git a/.config/nvim/lua/custom/lsp.lua b/.config/nvim/lua/custom/lsp.lua index 1238001..d534e22 100644 --- a/.config/nvim/lua/custom/lsp.lua +++ b/.config/nvim/lua/custom/lsp.lua @@ -1,18 +1,18 @@ -- NOTE: A list of language servers (and potentially their config) -- Accepts either true to enable, false to disable or a table with settings local servers = { - lua_ls = true, -- lua - clangd = true, -- C/C++ - gradle_ls = true, -- java package manager - jdtls = true, -- java eclipse lsp + lua_ls = true, -- lua + clangd = true, -- C/C++ + gradle_ls = true, -- java package manager + jdtls = true, -- java eclipse lsp kotlin_language_server = true, -- kotlin - pyright = true, -- python - rust_analyzer = true, -- rust - bashls = true, -- bash - taplo = true, -- toml - lemminx = true, -- xml - yamlls = true, -- yaml - jsonls = true, -- json + pyright = true, -- python + rust_analyzer = true, -- rust + bashls = true, -- bash + taplo = true, -- toml + lemminx = true, -- xml + yamlls = true, -- yaml + jsonls = true, -- json } -- NOTE: Not language servers but still make sure mason installs them @@ -97,3 +97,5 @@ vim.api.nvim_create_autocmd('LspAttach', { -- -- require('lsp_lines').setup() -- vim.diagnostic.config({ virtual_text = false }) + +print('Sourced lsp.lua') diff --git a/.config/nvim/lua/keymaps.lua b/.config/nvim/lua/keymaps.lua index 6772f0f..a48679e 100644 --- a/.config/nvim/lua/keymaps.lua +++ b/.config/nvim/lua/keymaps.lua @@ -1,18 +1,26 @@ local set = vim.keymap.set local silent = { silent = true } +---@param mode string|table +---@param keymap string +local function unbind(mode, keymap) + set(mode, keymap, function() end) +end -- Misc set({ 'n', 'i' }, '', 'ggVG', { desc = 'Visually Highlight [A]ll' }) -set('n', '', ':nohlsearch', silent) -set({ 'i', 'c' }, '', '+') +set('n', '', 'nohlsearch', silent) +set({ 'i', 'c' }, '', function() + vim.fn.getreg('+') +end) set('n', 'z', function() vim.cmd('Neotree close') vim.cmd('Trouble todo close') vim.cmd('UndotreeHide') end, { desc = '[Z]en Mode', silent = true }) +unbind({ 'i', 'n', 'v' }, '') -set('n', 'U', ':redo') -set('i', '', ':undo') +set('n', 'U', 'redo') +set('i', '', 'undo') -- Window Navigation set('n', '', '', { desc = 'Move focus to the left window' }) @@ -22,10 +30,10 @@ set('n', '', '', { desc = 'Move focus to the right window' }) -- Window resizing local resize = 2 -set({ 'n', 't' }, '', string.format(':vertical resize -%d', resize), { desc = 'Resize Left' }) -set({ 'n', 't' }, '', string.format(':resize -%d', resize), { desc = 'Resize Up' }) -set({ 'n', 't' }, '', string.format(':resize +%d', resize), { desc = 'Resize Down' }) -set({ 'n', 't' }, '', string.format(':vertical resize +%d', resize), { desc = 'Resize Right' }) +set({ 'n', 't' }, '', string.format('vertical resize -%d', resize), { desc = 'Resize Left' }) +set({ 'n', 't' }, '', string.format('resize -%d', resize), { desc = 'Resize Up' }) +set({ 'n', 't' }, '', string.format('resize +%d', resize), { desc = 'Resize Down' }) +set({ 'n', 't' }, '', string.format('vertical resize +%d', resize), { desc = 'Resize Right' }) -- Keep selection after < and > in visual mode set('v', '<', '', '>gv') -- Execute lua file or line set('n', 'x', '.lua', { desc = 'Execute the current line' }) set('n', 'x', 'source %', { desc = 'Execute the current file' }) + +print('Sourced keymaps.lua') diff --git a/.config/nvim/lua/options.lua b/.config/nvim/lua/options.lua index 85153de..0ff65b9 100644 --- a/.config/nvim/lua/options.lua +++ b/.config/nvim/lua/options.lua @@ -3,15 +3,15 @@ vim.g.maplocalleader = ' ' -- System vim.g.have_nerd_font = true -vim.opt.mouse = 'a' -- enable mouse +vim.opt.mouse = 'a' -- enable mouse vim.opt.clipboard = 'unnamedplus' -- use system clipboard vim.opt.undofile = true -- Persist undo history by saving it to a file -- Tab vim.opt.expandtab = true -- convert tabs to spaces -vim.opt.tabstop = 4 -- number of visual spaces per TAB -vim.opt.softtabstop = 4 -- number of idfk tab when editing -vim.opt.shiftwidth = 4 -- number of spaces to insert on tab +vim.opt.tabstop = 4 -- number of visual spaces per TAB +vim.opt.softtabstop = 4 -- number of idfk tab when editing +vim.opt.shiftwidth = 4 -- number of spaces to insert on tab -- UI vim.opt.signcolumn = 'auto:9' @@ -35,9 +35,9 @@ vim.opt.wrap = false vim.opt.scrolloff = 8 vim.opt.undofile = true vim.opt.termguicolors = true -vim.opt.laststatus = 3 -- views can only be fully collapsed with the global statusline -vim.opt.splitkeep = 'screen' -- for edgy.nvim -vim.opt.inccommand = 'split' -- shows preview for commands like :%s/from/to +vim.opt.laststatus = 3 -- views can only be fully collapsed with the global statusline +vim.opt.splitkeep = 'screen' -- for edgy.nvim +vim.opt.inccommand = 'split' -- shows preview for commands like :%s/from/to vim.opt.formatoptions:remove('o') -- don't have `o` add a comment -- Disable warnings for missing language providers @@ -45,3 +45,5 @@ vim.g.loaded_node_provider = 0 vim.g.loaded_perl_provider = 0 vim.g.loaded_ruby_provider = 0 vim.g.loaded_python3_provider = 0 + +print('Sourced options.lua') -- cgit v1.3.1