Something went wrong. Try again.
My neovim config
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526local vim = vim
-- ------------------------------------------------------------------------------- Helpers and shared config-- -----------------------------------------------------------------------------local function gh(repo) return "https://github.com/" .. repoend
local ensure_installed = { lsp = { "lua_ls", "emmet_ls", "tailwindcss", "cssls", "ols", "vtsls", "denols" }, treesitter = { "lua", "typescript", "javascript", "tsx", "html", "css", "svelte" },}
local function map(mode, lhs, rhs, desc, opts) local keymap_opts = vim.tbl_extend("force", opts or {}, { desc = desc }) vim.keymap.set(mode, lhs, rhs, keymap_opts)end
vim.api.nvim_create_user_command("LspStatus", function() local clients = vim.lsp.get_clients() if #clients == 0 then vim.notify("No active LSP clients", vim.log.levels.INFO) return end
local lines = { "Active LSP clients:" } for _, client in ipairs(clients) do local buffers = {} for bufnr in pairs(client.attached_buffers or {}) do local name = vim.api.nvim_buf_get_name(bufnr) table.insert( buffers, name == "" and "[No Name]" or vim.fn.fnamemodify(name, ":~:.") .. " (" .. bufnr .. ")" ) end table.sort(buffers) table.insert( lines, string.format( "- %s | root: %s | buffers: %s", client.name, client.root_dir or "?", table.concat(buffers, ", ") ) ) end vim.notify(table.concat(lines, "\n"), vim.log.levels.INFO)end, { desc = "Show active LSP clients and attached buffers" })
-- ------------------------------------------------------------------------------- Plugins-- -----------------------------------------------------------------------------vim.pack.add({ { src = gh("stevearc/oil.nvim") }, { src = gh("nvim-mini/mini.icons") }, -- { src = gh("nvim-mini/mini.pick" },
{ src = gh("nvim-telescope/telescope.nvim"), version = "master" }, { src = gh("nvim-telescope/telescope-fzf-native.nvim"), build = "make" }, { src = gh("kyazdani42/nvim-web-devicons") },
{ src = gh("lewis6991/gitsigns.nvim") }, { src = gh("j-hui/fidget.nvim") }, -- { src = gh("nvim-treesitter/nvim-treesitter"), version = "main" }, { src = "https://github.com/romus204/tree-sitter-manager.nvim" },
{ src = gh("saghen/blink.cmp"), version = "v1.9.1" }, { src = gh("rafamadriz/friendly-snippets") }, { src = gh("nvim-lualine/lualine.nvim") },
{ src = gh("smoka7/hop.nvim") }, { src = gh("folke/trouble.nvim") }, { src = gh("folke/twilight.nvim") }, { src = gh("folke/which-key.nvim") }, { src = gh("folke/todo-comments.nvim") },
-- themes { src = gh("vague-theme/vague.nvim") }, { src = gh("AlexvZyl/nordic.nvim") }, { src = gh("IroncladDev/osmium") }, { src = gh("serhez/teide.nvim") }, { src = gh("sainnhe/everforest") }, { src = gh("catppuccin/nvim") }, { src = gh("ellisonleao/gruvbox.nvim") }, { src = gh("shatur/neovim-ayu") }, -- { src = gh("aejkatappaja/cendre") },
-- Mason / Lsp { src = gh("mason-org/mason.nvim.git") }, { src = gh("mason-org/mason-lspconfig.nvim.git") }, { src = gh("neovim/nvim-lspconfig.git") }, { src = gh("nvim-lua/plenary.nvim") }, -- { src = gh("olrtg/nvim-emmet")}, { src = gh("stevearc/conform.nvim") }, { src = gh("yioneko/nvim-vtsls") },
-- css unit converter { src = gh("MunifTanjim/nui.nvim") }, { src = gh("cjodo/convert.nvim") },})
-- ------------------------------------------------------------------------------- Core options-- -----------------------------------------------------------------------------local options = { number = true, relativenumber = true, mouse = "a", showmode = false, clipboard = "unnamedplus", breakindent = true, undofile = true, ignorecase = true, smartcase = true, signcolumn = "yes", updatetime = 250, timeoutlen = 600, splitright = true, splitbelow = true, inccommand = "split", cursorline = true, swapfile = false, scrolloff = 10, hlsearch = true, list = true, wrap = false, tabstop = 4, shiftwidth = 4, winborder = "rounded", background = "dark",}
for key, value in pairs(options) do vim.o[key] = valueend
vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" }
-- U+2028/U+2029 from Figma/Docs paste break tsserver (it reads JSON lines).vim.api.nvim_set_hl(0, "UnicodeLineSeparator", { default = true, link = "Error" })local line_sep_group = vim.api.nvim_create_augroup("unicode-line-separators", { clear = true })vim.api.nvim_create_autocmd({ "BufWinEnter", "WinEnter", "ColorScheme" }, { group = line_sep_group, callback = function() vim.api.nvim_set_hl(0, "UnicodeLineSeparator", { default = true, link = "Error" }) if vim.w.unicode_line_sep_match then pcall(vim.fn.matchdelete, vim.w.unicode_line_sep_match) end vim.w.unicode_line_sep_match = vim.fn.matchadd("UnicodeLineSeparator", [[\%u2028\|\%u2029]]) end,})
local paste = vim.paste---@diagnostic disable-next-line: duplicate-set-fieldvim.paste = function(lines, phase) local out = {} for _, line in ipairs(lines) do line = line:gsub("\226\128\168", "\n"):gsub("\226\128\169", "\n") for piece in (line .. "\n"):gmatch("(.-)\n") do table.insert(out, piece) end end return paste(out, phase)end
vim.g.mapleader = " "vim.g.maplocalleader = " "vim.g.have_nerd_font = truevim.g.everforest_background = "hard"vim.g.everforest_better_performance = 1
-- ------------------------------------------------------------------------------- Keymaps-- -----------------------------------------------------------------------------local function setup_keymaps() map("n", "<leader>cc", "<CMD>ConvertFindCurrent<CR>", "Find [C]onvertable unit in [C]urrent line")
map("n", "<leader>e", vim.diagnostic.open_float, "Show diagnostic [E]rror messages") map("n", "<leader>q", vim.diagnostic.setloclist, "Open diagnostic [Q]uickfix list") map("n", "<leader>ih", function() local bufnr = vim.api.nvim_get_current_buf() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr }) end, "Toggle [I]nlay [H]ints") map("n", "<leader>fb", "<CMD>Oil<CR>", "[F]ile [B]rowser") map("n", "<leader>sf", "<CMD>Telescope find_files<CR>", "[S]earch [F]iles") map("n", "<leader>sg", "<CMD>Telescope live_grep<CR>", "[S]earch by [G]rep") map("n", "<leader>sr", "<CMD>Telescope resume<CR>", "[S]earch [R]esume")
map({ "i", "s" }, "<C-j>", function() if vim.snippet.active({ direction = 1 }) then vim.snippet.jump(1) end end, "Jump snippet next")
map({ "i", "s" }, "<C-k>", function() if vim.snippet.active({ direction = -1 }) then vim.snippet.jump(-1) end end, "Jump snippet back")end
local function setup_lsp_keymaps() local lsp_group = vim.api.nvim_create_augroup("user-lsp-keymaps", { clear = true }) local lsp_maps = { { "n", "<leader>ca", vim.lsp.buf.code_action, "[C]ode [A]ction" }, { "n", "<leader>rn", vim.lsp.buf.rename, "[R]e[n]ame" }, { "n", "gd", vim.lsp.buf.definition, "[G]oto [D]efinition" }, { "n", "gr", vim.lsp.buf.references, "[G]oto [R]eferences" }, { "n", "gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration" }, { "n", "gi", vim.lsp.buf.implementation, "[G]oto [I]mplementation" }, { "n", "gy", vim.lsp.buf.type_definition, "[G]oto T[y]pe Definition" }, }
vim.api.nvim_create_autocmd("LspAttach", { group = lsp_group, callback = function(event) for _, item in ipairs(lsp_maps) do map(item[1], item[2], item[3], item[4], { buffer = event.buf }) end
local client = vim.lsp.get_client_by_id(event.data.client_id) if client and client.server_capabilities.inlayHintProvider then vim.lsp.inlay_hint.enable(true, { bufnr = event.buf }) end end, })end
-- ------------------------------------------------------------------------------- Plugin setup-- -----------------------------------------------------------------------------
local function setup_twilight() require("twilight").setup({ dimming = { alpha = 0.25, -- amount of dimming -- we try to get the foreground from the highlight groups or fallback color color = { "Normal", "#ffffff" }, term_bg = "#000000", -- if guibg=NONE, this will be used to calculate text color inactive = false, -- when true, other windows will be fully dimmed (unless they contain the same buffer) }, context = 10, -- amount of lines we will try to show around the current line treesitter = true, -- use treesitter when available for the filetype -- treesitter is used to automatically expand the visible text, -- but you can further control the types of nodes that should always be fully expanded expand = { -- for treesitter, we we always try to expand to the top-most ancestor with these types "function", "method", "table", "if_statement", }, exclude = {}, -- exclude these filetypes })end
local function setup_blink() local function kind_icon_from_mini(ctx) local mini = require("mini.icons") if ctx.source_name == "Path" then local category = ctx.kind == "Folder" and "directory" or "file" return mini.get(category, ctx.label) end return mini.get("lsp", ctx.kind) end
require("blink.cmp").setup({ keymap = { preset = "super-tab", }, appearance = { nerd_font_variant = "mono" }, completion = { documentation = { auto_show = true, auto_show_delay_ms = 200, }, accept = { auto_brackets = { enabled = true }, }, menu = { draw = { components = { kind_icon = { text = function(ctx) local icon = kind_icon_from_mini(ctx) return (icon or ctx.kind_icon) .. ctx.icon_gap end, highlight = function(ctx) local _, hl = kind_icon_from_mini(ctx) return { { group = hl or ctx.kind_hl, priority = 20000 } } end, }, }, }, }, }, signature = { enabled = true }, sources = { default = { "lsp", "path", "snippets", "buffer" } }, fuzzy = { implementation = "prefer_rust_with_warning" }, })end
local function setup_conform() require("conform").setup({ format_on_save = { timeout_ms = 500, lsp_fallback = true }, formatters_by_ft = { lua = { "stylua" }, javascript = { "oxfmt", "prettierd", "prettier", stop_after_first = true }, typescript = { "oxfmt", "prettierd", "prettier", stop_after_first = true }, typescriptreact = { "oxfmt", "prettierd", "prettier", stop_after_first = true }, javascriptreact = { "oxfmt", "prettierd", "prettier", stop_after_first = true }, json = { "oxfmt", "prettierd", "prettier", stop_after_first = true }, html = { "oxfmt", "prettierd", "prettier", stop_after_first = true }, css = { "cssls", "prettierd", "prettier", stop_after_first = true }, }, })end
local function setup_oil() require("oil").setup({ default_file_explorer = true, columns = { "icon" }, view_options = { show_hidden = true, is_hidden_file = function(name) return name ~= ".." and vim.startswith(name, ".") end, }, }) require("mini.icons").setup({})end
local function setup_hop() local hop = require("hop") local directions = require("hop.hint").HintDirection
local function hopmap(key, direction, current_line_only) vim.keymap.set("", key, function() hop.hint_char1({ direction = direction, current_line_only = current_line_only, }) end, { remap = true }) end
hopmap("f", directions.AFTER_CURSOR, false) hopmap("F", directions.BEFORE_CURSOR, false) hopmap("t", directions.AFTER_CURSOR, true) hopmap("T", directions.BEFORE_CURSOR, true) hop.setup({ keys = "etovxqpdygfblzhckisuran" })end
local function setup_trouble() require("trouble").setup({}) map("n", "<leader>xx", "<cmd>Trouble diagnostics toggle<cr>", "Trouble: diagnostics") map("n", "<leader>xq", "<cmd>Trouble qflist toggle<cr>", "Trouble: quickfix") map("n", "<leader>xl", "<cmd>Trouble loclist toggle<cr>", "Trouble: loclist") map("n", "<leader>xs", "<cmd>Trouble symbols toggle focus=false<cr>", "Trouble: symbols")end
local function setup_treesitter() require("tree-sitter-manager").setup({ ensure_installed = ensure_installed.treesitter, })end
local function setup_mason_and_lsp() require("mason").setup()
local capabilities = require("blink.cmp").get_lsp_capabilities() require("mason-lspconfig").setup({ ensure_installed = ensure_installed.lsp, automatic_enable = false, })
local servers = { lua_ls = {}, emmet_ls = {}, tailwindcss = {}, cssls = {}, ols = {}, }
for server_name, server_opts in pairs(servers) do server_opts.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server_opts.capabilities or {}) vim.lsp.config(server_name, server_opts) vim.lsp.enable(server_name) end
local typescript_servers = dofile(vim.fn.stdpath("config") .. "/lsp/typescript.lua") for server_name, server_opts in pairs(typescript_servers) do server_opts.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server_opts.capabilities or {}) vim.lsp.config(server_name, server_opts) vim.lsp.enable(server_name) endend
local function setup_lualine() require("lualine").setup({ options = { icons_enabled = true, theme = "auto", section_separators = "", component_separators = "", disabled_filetypes = { statusline = {}, winbar = {}, }, ignore_focus = {}, always_divide_middle = true, always_show_tabline = true, globalstatus = false, refresh = { statusline = 1000, tabline = 1000, winbar = 1000, refresh_time = 16, -- ~60fps events = { "WinEnter", "BufEnter", "BufWritePost", "SessionLoadPost", "FileChangedShellPost", "VimResized", "Filetype", "CursorMoved", "CursorMovedI", "ModeChanged", }, }, }, sections = { lualine_a = { "mode" }, lualine_b = { "diagnostics" }, lualine_c = { { "filename", path = 1 } }, lualine_x = { "filetype" }, lualine_y = { "progress" }, lualine_z = { "location" }, }, inactive_sections = { lualine_a = {}, lualine_b = {}, lualine_c = { "filename" }, lualine_x = { "location" }, lualine_y = {}, lualine_z = {}, }, tabline = {}, winbar = {}, inactive_winbar = {}, extensions = {}, })end
local function setup_theme() require("nordic").setup({ transparent = { bg = true }, })
require("gruvbox").setup({ breakindent = "dark", terminal_colors = true, contrast = "", })
require("osmium").setup({ integrations = { gitsigns = true, telescope = true, indent_blankline = true, fff = false, oil = true, mini_icons = true, }, transparent_bg = false, show_end_of_buffer = false, })
require("catppuccin").setup({ integrations = { cmp = true, gitsigns = true, nvimtree = true, notify = false, mini = { enabled = true, indentscope_color = "", }, blink_cmp = { style = "bordered", }, }, })
vim.cmd("colorscheme ayu-mirage") vim.cmd("hi statusline guibg=NONE")end
-- ------------------------------------------------------------------------------- Bootstrap-- -----------------------------------------------------------------------------setup_blink()setup_mason_and_lsp()setup_treesitter()setup_conform()setup_oil()setup_hop()setup_trouble()setup_keymaps()setup_lsp_keymaps()
require("todo-comments").setup({ signs = false })require("debugger")
setup_lualine()setup_theme()setup_twilight()
vim.api.nvim_create_autocmd("CmdlineLeave", { callback = function() -- Automatically clear search highlight matching and redraw vim.cmd("noh") vim.cmd("redraw!") end,})