From 0d5860fab0693f45b869b9bd71bfc49e2088ffc4 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Wed, 5 Jul 2023 19:00:59 +0200 Subject: [PATCH] Updated neovim config --- config/lazygit/config.yml | 2 +- config/nvim/init.lua | 180 ++++++++++++++++++++++++++++---------- 2 files changed, 133 insertions(+), 49 deletions(-) diff --git a/config/lazygit/config.yml b/config/lazygit/config.yml index 03fc5f6..a23d81a 100644 --- a/config/lazygit/config.yml +++ b/config/lazygit/config.yml @@ -1,3 +1,3 @@ gui: - showIcons: true + showIcons: false diff --git a/config/nvim/init.lua b/config/nvim/init.lua index b070c4e..a40d6ce 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -53,9 +53,7 @@ vim.o.showmode = false vim.o.showtabline = 0 -vim.o.wrap = false - --- vim.o.cmdheight = 0 +vim.o.wrap = true -- show cursor line only in active window local cursorLineGrp = vim.api.nvim_create_augroup("CursorLine", { clear = true }) @@ -68,6 +66,9 @@ vim.api.nvim_create_autocmd( { pattern = "*", command = "set nocursorline", group = cursorLineGrp } ) +-- Auto format on save +vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]] + ------------------------------------------------------------------- -- Plugin management ------------------------------------------------------------------- @@ -125,7 +126,7 @@ require('lazy').setup({ }, -- "gc" to comment visual regions/lines - { 'numToStr/Comment.nvim', opts = {} }, + { 'numToStr/Comment.nvim', opts = {} }, -- Fuzzy Finder (files, lsp, etc) { @@ -243,10 +244,18 @@ require('lazy').setup({ add = { text = "▎" }, change = { text = "▎" }, delete = { text = "▎" }, - topdelete = { text = "契" }, + topdelete = { text = "▎" }, changedelete = { text = "▎" }, untracked = { text = "▎" }, }, + preview_config = { + -- Options passed to nvim_open_win + border = 'solid', + style = 'minimal', + relative = 'cursor', + row = 0, + col = 1 + }, on_attach = function(bufnr) vim.keymap.set('n', 'gp', require('gitsigns').prev_hunk, { buffer = bufnr, desc = '[G]o to [P]revious Hunk' }) @@ -308,7 +317,12 @@ require('lazy').setup({ } }, - { 'mrjones2014/smart-splits.nvim' }, + { + 'mrjones2014/smart-splits.nvim', + opts = { + at_edge = 'stop', + } + }, { "folke/neodev.nvim", @@ -409,17 +423,6 @@ require('lazy').setup({ Y = "copy_selector", }, }, - -- filesystem = { - -- follow_current_file = false, - -- hijack_netrw_behavior = "open_current", - -- use_libuv_file_watcher = true, - -- }, - -- event_handlers = { - -- { - -- event = "neo_tree_buffer_enter", - -- handler = function(_) vim.opt_local.signcolumn = "auto" end, - -- }, - -- }, } end, }, @@ -459,14 +462,50 @@ require('lazy').setup({ } }, - -- { - -- "levouh/tint.nvim", - -- config = function() - -- require("tint").setup { - -- highlight_ignore_patterns = { "EndOfBuffer" }, - -- } - -- end, - -- }, + { + "simrat39/rust-tools.nvim", + }, + + { + "folke/todo-comments.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + } + }, + + { + 'phaazon/hop.nvim', + branch = 'v2', -- optional but strongly recommended + config = function() + -- you can configure Hop the way you like here; see :h hop-config + require 'hop'.setup { keys = 'etovxqpdygfblzhckisuran' } + end + }, + + { + "folke/trouble.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + }, + }, + + { + "ray-x/lsp_signature.nvim", + config = function() + require "lsp_signature".setup { + bind = true, -- This is mandatory, otherwise border config won't get registered. + handler_opts = { + border = "solid" + } + } + end + }, }, {}) @@ -512,7 +551,12 @@ local servers = { cmd = { 'clangd', '--background-index' }, filetypes = { 'c', 'cpp', 'objc', 'objcpp' }, }, - rust_analyzer = {}, + rust_analyzer = { + -- rust = { + -- target = "thumbv7em-none-eabihf", + -- all_targets = false + -- } + }, bashls = {}, pyright = {}, marksman = {}, @@ -543,15 +587,50 @@ mason_lspconfig.setup_handlers { } local handlers = { - ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "single" }), - ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "single" }), + ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "solid" }), + ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "solid" }), } require('lspconfig').rust_analyzer.setup { on_attach = on_attach, handlers = handlers, + -- require("rust-tools").setup() } +local opts = { + tools = { + runnables = { + use_telescope = true, + }, + inlay_hints = { + auto = true, + show_parameter_hints = false, + parameter_hints_prefix = "=> ", + other_hints_prefix = "=> ", + }, + }, + + -- all the opts to send to nvim-lspconfig + -- these override the defaults set by rust-tools.nvim + -- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer + server = { + -- on_attach is a callback called when the language server attachs to the buffer + on_attach = on_attach, + settings = { + -- to enable rust-analyzer settings visit: + -- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc + ["rust-analyzer"] = { + -- enable clippy on save + checkOnSave = { + command = "clippy", + }, + }, + }, + }, +} + +require("rust-tools").setup(opts) + require('lspconfig').clangd.setup { on_attach = on_attach, capabilities = { offsetEncoding = 'utf-16' }, @@ -593,12 +672,15 @@ local luasnip = require 'luasnip' require('luasnip.loaders.from_vscode').lazy_load() luasnip.config.setup {} local cmp_opts = { - border = "single", + border = "solid", winhighlight = 'Normal:Pmenu,FloatBorder:FloatBorder,Search:NONE,CursorLine:PmenuSel', } cmp.setup { preselect = cmp.PreselectMode.None, + view = { + entries = "custom" -- can be "custom", "wildmenu" or "native" + }, completion = { completion = { completeopt = 'menu,menuone,noinsert,noselect' }, }, @@ -644,9 +726,9 @@ cmp.setup { end, { 'i', 's' }), }, sources = { - { name = 'copilot', priority = 2000 }, - { name = 'nvim_lsp', priority = 1000 }, - { name = 'luasnip', priority = 750 }, + { name = 'nvim_lsp', priority = 2000 }, + { name = 'luasnip', priority = 1000 }, + { name = 'copilot', priority = 750 }, { name = 'buffer', priority = 500 }, { name = 'path', priority = 250 }, }, @@ -654,6 +736,9 @@ cmp.setup { cmp.setup.cmdline({ '/', '?' }, { mapping = cmp.mapping.preset.cmdline(), + view = { + entries = { name = 'wildmenu', separator = '|' } + }, window = { completion = cmp.config.window.bordered(cmp_opts), documentation = cmp.config.window.bordered(cmp_opts), @@ -665,6 +750,9 @@ cmp.setup.cmdline({ '/', '?' }, { cmp.setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), + view = { + entries = { name = 'wildmenu', separator = '|' } + }, window = { completion = cmp.config.window.bordered(cmp_opts), documentation = cmp.config.window.bordered(cmp_opts), @@ -743,23 +831,15 @@ require('nvim-treesitter.configs').setup { -- resizing splits -vim.keymap.set('n', '', require('smart-splits').resize_left, { desc = 'Resize left' }) -vim.keymap.set('n', '', require('smart-splits').resize_down, { desc = 'Resize down' }) -vim.keymap.set('n', '', require('smart-splits').resize_up, { desc = 'Resize up' }) -vim.keymap.set('n', '', require('smart-splits').resize_right, { desc = 'Resize right' }) -vim.keymap.set('t', '', require('smart-splits').resize_left, { desc = 'Resize left' }) -vim.keymap.set('t', '', require('smart-splits').resize_down, { desc = 'Resize down' }) -vim.keymap.set('t', '', require('smart-splits').resize_up, { desc = 'Resize up' }) -vim.keymap.set('t', '', require('smart-splits').resize_right, { desc = 'Resize right' }) +vim.keymap.set({ 'n', 't' }, '', require('smart-splits').resize_left, { desc = 'Resize left' }) +vim.keymap.set({ 'n', 't' }, '', require('smart-splits').resize_down, { desc = 'Resize down' }) +vim.keymap.set({ 'n', 't' }, '', require('smart-splits').resize_up, { desc = 'Resize up' }) +vim.keymap.set({ 'n', 't' }, '', require('smart-splits').resize_right, { desc = 'Resize right' }) -- moving between splits -vim.keymap.set('n', '', require('smart-splits').move_cursor_left, { desc = 'Move cursor left' }) -vim.keymap.set('n', '', require('smart-splits').move_cursor_down, { desc = 'Move cursor down' }) -vim.keymap.set('n', '', require('smart-splits').move_cursor_up, { desc = 'Move cursor up' }) -vim.keymap.set('n', '', require('smart-splits').move_cursor_right, { desc = 'Move cursor right' }) -vim.keymap.set('t', '', require('smart-splits').move_cursor_left, { desc = 'Move cursor left' }) -vim.keymap.set('t', '', require('smart-splits').move_cursor_down, { desc = 'Move cursor down' }) -vim.keymap.set('t', '', require('smart-splits').move_cursor_up, { desc = 'Move cursor up' }) -vim.keymap.set('t', '', require('smart-splits').move_cursor_right, { desc = 'Move cursor right' }) +vim.keymap.set({ 'n', 't' }, '', require('smart-splits').move_cursor_left, { desc = 'Move cursor left' }) +vim.keymap.set({ 'n', 't' }, '', require('smart-splits').move_cursor_down, { desc = 'Move cursor down' }) +vim.keymap.set({ 'n', 't' }, '', require('smart-splits').move_cursor_up, { desc = 'Move cursor up' }) +vim.keymap.set({ 'n', 't' }, '', require('smart-splits').move_cursor_right, { desc = 'Move cursor right' }) -- swapping buffers between windows vim.keymap.set('n', 'h', require('smart-splits').swap_buf_left, { desc = 'Swap buffer left' }) vim.keymap.set('n', 'j', require('smart-splits').swap_buf_down, { desc = 'Swap buffer down' }) @@ -779,6 +859,10 @@ vim.keymap.set('n', '', ":Format", { desc = 'Format code', silent = tru vim.keymap.set('n', 'gg', ":LazyGitCurrentFile", { desc = 'Format code', silent = true }) vim.keymap.set('n', '', ":make", { desc = 'Format code', silent = true }) vim.keymap.set('n', '', ":make clean", { desc = 'Format code', silent = true }) +vim.keymap.set('n', '', ":write", { desc = 'Save', silent = true }) +vim.keymap.set('n', '', ":quit", { desc = 'Quit', silent = true }) vim.keymap.set('n', 'n', ":tabnew", { desc = 'Format code', silent = true }) vim.keymap.set('n', 'c', ":tabclose", { desc = 'Format code', silent = true }) vim.keymap.set('n', 'e', ":NeoTreeShowToggle", { desc = 'File explorer', silent = true }) +vim.keymap.set('n', 's', ":HopWord", { desc = 'hop', silent = true }) +vim.keymap.set('n', 't', ":TroubleToggle", { desc = 'Trouble view', silent = true })