From 30073d82a57a4839f9687c9dbcde627c112b1839 Mon Sep 17 00:00:00 2001 From: pml68 Date: Mon, 18 Mar 2024 21:33:54 +0100 Subject: feat: autocompletion, keymaps and more --- lua/pml68/configs/cmp.lua | 21 +++++++++ lua/pml68/configs/lspconfig.lua | 1 - lua/pml68/configs/settings/lua_ls.lua | 24 +++++----- lua/pml68/configs/toggleterm.lua | 15 ++++++ lua/pml68/init.lua | 6 ++- lua/pml68/plugins.lua | 89 +++++++++++++++++++++++++---------- lua/pml68/remap.lua | 37 +++++++++++++++ 7 files changed, 155 insertions(+), 38 deletions(-) create mode 100644 lua/pml68/configs/cmp.lua create mode 100644 lua/pml68/configs/toggleterm.lua (limited to 'lua/pml68') diff --git a/lua/pml68/configs/cmp.lua b/lua/pml68/configs/cmp.lua new file mode 100644 index 0000000..ff69651 --- /dev/null +++ b/lua/pml68/configs/cmp.lua @@ -0,0 +1,21 @@ +local cmp = require("cmp") + +cmp.setup({ + sources = { + {name = 'nvim_lsp'}, + }, + preselect = 'item', + completion = { + completeopt = 'menu,menuone,noinsert' + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.confirm({select = false}), + [''] = cmp.mapping.select_prev_item({behavior = 'select'}), + [''] = cmp.mapping.select_next_item({behavior = 'select'}), + }), + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, +}) diff --git a/lua/pml68/configs/lspconfig.lua b/lua/pml68/configs/lspconfig.lua index 12aacf8..40badc3 100644 --- a/lua/pml68/configs/lspconfig.lua +++ b/lua/pml68/configs/lspconfig.lua @@ -1,5 +1,4 @@ local capabilities = require("cmp_nvim_lsp").default_capabilities() - local lspconfig = require("lspconfig") local servers = { diff --git a/lua/pml68/configs/settings/lua_ls.lua b/lua/pml68/configs/settings/lua_ls.lua index 7db368c..de4124c 100644 --- a/lua/pml68/configs/settings/lua_ls.lua +++ b/lua/pml68/configs/settings/lua_ls.lua @@ -2,18 +2,18 @@ return { settings = { Lua = { diagnostics = { - globals = { "vim " }, - }, - workspace = { - library = { - [vim.fn.expand "$VIMRUNTIME/lua"] = true, - [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true, - [vim.fn.stdpath "data" .. "/lazy/ui/nvchad_types"] = true, - [vim.fn.stdpath "data" .. "/lazy/lazy.nvim/lua/lazy"] = true, - }, - maxPreload = 100000, - preloadFileSize = 10000, - } + globals = { "vim " }, + }, + workspace = { + library = { + [vim.fn.expand "$VIMRUNTIME/lua"] = true, + [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true, + [vim.fn.stdpath "data" .. "/lazy/ui/nvchad_types"] = true, + [vim.fn.stdpath "data" .. "/lazy/lazy.nvim/lua/lazy"] = true, + }, + maxPreload = 100000, + preloadFileSize = 10000, + } } } } diff --git a/lua/pml68/configs/toggleterm.lua b/lua/pml68/configs/toggleterm.lua new file mode 100644 index 0000000..6bf4f14 --- /dev/null +++ b/lua/pml68/configs/toggleterm.lua @@ -0,0 +1,15 @@ +local Terminal = require('toggleterm.terminal').Terminal +local lazygit = Terminal:new({ + cmd = "lazygit", + hidden = true, + direction = "float", + float_opts = { + border = "double", + }, +}) + +function _lazygit_toggle() + lazygit:toggle() +end + +vim.keymap.set("n", "g", " lua _lazygit_toggle() ", {noremap = true, silent = true}) diff --git a/lua/pml68/init.lua b/lua/pml68/init.lua index de513c3..e8b5665 100644 --- a/lua/pml68/init.lua +++ b/lua/pml68/init.lua @@ -5,6 +5,10 @@ vim.api.nvim_set_hl(0, "Normal", { bg = "none" }) vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" }) vim.opt.relativenumber = true -vim.cmd("set nu") +vim.opt.nu = true +vim.opt.shiftwidth = 2 +vim.opt.tabstop = 2 vim.opt.clipboard = "unnamedplus" + +vim.opt.termguicolors = true diff --git a/lua/pml68/plugins.lua b/lua/pml68/plugins.lua index 9a4b0e8..215d65d 100644 --- a/lua/pml68/plugins.lua +++ b/lua/pml68/plugins.lua @@ -1,14 +1,52 @@ local plugins = { -- CMP - { + { "hrsh7th/nvim-cmp", - dependencies = { + event = "InsertEnter", + dependencies = { + { + "L3MON4D3/LuaSnip", + dependencies = "rafamadriz/friendly-snippets", + }, + { + "windwp/nvim-autopairs", + opts = { + fast_wrap = {}, + disable_filetype = { "TelescopePrompt", "vim" }, + }, + config = function(_, opts) + require("nvim-autopairs").setup(opts) + + local cmp_autopairs = require "nvim-autopairs.completion.cmp" + require("cmp").event:on("confirm_done", cmp_autopairs.on_confirm_done()) + end, + }, "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "hrsh7th/cmp-cmdline", - } + }, + config = function() + require("pml68.configs.cmp") + end, }, + -- Terminal + { + "akinsho/toggleterm.nvim", + version = "*", + opts = { + shade_terminals = false, + persist_size = false, + size = function(term) + if term.direction == "horizontal" then + return 15 + elseif term.direction == "vertical" then + return vim.o.columns * 0.4 + end + end, + }, + config = function(_, opts) + require("pml68.configs.toggleterm") + require("toggleterm").setup(opts) + end + }, -- Undotree { "mbbill/undotree", @@ -23,25 +61,25 @@ local plugins = { "lewis6991/gitsigns.nvim", event = "BufReadPre", opts = { - signs = { - add = { text = "│" }, - change = { text = "│" }, - delete = { text = "󰍵" }, - topdelete = { text = "‾" }, - changedelete = { text = "~" }, - untracked = { text = "│" }, + signs = { + add = { text = "│" }, + change = { text = "│" }, + delete = { text = "󰍵" }, + topdelete = { text = "‾" }, + changedelete = { text = "~" }, + untracked = { text = "│" }, }, - on_attach = function(bufnr) - local gs = package.loaded.gitsigns + on_attach = function(bufnr) + local gs = package.loaded.gitsigns - local function map(mode, l, r, opts) - opts = opts or {} - opts.buffer = bufnr - vim.keymap.set(mode, l, r, opts) - end + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end - map("n", "gb", gs.blame_line) - end, + map("n", "gb", gs.blame_line) + end, }, config = function(_, opts) require("gitsigns").setup(opts) @@ -182,13 +220,16 @@ local plugins = { "mfussenegger/nvim-dap", }, opts = { - handlers = {}, + handlers = {}, }, }, { "rcarriga/nvim-dap-ui", event = "VeryLazy", - dependencies = "mfussenegger/nvim-dap", + dependencies = { + "mfussenegger/nvim-dap", + "nvim-neotest/nvim-nio" + }, config = function() local dap = require("dap") local dapui = require("dapui") diff --git a/lua/pml68/remap.lua b/lua/pml68/remap.lua index 578cb6f..dab15ca 100644 --- a/lua/pml68/remap.lua +++ b/lua/pml68/remap.lua @@ -5,6 +5,7 @@ vim.keymap.set("v", "cs", " Silicon ") vim.keymap.set("n", "cp", ":!xclip -sel clip -target image/png -i 2024*.png && rm 2024*.png ") vim.keymap.set("n", "u", "UndotreeToggle") +-- keyboard problems (temporary) function starting() local pos = vim.api.nvim_win_get_cursor(0)[2] local line = vim.api.nvim_get_current_line() @@ -13,3 +14,39 @@ function starting() end vim.keymap.set("n", "s", " lua starting() ") + +-- switch between windows +vim.keymap.set("n", "", "h") +vim.keymap.set("n", "", "l") +vim.keymap.set("n", "", "j") +vim.keymap.set("n", "", "k") + +-- close current buffer +vim.keymap.set("n", "x", " bd ") + +-- termtoggle +vim.keymap.set("n", "h", " ToggleTerm direction=horizontal ") +vim.keymap.set("n", "v", " ToggleTerm direction=vertical ") + +-- Diagnostics, LSP +vim.keymap.set('n', 'gl', 'lua vim.diagnostic.open_float()') +vim.keymap.set('n', '[d', 'lua vim.diagnostic.goto_prev()') +vim.keymap.set('n', ']d', 'lua vim.diagnostic.goto_next()') + +vim.api.nvim_create_autocmd('LspAttach', { + desc = 'LSP actions', + callback = function(event) + local opts = {buffer = event.buf} + + vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) + vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.rename()', opts) + vim.keymap.set({'n', 'x'}, '', 'lua vim.lsp.buf.format({async = true})', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.code_action()', opts) + end +}) -- cgit v1.2.3