Updated neovim config

This commit is contained in:
Christoffer Martinsson 2023-07-05 19:00:59 +02:00
parent 4a05a27e54
commit 0d5860fab0
2 changed files with 133 additions and 49 deletions

View File

@ -1,3 +1,3 @@
gui: gui:
showIcons: true showIcons: false

View File

@ -53,9 +53,7 @@ vim.o.showmode = false
vim.o.showtabline = 0 vim.o.showtabline = 0
vim.o.wrap = false vim.o.wrap = true
-- vim.o.cmdheight = 0
-- show cursor line only in active window -- show cursor line only in active window
local cursorLineGrp = vim.api.nvim_create_augroup("CursorLine", { clear = true }) 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 } { pattern = "*", command = "set nocursorline", group = cursorLineGrp }
) )
-- Auto format on save
vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]]
------------------------------------------------------------------- -------------------------------------------------------------------
-- Plugin management -- Plugin management
------------------------------------------------------------------- -------------------------------------------------------------------
@ -125,7 +126,7 @@ require('lazy').setup({
}, },
-- "gc" to comment visual regions/lines -- "gc" to comment visual regions/lines
{ 'numToStr/Comment.nvim', opts = {} }, { 'numToStr/Comment.nvim', opts = {} },
-- Fuzzy Finder (files, lsp, etc) -- Fuzzy Finder (files, lsp, etc)
{ {
@ -243,10 +244,18 @@ require('lazy').setup({
add = { text = "" }, add = { text = "" },
change = { text = "" }, change = { text = "" },
delete = { text = "" }, delete = { text = "" },
topdelete = { text = "" }, topdelete = { text = "" },
changedelete = { text = "" }, changedelete = { text = "" },
untracked = { 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) on_attach = function(bufnr)
vim.keymap.set('n', '<leader>gp', require('gitsigns').prev_hunk, vim.keymap.set('n', '<leader>gp', require('gitsigns').prev_hunk,
{ buffer = bufnr, desc = '[G]o to [P]revious 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", "folke/neodev.nvim",
@ -409,17 +423,6 @@ require('lazy').setup({
Y = "copy_selector", 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, end,
}, },
@ -459,14 +462,50 @@ require('lazy').setup({
} }
}, },
-- { {
-- "levouh/tint.nvim", "simrat39/rust-tools.nvim",
-- config = function() },
-- require("tint").setup {
-- highlight_ignore_patterns = { "EndOfBuffer" }, {
-- } "folke/todo-comments.nvim",
-- end, 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' }, cmd = { 'clangd', '--background-index' },
filetypes = { 'c', 'cpp', 'objc', 'objcpp' }, filetypes = { 'c', 'cpp', 'objc', 'objcpp' },
}, },
rust_analyzer = {}, rust_analyzer = {
-- rust = {
-- target = "thumbv7em-none-eabihf",
-- all_targets = false
-- }
},
bashls = {}, bashls = {},
pyright = {}, pyright = {},
marksman = {}, marksman = {},
@ -543,15 +587,50 @@ mason_lspconfig.setup_handlers {
} }
local handlers = { local handlers = {
["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "single" }), ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "solid" }),
["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "single" }), ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "solid" }),
} }
require('lspconfig').rust_analyzer.setup { require('lspconfig').rust_analyzer.setup {
on_attach = on_attach, on_attach = on_attach,
handlers = handlers, 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 { require('lspconfig').clangd.setup {
on_attach = on_attach, on_attach = on_attach,
capabilities = { offsetEncoding = 'utf-16' }, capabilities = { offsetEncoding = 'utf-16' },
@ -593,12 +672,15 @@ local luasnip = require 'luasnip'
require('luasnip.loaders.from_vscode').lazy_load() require('luasnip.loaders.from_vscode').lazy_load()
luasnip.config.setup {} luasnip.config.setup {}
local cmp_opts = { local cmp_opts = {
border = "single", border = "solid",
winhighlight = 'Normal:Pmenu,FloatBorder:FloatBorder,Search:NONE,CursorLine:PmenuSel', winhighlight = 'Normal:Pmenu,FloatBorder:FloatBorder,Search:NONE,CursorLine:PmenuSel',
} }
cmp.setup { cmp.setup {
preselect = cmp.PreselectMode.None, preselect = cmp.PreselectMode.None,
view = {
entries = "custom" -- can be "custom", "wildmenu" or "native"
},
completion = { completion = {
completion = { completeopt = 'menu,menuone,noinsert,noselect' }, completion = { completeopt = 'menu,menuone,noinsert,noselect' },
}, },
@ -644,9 +726,9 @@ cmp.setup {
end, { 'i', 's' }), end, { 'i', 's' }),
}, },
sources = { sources = {
{ name = 'copilot', priority = 2000 }, { name = 'nvim_lsp', priority = 2000 },
{ name = 'nvim_lsp', priority = 1000 }, { name = 'luasnip', priority = 1000 },
{ name = 'luasnip', priority = 750 }, { name = 'copilot', priority = 750 },
{ name = 'buffer', priority = 500 }, { name = 'buffer', priority = 500 },
{ name = 'path', priority = 250 }, { name = 'path', priority = 250 },
}, },
@ -654,6 +736,9 @@ cmp.setup {
cmp.setup.cmdline({ '/', '?' }, { cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(), mapping = cmp.mapping.preset.cmdline(),
view = {
entries = { name = 'wildmenu', separator = '|' }
},
window = { window = {
completion = cmp.config.window.bordered(cmp_opts), completion = cmp.config.window.bordered(cmp_opts),
documentation = cmp.config.window.bordered(cmp_opts), documentation = cmp.config.window.bordered(cmp_opts),
@ -665,6 +750,9 @@ cmp.setup.cmdline({ '/', '?' }, {
cmp.setup.cmdline(':', { cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(), mapping = cmp.mapping.preset.cmdline(),
view = {
entries = { name = 'wildmenu', separator = '|' }
},
window = { window = {
completion = cmp.config.window.bordered(cmp_opts), completion = cmp.config.window.bordered(cmp_opts),
documentation = cmp.config.window.bordered(cmp_opts), documentation = cmp.config.window.bordered(cmp_opts),
@ -743,23 +831,15 @@ require('nvim-treesitter.configs').setup {
-- resizing splits -- resizing splits
vim.keymap.set('n', '<A-h>', require('smart-splits').resize_left, { desc = 'Resize left' }) vim.keymap.set({ 'n', 't' }, '<A-h>', require('smart-splits').resize_left, { desc = 'Resize left' })
vim.keymap.set('n', '<A-j>', require('smart-splits').resize_down, { desc = 'Resize down' }) vim.keymap.set({ 'n', 't' }, '<A-j>', require('smart-splits').resize_down, { desc = 'Resize down' })
vim.keymap.set('n', '<A-k>', require('smart-splits').resize_up, { desc = 'Resize up' }) vim.keymap.set({ 'n', 't' }, '<A-k>', require('smart-splits').resize_up, { desc = 'Resize up' })
vim.keymap.set('n', '<A-l>', require('smart-splits').resize_right, { desc = 'Resize right' }) vim.keymap.set({ 'n', 't' }, '<A-l>', require('smart-splits').resize_right, { desc = 'Resize right' })
vim.keymap.set('t', '<A-h>', require('smart-splits').resize_left, { desc = 'Resize left' })
vim.keymap.set('t', '<A-j>', require('smart-splits').resize_down, { desc = 'Resize down' })
vim.keymap.set('t', '<A-k>', require('smart-splits').resize_up, { desc = 'Resize up' })
vim.keymap.set('t', '<A-l>', require('smart-splits').resize_right, { desc = 'Resize right' })
-- moving between splits -- moving between splits
vim.keymap.set('n', '<C-h>', require('smart-splits').move_cursor_left, { desc = 'Move cursor left' }) vim.keymap.set({ 'n', 't' }, '<C-h>', require('smart-splits').move_cursor_left, { desc = 'Move cursor left' })
vim.keymap.set('n', '<C-j>', require('smart-splits').move_cursor_down, { desc = 'Move cursor down' }) vim.keymap.set({ 'n', 't' }, '<C-j>', require('smart-splits').move_cursor_down, { desc = 'Move cursor down' })
vim.keymap.set('n', '<C-k>', require('smart-splits').move_cursor_up, { desc = 'Move cursor up' }) vim.keymap.set({ 'n', 't' }, '<C-k>', require('smart-splits').move_cursor_up, { desc = 'Move cursor up' })
vim.keymap.set('n', '<C-l>', require('smart-splits').move_cursor_right, { desc = 'Move cursor right' }) vim.keymap.set({ 'n', 't' }, '<C-l>', require('smart-splits').move_cursor_right, { desc = 'Move cursor right' })
vim.keymap.set('t', '<C-h>', require('smart-splits').move_cursor_left, { desc = 'Move cursor left' })
vim.keymap.set('t', '<C-j>', require('smart-splits').move_cursor_down, { desc = 'Move cursor down' })
vim.keymap.set('t', '<C-k>', require('smart-splits').move_cursor_up, { desc = 'Move cursor up' })
vim.keymap.set('t', '<C-l>', require('smart-splits').move_cursor_right, { desc = 'Move cursor right' })
-- swapping buffers between windows -- swapping buffers between windows
vim.keymap.set('n', '<leader><leader>h', require('smart-splits').swap_buf_left, { desc = 'Swap buffer left' }) vim.keymap.set('n', '<leader><leader>h', require('smart-splits').swap_buf_left, { desc = 'Swap buffer left' })
vim.keymap.set('n', '<leader><leader>j', require('smart-splits').swap_buf_down, { desc = 'Swap buffer down' }) vim.keymap.set('n', '<leader><leader>j', require('smart-splits').swap_buf_down, { desc = 'Swap buffer down' })
@ -779,6 +859,10 @@ vim.keymap.set('n', '<A-f>', ":Format<cr>", { desc = 'Format code', silent = tru
vim.keymap.set('n', '<leader>gg', ":LazyGitCurrentFile<cr>", { desc = 'Format code', silent = true }) vim.keymap.set('n', '<leader>gg', ":LazyGitCurrentFile<cr>", { desc = 'Format code', silent = true })
vim.keymap.set('n', '<C-m>', ":make<cr>", { desc = 'Format code', silent = true }) vim.keymap.set('n', '<C-m>', ":make<cr>", { desc = 'Format code', silent = true })
vim.keymap.set('n', '<C-n>', ":make clean<cr>", { desc = 'Format code', silent = true }) vim.keymap.set('n', '<C-n>', ":make clean<cr>", { desc = 'Format code', silent = true })
vim.keymap.set('n', '<C-s>', ":write<cr>", { desc = 'Save', silent = true })
vim.keymap.set('n', '<C-q>', ":quit<cr>", { desc = 'Quit', silent = true })
vim.keymap.set('n', '<leader>n', ":tabnew<cr>", { desc = 'Format code', silent = true }) vim.keymap.set('n', '<leader>n', ":tabnew<cr>", { desc = 'Format code', silent = true })
vim.keymap.set('n', '<leader>c', ":tabclose<cr>", { desc = 'Format code', silent = true }) vim.keymap.set('n', '<leader>c', ":tabclose<cr>", { desc = 'Format code', silent = true })
vim.keymap.set('n', '<leader>e', ":NeoTreeShowToggle<cr>", { desc = 'File explorer', silent = true }) vim.keymap.set('n', '<leader>e', ":NeoTreeShowToggle<cr>", { desc = 'File explorer', silent = true })
vim.keymap.set('n', 's', ":HopWord<cr>", { desc = 'hop', silent = true })
vim.keymap.set('n', '<leader>t', ":TroubleToggle<cr>", { desc = 'Trouble view', silent = true })