Files
nvim/init.lua
2026-03-30 07:01:38 -04:00

188 lines
5.4 KiB
Lua

vim.g.mapleader = " "
vim.g.maplocalleader = ","
vim.o.shiftwidth = 4
vim.o.tabstop = 4
vim.o.number = true
vim.o.mouse = "a"
vim.o.showmode = false
vim.schedule(function()
vim.o.clipboard = "unnamedplus"
end)
vim.o.breakindent = true
vim.o.undofile = true
vim.o.ignorecase = true
vim.o.smartcase = true
-- Adds extra space for git diff symbols and stuff
vim.o.signcolumn = "yes"
-- Decrease update time
vim.o.updatetime = 250
-- Decrease mapped sequence wait time
vim.o.timeoutlen = 300
-- Configure how new splits should be opened
vim.o.splitright = true
vim.o.splitbelow = true
vim.o.list = true
vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "" }
-- Preview substitutions live, as you type!
vim.o.inccommand = "split"
-- Show which line your cursor is on
vim.o.cursorline = true
-- Minimal number of screen lines to keep above and below the cursor.
vim.o.scrolloff = 3
-- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`),
-- instead raise a dialog asking if you wish to save the current file(s)
-- See `:help 'confirm'`
vim.o.confirm = true
vim.api.nvim_create_autocmd("TextYankPost", {
desc = "Highlight when yanking (copying) text",
group = vim.api.nvim_create_augroup("kickstart-highlight-yank", { clear = true }),
callback = function()
vim.hl.on_yank()
end,
})
-- Clear highlights on search when pressing <Esc> in normal mode
-- See `:help hlsearch`
vim.keymap.set("n", "<Esc>", "<cmd>nohlsearch<CR>")
-- Diagnostic Config & Keymaps
-- See :help vim.diagnostic.Opts
vim.diagnostic.config({
update_in_insert = false,
severity_sort = true,
float = { border = "rounded", source = "if_many" },
underline = { severity = { min = vim.diagnostic.severity.WARN } },
-- Can switch between these as you prefer
virtual_text = false, -- Text shows up at the end of the line
virtual_lines = true, -- Text shows up underneath the line, with virtual lines
-- Auto open the float, so you can easily read the errors when jumping with `[d` and `]d`
jump = { float = true },
})
vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" })
vim.keymap.set("n", "<leader>so", "<CMD>so<CR>")
vim.keymap.set("t", "<Esc><Esc>", "<C-\\><C-n>", { desc = "Exit terminal mode" })
vim.keymap.set("n", "K", function()
vim.lsp.buf.hover({ border = "rounded" })
end)
vim.lsp.enable({ "lua_ls", "dartls" })
local github = "https://github.com/"
vim.pack.add({
github .. "nvim-lua/plenary.nvim",
github .. "nvim-telescope/telescope-fzf-native.nvim",
github .. "nvim-telescope/telescope.nvim",
github .. "stevearc/oil.nvim",
github .. "neovim/nvim-lspconfig",
github .. "nvim-mini/mini.nvim",
github .. "lewis6991/gitsigns.nvim",
github .. "neogitorg/neogit",
github .. "stevearc/conform.nvim",
{ src = github .. "saghen/blink.cmp", version = vim.version.range("v1.*") },
github .. "tjdevries/colorbuddy.nvim",
github .. "hgranthorner/ghosttybuddy.nvim",
github .. "nvim-treesitter/nvim-treesitter",
})
-- Telescope
local builtin = require("telescope.builtin")
vim.keymap.set("n", "<leader>ff", builtin.find_files, { desc = "Telescope find files" })
vim.keymap.set("n", "<leader>fc", function()
builtin.find_files({ cwd = vim.fn.stdpath("config") })
end, { desc = "Telescope find config" })
vim.keymap.set("n", "<leader>fg", builtin.live_grep, { desc = "Telescope live grep" })
vim.keymap.set("n", "<leader>fb", builtin.buffers, { desc = "Telescope buffers" })
vim.keymap.set("n", "<leader>fh", builtin.help_tags, { desc = "Telescope help tags" })
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("telescope-lsp-attach", { clear = true }),
callback = function(event)
local buf = event.buf
vim.keymap.set("n", "gO", builtin.lsp_document_symbols, { buffer = buf, desc = "Open Document Symbols" })
vim.keymap.set(
"n",
"gW",
builtin.lsp_dynamic_workspace_symbols,
{ buffer = buf, desc = "Open Workspace Symbols" }
)
end,
})
-- Oil
require("oil").setup({
default_file_explorer = true,
columns = {
"icon",
},
})
vim.keymap.set("n", "<leader>rw", "<CMD>Oil<CR>", { desc = "Open file explorer" })
-- Mini
require("mini.move").setup()
require("mini.surround").setup()
require("mini.snippets").setup()
-- Neogit
vim.keymap.set("n", "<leader>gg", "<CMD>Neogit<CR>")
-- Conform
require("conform").setup({
formatters_by_ft = {
lua = { "stylua" },
dart = { "dart_format" },
-- Conform will run multiple formatters sequentially
python = { "ruff" },
-- You can customize some of the format options for the filetype (:help conform.format)
rust = { "rustfmt", lsp_format = "fallback" },
-- Conform will run the first available formatter
javascript = { "prettierd", "prettier", stop_after_first = true },
},
})
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*",
callback = function(args)
require("conform").format({ bufnr = args.buf })
end,
})
-- blink.cmp
require("blink.cmp").setup()
-- ghosttybuddy
vim.cmd.colorscheme("ghostty")
-- nvim-treesitter
local langs = { "rust", "javascript", "zig", "lua", "vim", "vimdoc" }
require("nvim-treesitter").install(langs)
vim.api.nvim_create_autocmd("FileType", {
pattern = langs,
callback = function()
-- syntax highlighting, provided by Neovim
vim.treesitter.start()
-- folds, provided by Neovim
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
vim.wo.foldmethod = "expr"
-- indentation, provided by nvim-treesitter
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end,
})