Files
dotfiles/neovim/.config/nvim/init.lua
2026-04-08 19:17:07 +02:00

270 lines
6.4 KiB
Lua

-- Abbreviations
local opt = vim.opt
local map = vim.keymap.set
local cmd = vim.cmd
-- [[ OPTIONS ]] --
-- Line numbers
opt.number = true
opt.relativenumber = true
-- Status line
opt.statusline = "[%n] %<%f %h%w%m%r%=%-14.(%l,%c%V%) %P"
-- Block cursor
opt.guicursor = ""
-- Highlight cursor line
opt.cursorline = true
-- Set termguicolors
opt.termguicolors = true
-- File options
opt.undofile = true
opt.undodir = os.getenv("HOME") .. "/.vim/nvim_undodir"
opt.swapfile = false
opt.backup = false
opt.fixendofline = false
-- Tabs
opt.tabstop = 4
opt.softtabstop = 4
opt.shiftwidth = 4
opt.expandtab = true
opt.breakindent = true
-- Search
opt.ignorecase = true
opt.smartcase = true
opt.incsearch = true
map("n", "<ESC>", "<cmd>nohlsearch<CR>")
-- Columns
opt.signcolumn = "yes"
-- opt.textwidth = 78 -- RFC 5322
opt.colorcolumn = "79"
-- Auto complete
opt.completeopt = { "menuone", "popup" --[[, "noselect" ]] }
-- Window border
opt.winborder = "rounded"
-- [[ KEYMAPS ]] --
-- Leader key
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- Clipboard
map({ "n", "v" }, "<leader>y", "\"+y")
-- Deletions
map({ "n", "v" }, "<leader>d", "\"_d")
map("n", "<leader>md", ":delmarks!<CR>")
-- Commands
map("n", "<leader>x", ":!chmod +x %<CR>")
map("n", "<leader>cd", ":cd %:h | pwd<CR>")
-- Tabs
map("n", "<leader>tt", ":tabnew<CR>")
map("n", "<leader>tw", ":tabclose<CR>")
map("n", "<leader>tn", ":tabnext<CR>")
map("n", "<leader>tp", ":tabprevious<CR>")
map("n", "<leader>tf", ":tabfirst<CR>")
map("n", "<leader>tl", ":tablast<CR>")
-- Buffers
map("n", "<leader>n", ":enew<CR>")
map("n", "<leader>db", ":bdelete<CR>")
map("n", "<TAB>", ":bnext<CR>")
map("n", "<S-TAB>", ":bprevious<CR>")
map("n", "<leader>\\", ":buffer term<CR>")
map("t", "<ESC>", "<C-\\><C-n>")
-- Indentation in visual mode
map("v", "<", "<gv")
map("v", ">", ">gv")
-- Move text in visual mode
map("v", "J", ":move '>+1<CR>gv=gv")
map("v", "K", ":move '<-2<CR>gv=gv")
-- Run last command in terminal
map("n", "<leader>r", ":buffer term<CR>i<Up><CR><C-\\><C-n>")
-- Window movement
map("n", "<M-h>", "<C-w>h")
map("n", "<M-j>", "<C-w>j")
map("n", "<M-k>", "<C-w>k")
map("n", "<M-l>", "<C-w>l")
map("t", "<M-h>", "<cmd>wincmd h<CR>")
map("t", "<M-j>", "<cmd>wincmd j<CR>")
map("t", "<M-k>", "<cmd>wincmd k<CR>")
map("t", "<M-l>", "<cmd>wincmd l<CR>")
-- Window resizing
map("n", "<M-Up>", "<cmd>resize -2<CR>")
map("n", "<M-Down>", "<cmd>resize +2<CR>")
map("n", "<M-Left>", "<cmd>vertical resize -2<CR>")
map("n", "<M-Right>", "<cmd>vertical resize +2<CR>")
-- Listchars
opt.listchars = {
-- eol = "$",
tab = "» ",
space = "·",
trail = "-"
}
-- Toggle listchars
map("n", "<leader>lc", function()
vim.wo.list = not vim.wo.list
end)
-- [[ AUTOCMDS ]] --
-- Highlight copied text
vim.api.nvim_create_autocmd("TextYankPost", {
callback = function() vim.highlight.on_yank() end
})
-- Disable LSP syntax highlight
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("my.lsp", {}),
callback = function(ev)
local client = assert(vim.lsp.get_client_by_id(ev.data.client_id))
client.server_capabilities.semanticTokensProvider = nil
end
})
-- [[ PLUGINS ]] --
-- Install plugins
vim.pack.add({
-- Colorscheme
"https://github.com/habamax/vim-gruvbit",
-- Background trasparency
"https://github.com/xiyaowong/transparent.nvim",
-- Fuzzy finder
"https://github.com/echasnovski/mini.pick",
-- Git integration
"https://github.com/tpope/vim-fugitive",
"https://github.com/lewis6991/gitsigns.nvim",
-- Text aligning
{ src = "https://github.com/Vonr/align.nvim", version = "v2" },
-- Multi cursor
"https://github.com/brenton-leighton/multiple-cursors.nvim",
-- Trailing whitespace
"https://github.com/kaplanz/retrail.nvim",
-- Indent blankline
"https://github.com/lukas-reineke/indent-blankline.nvim",
-- File tree
{ src = "https://github.com/nvim-neo-tree/neo-tree.nvim", version = vim.version.range("3") },
"https://github.com/nvim-lua/plenary.nvim",
"https://github.com/MunifTanjim/nui.nvim",
"https://github.com/nvim-tree/nvim-web-devicons",
-- LSP
"https://github.com/neovim/nvim-lspconfig",
"https://github.com/mason-org/mason.nvim",
"https://github.com/mason-org/mason-lspconfig.nvim",
-- Autocompletion
{ src = "https://github.com/saghen/blink.cmp", version = "v1" }
})
vim.cmd.packadd("nvim.undotree")
vim.cmd.packadd("nvim.difftool")
-- [[ PLUGINS CONFIGURATIONS ]] --
cmd.colorscheme("gruvbit")
require("mini.pick").setup()
require("multiple-cursors").setup()
require("retrail").setup({
hlgroup = "Error",
trim = {
auto = false, -- Auto trim on BufWritePre
}
})
require("ibl").setup()
require("neo-tree").setup({
window = {
width = 32
}
})
require("mason").setup()
require("mason-lspconfig").setup()
vim.lsp.config("lua_ls", {
settings = {
Lua = {
runtime = {
version = "LuaJIT",
},
diagnostics = {
globals = {
"vim",
"require"
},
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
},
telemetry = {
enable = false,
}
}
}
})
require("blink.cmp").setup({
fuzzy = { implementation = "lua" }
})
-- [[ PLUGIN KEYMAPS ]] --
map("n", "<leader>f", ":Pick files<CR>")
map("n", "<leader>b", ":Pick buffers<CR>")
map("n", "<leader>u", ":Undotree<CR>")
map("n", "<leader>gs", ":Git<CR>")
map("n", "<leader>gt", ":Gitsigns toggle_signs<CR>")
map("n", "<leader>gp", ":Gitsigns preview_hunk<CR>")
map("n", "<leader>gb", ":Gitsigns toggle_current_line_blame<CR>")
map("x", "<leader>al", function()
require("align").align_to_string({ preview = true, regex = true })
end)
map({ "n", "x" }, "<C-j>", "<cmd>MultipleCursorsAddDown<CR>")
map({ "n", "x" }, "<C-k>", "<cmd>MultipleCursorsAddUp<CR>")
map({ "n", "i", "x" }, "<C-Up>", "<cmd>MultipleCursorsAddUp<CR>")
map({ "n", "i", "x" }, "<C-Down>", "<cmd>MultipleCursorsAddDown<CR>")
map({ "n", "i" }, "<C-LeftMouse>", "<cmd>MultipleCursorsMouseAddDelete<CR>")
map({ "n", "v", "x" }, "<C-l>", "<cmd>MultipleCursorsAddJumpNextMatch<CR>")
map({ "n", "x" }, "<leader>D", "<cmd>MultipleCursorsJumpNextMatch<CR>")
map("n", "<leader>|", function()
require("multiple-cursors").align()
end)
map("n", "<leader>p", "<cmd>Neotree toggle<CR>")
map("n", "grd", vim.diagnostic.open_float)