Updated config

This commit is contained in:
Eduard Urbach 2025-05-28 16:39:25 +02:00
parent 8fcda55cbd
commit 0943589dd7
Signed by: eduard
GPG key ID: 49226B848C78F6C8
21 changed files with 155 additions and 199 deletions

View file

@ -1,6 +1,6 @@
require("boot")
require("settings")
require("lsp")
require("keys")
require("autocmds")
require("usercmds")
require("events")
require("commands")
require("languages")

View file

@ -1,5 +1,5 @@
return {
cmd = { "clangd", "--background-index" },
root_markers = { "meson_options.txt", "CMakePresets.json" },
root_markers = { "meson_options.txt", "CMakePresets.json", "compile_commands.json" },
filetypes = { "c", "cpp" },
}

View file

@ -13,34 +13,19 @@ end
-- Disable plugins
local disabled_plugins = {
"2html_plugin",
"tohtml",
"getscript",
"getscriptPlugin",
"gzip",
"logipat",
"netrw",
"netrwPlugin",
"netrwSettings",
"netrwFileHandlers",
"matchit",
"tar",
"tarPlugin",
"rrhelper",
"spellfile_plugin",
"vimball",
"vimballPlugin",
"zip",
"zipPlugin",
"tutor",
"rplugin",
"syntax",
"synmenu",
"optwin",
"compiler",
"bugreport",
"ftplugin",
"gzip",
"man",
"netrw",
"matchit",
"remote_plugins",
"spellfile_plugin",
"shada_plugin",
"tarPlugin",
"tutor_mode_plugin",
"zipPlugin",
}
for _, plugin in ipairs(disabled_plugins) do
vim.g["loaded_" .. plugin] = 1
vim.g["loaded_" .. plugin] = 0
end

View file

@ -11,6 +11,7 @@ vim.api.nvim_create_user_command("ToggleWord", function()
["yes"] = "no",
["Yes"] = "No",
["YES"] = "NO",
["y"] = "n",
["1"] = "0",
["<"] = ">",
["("] = ")",

View file

@ -1,35 +1,18 @@
local on = vim.api.nvim_create_autocmd
local group = vim.api.nvim_create_augroup("autocmds", {clear = true})
on({ "BufNewFile", "BufRead" }, {
desc = "Enable word wrap in text files and markdown documents",
group = group,
pattern = { "*.txt", "*.md" },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.signcolumn = "no"
end,
})
on({ "LspAttach" }, {
desc = "LSP completion",
group = group,
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if client:supports_method("textDocument/completion") then
vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true })
end
end,
})
on({ "TermOpen", "TermEnter" }, {
desc = "Disable sign column in terminals",
group = group,
callback = function()
vim.opt_local.signcolumn = "no"
end,
})
on({ "TextYankPost" }, {
desc = "Highlight when copying text",
group = group,
@ -38,33 +21,20 @@ on({ "TextYankPost" }, {
end,
})
on({ "VimEnter" }, {
desc = "Allow opening a directory and jumping to project root",
on({ "BufNewFile", "BufRead" }, {
desc = "Enable word wrap in text files and markdown documents",
group = group,
pattern = { "*.txt", "*.md" },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.signcolumn = "no"
end,
})
on({ "TermOpen", "TermEnter" }, {
desc = "Disable sign column in terminals",
group = group,
callback = function()
-- Change file to its directory if needed
local name = vim.api.nvim_buf_get_name(0)
local is_directory = vim.fn.isdirectory(name)
if is_directory == 0 then
name = vim.fs.dirname(name)
end
-- Switch to root directory of the project
local root_patterns = { ".git", "go.mod", "init.lua" }
local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, {
upward = true,
path = name,
})[1])
if root_dir then
vim.api.nvim_set_current_dir(root_dir)
else
vim.api.nvim_set_current_dir(name)
end
if is_directory ~= 0 then
--require("telescope.builtin").find_files()
end
vim.opt_local.signcolumn = "no"
end,
})

View file

@ -4,41 +4,37 @@ local function map(mode, lhs, rhs, info)
vim.keymap.set(mode, lhs, rhs, { desc = info })
end
-- Enter command mode without pressing shift
map("n", ";", ":", "Command mode")
-- Undo with u, Redo with U
map("n", "U", "<cmd>redo<cr>", "Redo")
map("n", "<Bslash>", "<cmd>ToggleWord<cr>", "Toggle word")
map("n", "<C-q>", "<cmd>close<cr>", "Close window")
-- Quit with q like any other terminal app
map({"n", "v"}, "q", "<cmd>qa<cr>", "Quit all")
map({"n", "v"}, "<leader>q", "<cmd>qa!<cr>", "Quit all")
map({"n", "v"}, "Q", "<cmd>qa!<cr>", "Force quit")
-- Clear search with Esc
map({"n", "i"}, "<esc>", "<cmd>noh<cr><esc>", "Clear search")
-- Ctrl S to save the file from any mode
map({"n", "i", "s", "v"}, "<C-s>", "<cmd>w<cr><esc>", "Save file")
-- Add or delete empty lines
-- Grab the line and move it up/down
map("n", "<C-j>", "<cmd>set paste<cr>m`O<esc>``<cmd>set nopaste<cr>", "Add empty line above")
map("n", "<C-k>", "m`<cmd>-g/\\m^\\s*$/d<cr>``<cmd>noh<cr>", "Delete empty line above")
-- Grab the line below and move it up/down
map("n", "<A-j>", "<cmd>set paste<cr>m`o<esc>``<cmd>set nopaste<cr>", "Add empty line below")
map("n", "<A-k>", "m`<cmd>+g/\\m^\\s*$/d<cr>``<cmd>noh<cr>", "Delete empty line below")
-- Quick movement
map("n", "J", "}", "Next paragraph")
map("n", "K", "{", "Previous paragraph")
-- Horizontal movement
map({"n", "v"}, "H", "^", "Beginning of line")
map({"n", "v"}, "L", "<end>", "End of line")
-- Editing multiple instances
map("n", "<f2>", "*#:%s//<C-r><C-w>/g<left><left>", "Replace word under cursor")
map("v", "<f2>", "y/<C-r>\"<cr>N:%s//<C-r>\"/g<left><left>", "Replace selection")
map("n", "<f3>", "#*", "Search word under cursor")
map("v", "<f3>", "y/<C-r>\"<cr>N", "Search selection")
-- Line movement
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")
-- Increasing and decreasing numbers
map("n", "+", "<C-a>", "Increase number")
map("n", "-", "<C-x>", "Decrease number")
map("n", "<kPlus>", "<C-a>", "Increase number")
map("n", "<kMinus>", "<C-x>", "Decrease number")
-- Vertical movement
map({"n", "v"}, "J", "}", "Next paragraph")
map({"n", "v"}, "K", "{", "Previous paragraph")
-- Indenting
map("n", "<Tab>", "V>gv<esc>")
@ -46,24 +42,26 @@ map("n", "<S-Tab>", "V<gv<esc>")
map("v", "<Tab>", ">gv")
map("v", "<S-Tab>", "<gv")
-- Shift arrow selection
map("n", "<S-Up>", "v<Up>")
map("n", "<S-Down>", "v<Down>")
map("n", "<S-Left>", "v<Left>")
map("n", "<S-Right>", "v<Right>")
-- Toggle word
map("n", "<Bslash>", "<cmd>ToggleWord<cr>", "Toggle word")
map("v", "<S-Up>", "<Up>")
map("v", "<S-Down>", "<Down>")
map("v", "<S-Left>", "<Left>")
map("v", "<S-Right>", "<Right>")
-- Increasing and decreasing numbers
map("n", "+", "<C-a>", "Increase number")
map("n", "-", "<C-x>", "Decrease number")
map("n", "<kPlus>", "<C-a>", "Increase number")
map("n", "<kMinus>", "<C-x>", "Decrease number")
map("i", "<S-Up>", "<Esc>v<Up>")
map("i", "<S-Down>", "<Esc>v<Down>")
map("i", "<S-Left>", "<Esc>v<Left>")
map("i", "<S-Right>", "<Esc>v<Right>")
-- Replace all instances
map("n", "<f2>", "*#:%s//<C-r><C-w>/g<left><left>", "Replace word under cursor")
map("v", "<f2>", "y/<C-r>\"<cr>N:%s//<C-r>\"/g<left><left>", "Replace selection")
-- Window switching
-- Search all instances
map("n", "<f3>", "#*", "Search word under cursor")
map("v", "<f3>", "y/<C-r>\"<cr>N", "Search selection")
-- Window management
map("n", "<A-Up>", "<C-w>k", "Move to the window above")
map("n", "<A-Down>", "<C-w>j", "Move to the window below")
map("n", "<A-Left>", "<C-w>h", "Move to the window on the left")
map("n", "<A-Right>", "<C-w>l", "Move to the window on the right")
map("n", "<A-Right>", "<C-w>l", "Move to the window on the right")
map("n", "<A-q>", "<cmd>close<cr>", "Close window")

View file

@ -1,7 +1,9 @@
-- Virtual text
vim.diagnostic.config({
virtual_lines = true,
})
-- LSP
vim.lsp.enable({
"clangd",
"gopls",

View file

@ -43,8 +43,4 @@ opt.statusline = "%{repeat('─',winwidth('.'))}"
-- Undo
opt.undofile = true
opt.undolevels = 10000
-- Virtual text
vim.diagnostic.config({ virtual_lines = true })
vim.lsp.enable({"clangd", "gopls", "rust-analyzer"})
opt.undolevels = 10000