local vim = vim -- ----------------------------------------------------------------------------- -- Helpers and shared config -- ----------------------------------------------------------------------------- local function gh(repo) return "https://github.com/" .. repo end 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] = value end 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-field vim.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 = true vim.g.everforest_background = "hard" vim.g.everforest_better_performance = 1 -- ----------------------------------------------------------------------------- -- Keymaps -- ----------------------------------------------------------------------------- local function setup_keymaps() map("n", "cc", "ConvertFindCurrent", "Find [C]onvertable unit in [C]urrent line") map("n", "e", vim.diagnostic.open_float, "Show diagnostic [E]rror messages") map("n", "q", vim.diagnostic.setloclist, "Open diagnostic [Q]uickfix list") map("n", "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", "fb", "Oil", "[F]ile [B]rowser") map("n", "sf", "Telescope find_files", "[S]earch [F]iles") map("n", "sg", "Telescope live_grep", "[S]earch by [G]rep") map("n", "sr", "Telescope resume", "[S]earch [R]esume") map({ "i", "s" }, "", function() if vim.snippet.active({ direction = 1 }) then vim.snippet.jump(1) end end, "Jump snippet next") map({ "i", "s" }, "", 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", "ca", vim.lsp.buf.code_action, "[C]ode [A]ction" }, { "n", "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", "xx", "Trouble diagnostics toggle", "Trouble: diagnostics") map("n", "xq", "Trouble qflist toggle", "Trouble: quickfix") map("n", "xl", "Trouble loclist toggle", "Trouble: loclist") map("n", "xs", "Trouble symbols toggle focus=false", "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) end end 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, })