Last active
January 2, 2025 19:34
-
-
Save SamuelDavis/f76f1bfda3ab264ccc788590d96e2fe7 to your computer and use it in GitHub Desktop.
Neovim Configuration File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------- | |
-- OPTIONS -- | |
------------- | |
vim.g.mapleader = "," | |
vim.g.maplocalleader = vim.g.mapleader | |
vim.g.have_nerd_font = false | |
vim.opt.number = true | |
vim.opt.mouse = "a" | |
vim.opt.showmode = false | |
vim.schedule(function() | |
vim.opt.clipboard = "unnamedplus" | |
end) | |
vim.opt.breakindent = true | |
vim.opt.undofile = true | |
vim.opt.ignorecase = true | |
vim.opt.smartcase = true | |
vim.opt.signcolumn = "yes" | |
vim.opt.updatetime = 250 | |
vim.opt.timeoutlen = 300 | |
vim.opt.splitright = true | |
vim.opt.splitbelow = true | |
vim.opt.list = true | |
vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" } | |
vim.opt.inccommand = "split" | |
vim.opt.cursorline = true | |
vim.opt.scrolloff = 10 | |
------------- | |
-- KEYMAPS -- | |
------------- | |
local function map(keys, fn, desc, opts, mode) | |
opts = opts or {} | |
opts.desc = desc | |
mode = mode or "n" | |
vim.keymap.set(mode, "<leader>" .. keys, fn, opts) | |
end | |
local function currymap(prefixed_keys, prefixed_desc) | |
return function(keys, fn, desc, opts, mode) | |
keys = prefixed_keys .. keys | |
desc = prefixed_desc .. " " .. desc | |
mode = mode or "n" | |
map(keys, fn, desc, opts) | |
end | |
end | |
local dmap = currymap("d", "[D]iagnostic") | |
local smap = currymap("s", "[S]earch") | |
local fmap = currymap("f", "[F]ind") | |
map("<Esc>", "<cmd>nohlsearch<CR>") | |
vim.keymap.set("t", "<Esc><Esc>", "<C-\\><C-n>", { desc = "Exit terminal mode" }) | |
dmap("o", vim.diagnostic.open_float, "[O]pen Float") | |
dmap("p", vim.diagnostic.get_prev, "[P]revious") | |
dmap("n", vim.diagnostic.get_next, "[N]ext") | |
dmap("l", vim.diagnostic.setloclist, "[L]ist") | |
------------- | |
-- PLUGINS -- | |
------------- | |
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" | |
if not (vim.uv or vim.loop).fs_stat(lazypath) then | |
local lazyrepo = "https://github.com/folke/lazy.nvim.git" | |
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) | |
if vim.v.shell_error ~= 0 then | |
error("Error cloning lazy.nvim:\n" .. out) | |
end | |
end ---@diagnostic disable-next-line: undefined-field | |
vim.opt.rtp:prepend(lazypath) | |
require("lazy").setup({ | |
"tpope/vim-sleuth", | |
{ | |
"lewis6991/gitsigns.nvim", | |
opts = { | |
signs = { | |
add = { text = "+" }, | |
change = { text = "~" }, | |
delete = { text = "_" }, | |
topdelete = { text = "‾" }, | |
changedelete = { text = "~" }, | |
}, | |
}, | |
}, | |
{ | |
"folke/which-key.nvim", | |
event = "VimEnter", | |
opts = { | |
icons = { | |
mappings = vim.g.have_nerd_font, | |
keys = vim.g.have_nerd_font and {} or { | |
Up = "<Up> ", | |
Down = "<Down> ", | |
Left = "<Left> ", | |
Right = "<Right> ", | |
C = "<C-…> ", | |
M = "<M-…> ", | |
D = "<D-…> ", | |
S = "<S-…> ", | |
CR = "<CR> ", | |
Esc = "<Esc> ", | |
ScrollWheelDown = "<ScrollWheelDown> ", | |
ScrollWheelUp = "<ScrollWheelUp> ", | |
NL = "<NL> ", | |
BS = "<BS> ", | |
Space = "<Space> ", | |
Tab = "<Tab> ", | |
F1 = "<F1>", | |
F2 = "<F2>", | |
F3 = "<F3>", | |
F4 = "<F4>", | |
F5 = "<F5>", | |
F6 = "<F6>", | |
F7 = "<F7>", | |
F8 = "<F8>", | |
F9 = "<F9>", | |
F10 = "<F10>", | |
F11 = "<F11>", | |
F12 = "<F12>", | |
}, | |
}, | |
spec = { | |
{ "<leader>c", group = "[C]ode", mode = { "n", "x" } }, | |
{ "<leader>d", group = "[D]ocument" }, | |
{ "<leader>r", group = "[R]ename" }, | |
{ "<leader>s", group = "[S]earch" }, | |
{ "<leader>w", group = "[W]orkspace" }, | |
{ "<leader>t", group = "[T]oggle" }, | |
{ "<leader>h", group = "Git [H]unk", mode = { "n", "v" } }, | |
}, | |
}, | |
}, | |
{ | |
"nvim-telescope/telescope.nvim", | |
event = "VimEnter", | |
branch = "0.1.x", | |
dependencies = { | |
"nvim-lua/plenary.nvim", | |
"nvim-telescope/telescope-ui-select.nvim", | |
{ | |
"nvim-telescope/telescope-fzf-native.nvim", | |
build = "make", | |
cond = function() | |
return vim.fn.executable("make") == 1 | |
end, | |
}, | |
{ "nvim-tree/nvim-web-devicons", enabled = vim.g.have_nerd_font }, | |
}, | |
config = function() | |
require("telescope").setup({ | |
defaults = { | |
file_ignore_patterns = { | |
"venv", | |
"__pycache__", | |
"node_modules", | |
"vendor", | |
}, | |
}, | |
extensions = { | |
["ui-select"] = { | |
require("telescope.themes").get_dropdown(), | |
}, | |
}, | |
}) | |
pcall(require("telescope").load_extension, "fzf") | |
pcall(require("telescope").load_extension, "ui-select") | |
local builtin = require("telescope.builtin") | |
local function current_file() | |
builtin.current_buffer_fuzzy_find(require("telescope.themes").get_dropdown({ | |
winblend = 10, | |
previewer = false, | |
})) | |
end | |
local function open_files() | |
builtin.live_grep({ | |
grep_open_files = true, | |
prompt_title = "Live Grep in Open Files", | |
}) | |
end | |
smap("h", builtin.help_tags, "[H]elp") | |
smap("k", builtin.keymaps, "[K]eymaps") | |
smap("f", builtin.find_files, "[F]iles") | |
smap("t", builtin.builtin, "[T]elescope") | |
smap("g", builtin.grep_string, "[G]rep") | |
smap("d", builtin.diagnostics, "[D]iagnostics") | |
smap("r", builtin.resume, "[R]esume") | |
smap("b", builtin.buffers, "[B]uffers") | |
smap("o", builtin.oldfiles, "[O]ld Files") | |
smap(".", current_file, "[.] Current File") | |
smap("..", open_files, "[..] Open Files") | |
end, | |
}, | |
{ | |
"folke/lazydev.nvim", | |
ft = "lua", | |
opts = { | |
library = { | |
{ path = "luvit-meta/library", words = { "vim%.uv" } }, | |
}, | |
}, | |
}, | |
{ "Bilal2453/luvit-meta", lazy = true }, | |
{ | |
"neovim/nvim-lspconfig", | |
dependencies = { | |
{ "williamboman/mason.nvim", config = true }, | |
"williamboman/mason-lspconfig.nvim", | |
"WhoIsSethDaniel/mason-tool-installer.nvim", | |
{ "j-hui/fidget.nvim", opts = {} }, | |
"hrsh7th/cmp-nvim-lsp", | |
}, | |
config = function() | |
local group = vim.api.nvim_create_augroup("kickstart-lsp-attach", { clear = true }) | |
vim.api.nvim_create_autocmd("LspAttach", { | |
group = group, | |
callback = function(event) | |
local builtin = require("telescope.builtin") | |
fmap("d", builtin.lsp_definitions, "[D]efinition") | |
fmap("r", builtin.lsp_references, "[R]eferences") | |
fmap("I", builtin.lsp_implementations, "[I]mplementations") | |
fmap("T", builtin.lsp_type_definitions, "[T]ype definitions") | |
fmap("s", builtin.lsp_dynamic_workspace_symbols, "[S]ymbols (Workspace)") | |
fmap("sd", builtin.lsp_document_symbols, "[S]ymbols ([D]ocument)") | |
fmap("D", vim.lsp.buf.declaration, "[D]eclaration") | |
map("rn", vim.lsp.buf.rename, "[R]e[N]ame") | |
map("ca", vim.lsp.buf.code_action, "[C]ode [A]ction", {}, { "n", "x" }) | |
map("hd", vim.lsp.buf.hover, "[H]over [D]ocumentation") | |
local client = vim.lsp.get_client_by_id(event.data.client_id) | |
if client and client.config.root_dir then | |
vim.cmd("cd " .. client.config.root_dir) | |
end | |
if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then | |
local highlight_augroup = | |
vim.api.nvim_create_augroup("kickstart-lsp-highlight", { clear = false }) | |
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { | |
buffer = event.buf, | |
group = highlight_augroup, | |
callback = vim.lsp.buf.document_highlight, | |
}) | |
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { | |
buffer = event.buf, | |
group = highlight_augroup, | |
callback = vim.lsp.buf.clear_references, | |
}) | |
vim.api.nvim_create_autocmd("LspDetach", { | |
group = vim.api.nvim_create_augroup("kickstart-lsp-detach", { clear = true }), | |
callback = function(event2) | |
vim.lsp.buf.clear_references() | |
vim.api.nvim_clear_autocmds({ | |
group = "kickstart-lsp-highlight", | |
buffer = event2.buf, | |
}) | |
end, | |
}) | |
end | |
if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then | |
map("th", function() | |
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf })) | |
end, "[T]oggle Inlay [H]ints") | |
end | |
end, | |
}) | |
local lspconfig = require("lspconfig") | |
local capabilities = vim.lsp.protocol.make_client_capabilities() | |
capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities()) | |
lspconfig.gdscript.setup({ | |
capabilities = capabilities, | |
root_dir = function() | |
local results = vim.fs.find({ "project.godot", ".git" }, { upward = true }) | |
local root = vim.fs.dirname(results[1]) | |
return root | |
end, | |
}) | |
local servers = { | |
lua_ls = { | |
settings = { | |
Lua = { | |
completion = { | |
callSnippet = "Replace", | |
}, | |
}, | |
}, | |
}, | |
bashls = {}, | |
} | |
require("mason").setup() | |
local ensure_installed = vim.tbl_keys(servers or {}) | |
vim.list_extend(ensure_installed, { | |
"stylua", | |
}) | |
require("mason-tool-installer").setup({ ensure_installed = ensure_installed }) | |
--- @diagnostic disable-next-line: missing-fields | |
require("mason-lspconfig").setup({ | |
handlers = { | |
function(server_name) | |
local server = servers[server_name] or {} | |
server.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {}) | |
lspconfig[server_name].setup(server) | |
end, | |
}, | |
}) | |
end, | |
}, | |
{ | |
"stevearc/conform.nvim", | |
event = { "BufWritePre" }, | |
cmd = { "ConformInfo" }, | |
keys = { | |
{ | |
"<leader>f", | |
function() | |
require("conform").format({ async = true, lsp_format = "fallback" }) | |
end, | |
mode = "", | |
desc = "[F]ormat buffer", | |
}, | |
}, | |
opts = { | |
notify_on_error = false, | |
format_on_save = function(bufnr) | |
local disable_filetypes = { c = true, cpp = true } | |
local lsp_format_opt | |
if disable_filetypes[vim.bo[bufnr].filetype] then | |
lsp_format_opt = "never" | |
else | |
lsp_format_opt = "fallback" | |
end | |
return { | |
timeout_ms = 500, | |
lsp_format = lsp_format_opt, | |
} | |
end, | |
formatters_by_ft = { | |
lua = { "stylua" }, | |
javascript = { "prettierd" }, | |
javascriptreact = { "prettierd" }, | |
typescript = { "prettierd" }, | |
typescriptreact = { "prettierd" }, | |
html = { "prettierd" }, | |
css = { "prettierd" }, | |
json = { "prettierd" }, | |
python = { "isort", "black" }, | |
gdscript = { "gdformat" }, | |
}, | |
formatters = { | |
gdformat = { | |
command = "gdformat", | |
args = { "$FILENAME" }, | |
stdin = false, | |
}, | |
}, | |
}, | |
}, | |
{ | |
"hrsh7th/nvim-cmp", | |
event = "InsertEnter", | |
dependencies = { | |
{ | |
"L3MON4D3/LuaSnip", | |
build = (function() | |
if vim.fn.has("win32") == 1 or vim.fn.executable("make") == 0 then | |
return | |
end | |
return "make install_jsregexp" | |
end)(), | |
dependencies = {}, | |
}, | |
"saadparwaiz1/cmp_luasnip", | |
"hrsh7th/cmp-nvim-lsp", | |
"hrsh7th/cmp-path", | |
}, | |
config = function() | |
local cmp = require("cmp") | |
local luasnip = require("luasnip") | |
luasnip.config.setup({}) | |
luasnip.add_snippets("html", { | |
luasnip.snippet("favicon", { | |
luasnip.text_node('<link rel="icon" href="data:;base64,iVBORw0KGgo=">'), | |
}), | |
}) | |
cmp.setup({ | |
snippet = { | |
expand = function(args) | |
luasnip.lsp_expand(args.body) | |
end, | |
}, | |
completion = { completeopt = "menu,menuone,noinsert" }, | |
mapping = cmp.mapping.preset.insert({ | |
["<C-n>"] = cmp.mapping.select_next_item(), | |
["<C-p>"] = cmp.mapping.select_prev_item(), | |
["<C-b>"] = cmp.mapping.scroll_docs(-4), | |
["<C-f>"] = cmp.mapping.scroll_docs(4), | |
["<CR>"] = cmp.mapping.confirm({ select = true }), | |
["<C-Space>"] = cmp.mapping.complete({}), | |
["<Tab>"] = cmp.mapping(function(fallback) | |
if cmp.visible() then | |
local entry = cmp.get_selected_entry() | |
if not entry then | |
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) | |
end | |
cmp.confirm() | |
else | |
fallback() | |
end | |
end, { "i", "s", "c" }), | |
["<C-l>"] = cmp.mapping(function() | |
if luasnip.expand_or_locally_jumpable() then | |
luasnip.expand_or_jump() | |
end | |
end, { "i", "s" }), | |
["<C-h>"] = cmp.mapping(function() | |
if luasnip.locally_jumpable(-1) then | |
luasnip.jump(-1) | |
end | |
end, { "i", "s" }), | |
}), | |
sources = { | |
{ | |
name = "lazydev", | |
group_index = 0, | |
}, | |
{ name = "nvim_lsp" }, | |
{ name = "luasnip" }, | |
{ name = "path" }, | |
}, | |
}) | |
end, | |
}, | |
{ | |
"navarasu/onedark.nvim", | |
priority = 1000, | |
init = function() | |
vim.cmd.colorscheme("onedark") | |
vim.cmd.hi("Comment gui=none") | |
end, | |
}, | |
{ | |
"folke/todo-comments.nvim", | |
event = "VimEnter", | |
dependencies = { "nvim-lua/plenary.nvim" }, | |
opts = { signs = false }, | |
}, | |
{ | |
"echasnovski/mini.nvim", | |
config = function() | |
require("mini.ai").setup({ n_lines = 500 }) | |
require("mini.surround").setup() | |
local statusline = require("mini.statusline") | |
statusline.setup({ use_icons = vim.g.have_nerd_font }) | |
---@diagnostic disable-next-line: duplicate-set-field | |
statusline.section_location = function() | |
return "%2l:%-2v" | |
end | |
end, | |
}, | |
{ | |
"nvim-treesitter/nvim-treesitter", | |
build = ":TSUpdate", | |
main = "nvim-treesitter.configs", | |
opts = { | |
ensure_installed = { | |
"bash", | |
"c", | |
"diff", | |
"html", | |
"lua", | |
"luadoc", | |
"markdown", | |
"markdown_inline", | |
"query", | |
"vim", | |
"vimdoc", | |
}, | |
auto_install = true, | |
highlight = { | |
enable = true, | |
additional_vim_regex_highlighting = { "ruby" }, | |
}, | |
indent = { enable = true, disable = { "ruby" } }, | |
}, | |
}, | |
}) | |
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.highlight.on_yank() | |
end, | |
}) | |
vim.api.nvim_create_autocmd({ "BufLeave", "VimLeave", "FocusLost" }, { | |
callback = function() | |
if vim.bo.modified and not vim.bo.readonly then | |
vim.cmd("silent! write") | |
end | |
end, | |
}) | |
vim.api.nvim_create_autocmd({ "VimEnter" }, { | |
callback = function() | |
local file_dir = vim.fn.expand("%:p:h") | |
if vim.fn.isdirectory(file_dir) == 1 then | |
vim.cmd("cd " .. file_dir) | |
end | |
end, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment