From 346854ff3ea83202de7437f01f1c1c336f4c3edf Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Tue, 14 May 2024 17:00:51 +0200 Subject: add whole neovim config --- .config/nvim/lua/cmp-config.lua | 90 ++++++++++++++++++++++++++++++++++++++ .config/nvim/lua/lsp.lua | 97 +++++++++++++++++++++++++++++++++++++++++ .config/nvim/lua/plug.lua | 1 + .config/nvim/lua/tree.lua | 66 ++++++++++++++++++++++++++++ 4 files changed, 254 insertions(+) create mode 100644 .config/nvim/lua/cmp-config.lua create mode 100644 .config/nvim/lua/lsp.lua create mode 100644 .config/nvim/lua/tree.lua (limited to '.config/nvim/lua') diff --git a/.config/nvim/lua/cmp-config.lua b/.config/nvim/lua/cmp-config.lua new file mode 100644 index 0000000..2bb6047 --- /dev/null +++ b/.config/nvim/lua/cmp-config.lua @@ -0,0 +1,90 @@ +local cmp = require "cmp" +require("luasnip.loaders.from_vscode").lazy_load() + +local function border(hl_name) + return { + { "╭", hl_name }, + { "─", hl_name }, + { "╮", hl_name }, + { "│", hl_name }, + { "╯", hl_name }, + { "─", hl_name }, + { "╰", hl_name }, + { "│", hl_name }, + } +end + +--if cmp_style ~= "atom" and cmp_style ~= "atom_colored" then +-- options.window.completion.border = border "CmpBorder" +-- end + +cmp.setup { + completion = { + completeopt = "menu,menuone", + }, + + window = { + completion = { + border = border "CmpBorder", + side_padding = 1, + winhighlight = "Normal:CmpPmenu,CursorLine:CmpSel,Search:None", + scrollbar = true, + }, + documentation = { + border = border "CmpDocBorder", + winhighlight = "Normal:CmpDoc", + }, + }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }, + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif require("luasnip").expand_or_jumpable() then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-expand-or-jump", true, true, true), "") + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif require("luasnip").jumpable(-1) then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-jump-prev", true, true, true), "") + else + fallback() + end + end, { "i", "s" }), + }, + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "nvim_lua" }, + { name = "path" }, + }, +} + +local signs = { Error = "󰀨 ", Warn = " ", Hint = " ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl= hl, numhl = hl }) +end diff --git a/.config/nvim/lua/lsp.lua b/.config/nvim/lua/lsp.lua new file mode 100644 index 0000000..87c00ed --- /dev/null +++ b/.config/nvim/lua/lsp.lua @@ -0,0 +1,97 @@ +-- ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +-- ┃ ╻ ┏━┓┏━┓ ┏━╸┏━┓┏┓╻┏━╸╻┏━╸ ┃ +-- ┃ ┃ ┗━┓┣━┛ ┃ ┃ ┃┃┗┫┣╸ ┃┃╺┓ ┃ +-- ┃ ┗━╸┗━┛╹ ┗━╸┗━┛╹ ╹╹ ╹┗━┛ ┃ +-- ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +vim.diagnostic.config({ + virtual_text = { + prefix = "󰬨" + } +}) + +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + + vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' + + local opts = { buffer = ev.buf } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format { async = true } + end, opts) + vim.keymap.set('n', 'd', vim.diagnostic.open_float, opts) + vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) + vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) + vim.keymap.set('n', 'q', vim.diagnostic.setloclist) + end, +}) + + +local capabilities = require("cmp_nvim_lsp").default_capabilities() + +local lspconfig = require('lspconfig') + +local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver' } +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + capabilities = capabilities, + } +end + +lspconfig.lua_ls.setup { + on_init = function(client) + local path = client.workspace_folders[1].name + if not vim.loop.fs_stat(path..'/.luarc.json') and not vim.loop.fs_stat(path..'/.luarc.jsonc') then + client.config.settings = vim.tbl_deep_extend('force', client.config.settings, { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using + -- (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT' + }, + -- Make the server aware of Neovim runtime files + workspace = { + checkThirdParty = false, + library = { + vim.env.VIMRUNTIME + -- "${3rd}/luv/library" + -- "${3rd}/busted/library", + } + -- or pull in all of 'runtimepath'. NOTE: this is a lot slower + -- library = vim.api.nvim_get_runtime_file("", true) + } + } + }) + + client.notify("workspace/didChangeConfiguration", { settings = client.config.settings }) + end + return true + end +} + +vim.api.nvim_create_autocmd("InsertLeave", { + callback = function() + if + require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] + and not require("luasnip").session.jump_active + then + require("luasnip").unlink_current() + end + end, +}) + diff --git a/.config/nvim/lua/plug.lua b/.config/nvim/lua/plug.lua index 1a78aa8..91aa8be 100644 --- a/.config/nvim/lua/plug.lua +++ b/.config/nvim/lua/plug.lua @@ -60,4 +60,5 @@ require("lazy").setup({ require("nvim-tree").setup {} end, }, + { "elkowar/yuck.vim" } }) diff --git a/.config/nvim/lua/tree.lua b/.config/nvim/lua/tree.lua new file mode 100644 index 0000000..4615e61 --- /dev/null +++ b/.config/nvim/lua/tree.lua @@ -0,0 +1,66 @@ +require("nvim-tree").setup({ + sort = { + sorter = "case_sensitive", + }, + view = { + float = { + enable = true, + quit_on_focus_loss = true, + open_win_config = function() + local screen_w = vim.opt.columns:get() + local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get() + local window_w = screen_w * 0.5 + local window_h = screen_h * 0.3 + local window_w_int = math.floor(window_w) + local window_h_int = math.floor(window_h) + local center_x = (screen_w - window_w) / 2 + local center_y = ((vim.opt.lines:get() - window_h) / 2) - vim.opt.cmdheight:get() + return { + border = "rounded", + relative = "editor", + row = center_y, + col = center_x, + width = window_w_int, + height = window_h_int, + } + end, + } + }, + renderer = { + group_empty = true, + icons = { + glyphs = { + git = { + unstaged = "", + staged = "", + unmerged = "UM", + renamed = "", + deleted = "󰆴", + untracked = "", + ignored = "", + } + } + } + }, + filters = { + dotfiles = true, + }, +}) + +vim.api.nvim_create_autocmd({ 'WinEnter', 'BufWinEnter' }, { + pattern = 'NvimTree*', + callback = function() + local def = vim.api.nvim_get_hl_by_name('Cursor', true) + vim.api.nvim_set_hl(0, 'Cursor', vim.tbl_extend('force', def, { blend = 100 })) + vim.opt.guicursor:append('a:Cursor/lCursor') + end, +}) + +vim.api.nvim_create_autocmd({ 'BufLeave', 'WinClosed' }, { + pattern = 'NvimTree*', + callback = function() + local def = vim.api.nvim_get_hl_by_name('Cursor', true) + vim.api.nvim_set_hl(0, 'Cursor', vim.tbl_extend('force', def, { blend = 0 })) + vim.opt.guicursor = 'n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20' + end, +}) -- cgit v1.2.3-70-g09d2