Improved neovim config

This commit is contained in:
2023-08-22 16:51:35 +02:00
parent ce110d730e
commit 3d3380b6b6
9 changed files with 129 additions and 20 deletions

View File

@ -15,6 +15,7 @@ on({ "TermOpen", "TermEnter" }, {
on({ "BufNewFile", "BufRead" }, {
pattern = { "*.txt", "*.md" },
callback = function()
vim.lo.wrap = true
vim.opt_local.wrap = true
vim.opt_local.signcolumn = "no"
end,
})

View File

@ -1,28 +1,31 @@
local map = function(mode, lhs, rhs, info)
local function map(mode, lhs, rhs, info)
vim.keymap.set(mode, lhs, rhs, { desc = info })
end
-- Basics
map("n", ";", ":", "Command mode")
map("n", "qq", "<cmd>qa!<cr>", "Quit all")
map("n", "U", "<cmd>redo<cr>", "Redo")
map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", "Clear search")
map({ "i", "n", "s", "v" }, "<C-s>", "<cmd>w<cr><esc>", "Save file")
map("n", "U", "<cmd>redo<cr>", "Redo")
map("n", "<C-q>", "<cmd>bd<cr>", "Delete buffer")
map("n", "<C-n>", "<cmd>enew<cr>", "New File")
map("n", "<C-l>", "^Da", "Rewrite line")
map("i", "<C-l>", "<esc>^Da", "Rewrite line")
map("n", "<C-r>", ":%s/<C-R><C-W>//g<Left><Left>", "Replace word under cursor")
map("n", "<C-q>", "<cmd>qa<cr>", "Quit all")
map({"n", "v"}, "<C-b>", "^", "Beginning of line")
map({ "n", "v" }, "<C-b>", "^", "Beginning of line")
map("i", "<C-b>", "<esc>^i", "Beginning of line")
map({"i", "n", "v"}, "<C-e>", "<end>", "End of line")
map({ "i", "n", "v" }, "<C-e>", "<end>", "End of line")
-- Indenting
map("v", "<", "<gv")
map("v", ">", ">gv")
-- LSP
map("n", "gd", vim.lsp.buf.definition, "Go to definition")
map("n", "gr", vim.lsp.buf.references, "Go to references")
map("n", "<leader>cf", vim.lsp.buf.format, "Format")
map("n", "gr", vim.lsp.buf.references, "Get references")
map("n", "gd", vim.lsp.buf.definition, "Get definition")
map({ "n", "i" }, "<f1>", vim.lsp.buf.hover, "Show information")
map({ "n", "i" }, "<C-f>", vim.lsp.buf.format, "Format")
-- Plugins
map("n", "<leader>t", "<cmd>NvimTreeToggle<cr>", "Toggle tree")
-- Package manager
map("n", "<leader>l", "<cmd>Lazy<cr>", "Lazy")

View File

@ -16,15 +16,15 @@ opt.cursorline = true
opt.cursorlineopt = "both"
opt.expandtab = false
opt.grepformat = "%f:%l:%c:%m"
opt.grepprg = "rg --vimgrep"
opt.grepprg = "rg --grep"
opt.ignorecase = false
opt.laststatus = 0
opt.mouse = "a"
opt.ruler = false
opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize" }
opt.shiftwidth = 4
opt.shortmess:append "sI"
opt.shortmess:append "sCFI"
opt.showmode = false
opt.showtabline = 0
opt.smartindent = true
opt.softtabstop = 4
opt.spell = false
@ -40,6 +40,8 @@ opt.wrap = false
-- UI
opt.fillchars = { eob = " ", vert = " " }
opt.laststatus = 0
opt.number = true
opt.relativenumber = false
opt.signcolumn = "yes:1"
opt.statusline = "%{repeat('─',winwidth('.'))}"

View File

@ -1,3 +1,46 @@
local icons = {
Namespace = "󰌗",
Text = "󰉿",
Method = "󰆧",
Function = "󰆧",
Constructor = "",
Field = "󰜢",
Variable = "󰀫",
Class = "󰠱",
Interface = "",
Module = "",
Property = "󰜢",
Unit = "󰑭",
Value = "󰎠",
Enum = "",
Keyword = "󰌋",
Snippet = "",
Color = "󰏘",
File = "󰈚",
Reference = "󰈇",
Folder = "󰉋",
EnumMember = "",
Constant = "󰏿",
Struct = "󰙅",
Event = "",
Operator = "󰆕",
TypeParameter = "󰊄",
Table = "",
Object = "󰅩",
Tag = "",
Array = "[]",
Boolean = "",
Number = "",
Null = "󰟢",
String = "󰉿",
Calendar = "",
Watch = "󰥔",
Package = "",
Copilot = "",
Codeium = "",
TabNine = "",
}
return {
"hrsh7th/nvim-cmp",
event = "InsertEnter",
@ -5,20 +48,52 @@ return {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"L3MON4D3/LuaSnip",
},
config = function()
local cmp = require("cmp")
cmp.setup({
local opts = {
completion = {
completeopt = "menu,menuone,noinsert",
},
formatting = {
fields = { "abbr", "kind", "menu" },
format = function(_, item)
local icon = icons[item.kind] or ""
item.kind = string.format(" %s %s", icon, item.kind)
return item
end,
},
mapping = {
["<C-space>"] = cmp.mapping.complete(),
["<C-up>"] = cmp.mapping.select_prev_item(),
["<C-down>"] = cmp.mapping.select_next_item(),
["<C-e>"] = cmp.mapping.abort(),
["<cr>"] = cmp.mapping.confirm({ select = true }),
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
},
})
window = {
completion = {
border = "rounded",
scrollbar = false
},
documentation = {
border = "rounded",
}
},
}
cmp.setup(opts)
end,
}

View File

@ -8,6 +8,7 @@ return {
{"<leader>f", "<cmd>Telescope find_files<cr>", desc = "Find files"},
{"<leader>r", "<cmd>Telescope oldfiles<cr>", desc = "Recent files"},
{"<leader>p", "<cmd>Telescope project<cr>", desc = "Projects"},
{"<leader>b", "<cmd>Telescope buffers<cr>", desc = "Buffers"},
},
config = function()
require("telescope").setup({

View File

@ -6,6 +6,10 @@ return {
style = "dark",
transparent = false,
term_colors = true,
highlights = {
["StatusLine"] = {fg = "$bg3", bg = "Normal"},
["StatusLineNC"] = {fg = "$bg3", bg = "Normal"},
},
},
config = function(_, opts)
local theme = require("onedark")

View File

@ -4,6 +4,9 @@ return {
dependencies = {
"nvim-tree/nvim-web-devicons",
},
keys = {
{ "<leader>e", function() require("nvim-tree.api").tree.toggle() end, desc = "Toggle files" },
},
opts = {
filesystem_watchers = {
enable = true,

View File

@ -0,0 +1,18 @@
return {
"folke/trouble.nvim",
event = "VeryLazy",
keys = {
{ "<leader>x", function() require("trouble").toggle() end, desc = "Show errors" },
},
dependencies = {
"nvim-tree/nvim-web-devicons",
},
opts = {
position = "right",
padding = false,
use_diagnostic_signs = true,
auto_open = true,
auto_close = true,
},
config = true,
}