--@diagnostic disable: undefined-global, vim.loader.enable() vim.g.netrw_banner = 0 vim.g.netrw_liststyle = 3 vim.g.netrw_altv = 0 vim.g.netrw_winsize = 25 vim.g.netrw_browse_split = 4 vim.g.rustfmt_autosave = 1 vim.g.mkdp_auto_start = 1 vim.g.gitgutter_set_sign_backgrounds = 1 vim.opt.nu = true vim.opt.tabstop = 4 vim.opt.softtabstop = 4 vim.opt.shiftwidth = 4 vim.opt.expandtab = true vim.opt.smartindent = true vim.opt.ruler = false vim.opt.wrap = false vim.opt.swapfile = false vim.opt.wildmenu = true vim.opt.path:append("**") vim.opt.hlsearch = true vim.opt.incsearch = true vim.opt.updatetime = 50 vim.opt.laststatus = 0 -- vim.opt.termguicolors = true vim.opt.signcolumn = "number" vim.opt.clipboard = "unnamedplus" vim.opt.fillchars = "eob: " vim.opt.autoindent = true vim.opt.lazyredraw = false vim.opt.updatetime = 300 vim.opt.timeoutlen = 500 -- -- Format on save if any attached LSP supports formatting vim.api.nvim_create_autocmd( "BufWritePre", { callback = function() local buf = vim.api.nvim_get_current_buf() local clients = vim.lsp.get_clients({bufnr = buf}) for _, client in ipairs(clients) do if client.server_capabilities.documentFormattingProvider then vim.lsp.buf.format({silent = true}) return end end -- No formatting-capable client: do nothing end } ) local run_on_save = vim.api.nvim_create_augroup("RunPfOnSave", {clear = true}) local formatters = { { patterns = { "*.js", "*.ts", "*.jsx", "*.json", "*.tsx", "*.css", "*.html", "*.yaml", "*.md", "*.svelte", "*.lua" }, command = function(file) vim.fn.system({"prettier", "--write", file}) end }, { patterns = {"*.tex"}, command = function(file) vim.fn.system({"pdflatex", "--shell-escape", file}) end }, { patterns = {"*.c", "*.h"}, command = function(file) vim.fn.system({"clang-format", "-i", file}) end } } for _, fmt in ipairs(formatters) do vim.api.nvim_create_autocmd( "BufWritePost", { group = run_on_save, pattern = fmt.patterns, callback = function(args) local filepath = args.match or args.file pcall(fmt.command, filepath) end } ) end -- Auto-delete Netrw hidden buffers vim.api.nvim_create_augroup("AutoDeleteNetrwHiddenBuffers", {clear = true}) vim.api.nvim_create_autocmd( "FileType", { group = "AutoDeleteNetrwHiddenBuffers", pattern = "netrw", callback = function() vim.opt_local.bufhidden = "wipe" vim.opt_local.buflisted = false end } ) function ToggleVExplorer() local expl_buf = vim.t.expl_buf_num local expl_win = expl_buf and vim.fn.bufwinnr(expl_buf) or -1 if expl_win ~= -1 then vim.cmd(expl_win .. "wincmd c") vim.t.expl_buf_num = nil else vim.cmd("topleft " .. (vim.g.netrw_winsize or 30) .. "vsplit") vim.cmd("Explore") vim.t.expl_buf_num = vim.fn.bufnr("%") end end local autopairs = { ["("] = ")", ["["] = "]", ["{"] = "}", ["<"] = ">" } for open, close in pairs(autopairs) do vim.api.nvim_set_keymap("i", open, open .. close .. "", {noremap = true, silent = true}) end function set_highlights() local highlights = { {"GitGutterAdd", {bg = "none"}}, {"GitGutterDelete", {bg = "none"}}, {"GitGutterChange", {bg = "none"}}, {"GitGutterChangeAdd", {bg = "none"}}, {"GitGutterChangeDelete", {bg = "none"}}, {"NonText", {fg = "none"}}, {"EndOfBuffer", {fg = "none", bg = "none"}}, {"SignColumn", {bg = "none"}}, {"StatusLine", {bg = "none", fg = "none"}}, {"StatusLineNc", {bg = "none", fg = "none"}}, {"CursorColumn", {fg = "none"}}, {"CursorLine", {bg = "none"}}, {"VertSplit", {bg = "none"}}, {"DiagnosticError", {bg = "none"}}, {"DiagnosticWarn", {bg = "none"}}, {"DiagnosticInfo", {bg = "none"}}, {"DiagnosticHint", {bg = "none"}}, {"Pmenu", {bg = "none"}}, {"DiagnosticVirtualTextError", {bg = "none"}}, {"DiagnosticVirtualTextWarn", {bg = "none"}}, {"DiagnosticVirtualTextInfo", {bg = "none"}}, {"DiagnosticVirtualTextHint", {bg = "none"}}, {"LspFloatWinNormal", {bg = "none"}}, {"NormalFloat", {bg = "none"}}, {"LineNr", {bg = "none"}}, {"DiagnosticVirtualError", {bg = "none"}}, {"DiagnosticVirtualWarn", {bg = "none"}}, {"DiagnosticVirtualInfo", {bg = "none"}}, {"DiagnosticVirtualHint", {bg = "none"}} } for _, hl in ipairs(highlights) do vim.api.nvim_set_hl(0, hl[1], hl[2]) end end vim.cmd("colorscheme quiet") vim.o.background = "dark" function color_mode() if vim.o.background == "dark" then vim.o.background = "light" vim.cmd("colorscheme zellner") else vim.o.background = "dark" vim.cmd("colorscheme quiet") end set_highlights() end local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then vim.fn.system( { "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath } ) end vim.opt.rtp:prepend(lazypath) require("lazy").setup( { { "ibhagwan/fzf-lua", opts = {} }, {"airblade/vim-gitgutter"}, { "neovim/nvim-lspconfig", lazy = false, dependencies = { {"ms-jpq/coq_nvim", branch = "coq"}, {"ms-jpq/coq.artifacts", branch = "artifacts"} }, init = function() vim.g.coq_settings = { auto_start = "shut-up", display = { icons = { mode = "none" }, ghost_text = { enabled = false } } } end } } ) local lsp_servers = { clangd = {filetypes = {"c", "h"}}, svelte = {filetypes = {"svelte"}}, ts_ls = {filetypes = {"typescript", "typescriptreact", "javascript", "javascriptreact"}}, rust_analyzer = {filetypes = {"rust"}} } local function server_maps(opts) local buf = opts.buffer end for server_name, config in pairs(lsp_servers) do require("lspconfig")[server_name].setup( coq.lsp_ensure_capabilities( { on_attach = function(client, bufnr) server_maps({buffer = bufnr}) end, filetypes = config.filetypes, settings = config.settings or {} } ) ) end set_highlights() vim.g.mapleader = " " vim.keymap.set("n", "e", ToggleVExplorer, {desc = "Toggle VExplorer"}) vim.keymap.set("n", "z", [[:%s/\<\>//gI]]) vim.keymap.set("n", "a", "ggVG") vim.keymap.set("n", "y", "cc") vim.keymap.set("n", "", "yy") vim.keymap.set("n", "", "p") vim.keymap.set("n", "", "u") vim.keymap.set("n", "j", "5j") vim.keymap.set("n", "k", "5k") vim.keymap.set("n", "f", "FzfLua files") vim.keymap.set("n", "F", "FzfLua live_grep", {noremap = true, silent = true}) vim.keymap.set("n", "b", "FzfLua buffers") vim.keymap.set("n", "d", vim.lsp.buf.definition, {silent = true}) vim.keymap.set( "n", "df", function() vim.diagnostic.open_float() end, {silent = true} ) vim.keymap.set("n", "k", vim.lsp.buf.hover, {silent = true}) vim.keymap.set( "n", "ca", function() vim.lsp.buf.code_action() end, {silent = true} ) vim.keymap.set("n", "r", color_mode, {desc = "Change mode light/dark"}) vim.keymap.set( "n", "t", function() vim.cmd("terminal") vim.cmd("startinsert") end, {desc = "Open terminal in current window"} ) vim.keymap.set("v", "J", ":m '>+1gv=gv") vim.keymap.set("v", "K", ":m '<-2gv=gv") vim.keymap.set( "t", "", function() vim.cmd([[stopinsert]]) vim.cmd([[b#]]) end, {noremap = true, silent = true} )