---@diagnostic disable: undefined-global, local option = vim.opt local keymap = vim.keymap local api = vim.api local fn = vim.fn 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 option.nu = true option.tabstop = 2 option.softtabstop = 2 option.shiftwidth = 2 option.expandtab = true option.smartindent = true option.ruler = false option.wrap = false option.swapfile = false option.hlsearch = false option.incsearch = true option.updatetime = 50 option.laststatus = 0 option.signcolumn = "number" option.autoindent = true option.clipboard = "unnamedplus" option.termguicolors = true option.fillchars = "eob: " option.autoindent = true option.lazyredraw = false option.updatetime = 300 option.timeoutlen = 500 -- Format on save api.nvim_create_autocmd( "BufWritePre", { callback = function() vim.lsp.buf.format() end } ) api.nvim_create_augroup("RunPfOnSave", {clear = true}) api.nvim_create_autocmd( "BufWritePost", { group = "RunPfOnSave", pattern = {"*.js", "*.ts", "*.jsx", "*.json", "*.tsx", "*.css", "*.html", "*.yaml", "*.md"}, command = "silent! !prettier --write %" } ) api.nvim_create_autocmd( "BufWritePost", { group = "RunPfOnSave", pattern = "*.tex", command = "silent! !pdflatex --shell-escape %" } ) -- Auto-delete Netrw hidden buffers api.nvim_create_augroup("AutoDeleteNetrwHiddenBuffers", {clear = true}) api.nvim_create_autocmd( "FileType", { group = "AutoDeleteNetrwHiddenBuffers", pattern = "netrw", callback = function() vim.opt_local.bufhidden = "wipe" end } ) -- Toggle VExplorer function ToggleVExplorer() if vim.t.expl_buf_num then local expl_win_num = fn.bufwinnr(vim.t.expl_buf_num) if expl_win_num ~= -1 then local cur_win_id = fn.win_getid() vim.cmd(expl_win_num .. "windo close") local prev_win_num = fn.win_id2win(cur_win_id) if prev_win_num ~= 0 then vim.cmd(prev_win_num .. "wincmd w") end end vim.t.expl_buf_num = nil else vim.cmd("1wincmd w") vim.cmd("Vexplore") vim.t.expl_buf_num = fn.bufnr("%") end end local function setup_autopairs() local autopairs = { ["("] = ")", ["["] = "]", ["{"] = "}", ["<"] = ">", } for open, close in pairs(autopairs) do vim.api.nvim_set_keymap( 'i', open, open .. close .. "", { noremap = true, silent = true } ) end end setup_autopairs() 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({ { 'mrcjkb/rustaceanvim', version = '^5', lazy = false, }, { 'rust-lang/rust.vim' }, { "ellisonleao/gruvbox.nvim", priority = 1000, config = true, opts = {}, }, { "airblade/vim-gitgutter" }, { "norcalli/nvim-colorizer.lua" }, { "nvim-treesitter/nvim-treesitter" }, { "neovim/nvim-lspconfig", lazy = false, dependencies = { { "ms-jpq/coq_nvim", branch = "coq" }, { "ms-jpq/coq.artifacts", branch = "artifacts" }, { "williamboman/mason.nvim" }, { "williamboman/mason-lspconfig.nvim" } }, init = function() vim.g.coq_settings = { auto_start = "shut-up" } end }, { "nvim-telescope/telescope.nvim", lazy = false, tag = "0.1.5", dependencies = { "nvim-lua/plenary.nvim" } }, { "nvim-telescope/telescope-fzf-native.nvim", lazy = true, build = "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build", }, }) vim.cmd('colorscheme gruvbox') require("colorizer").setup() vim.api.nvim_create_autocmd( "BufWritePre", { callback = function() vim.lsp.buf.format() end } ) local lsp_servers = {} require("mason").setup({ ui = { icons = { package_installed = "✓", package_pending = "➜", package_uninstalled = "✗" } } }) local server_maps = function(opts) end for lsp, settings in pairs(lsp_servers) do require("lspconfig")[lsp].setup( coq.lsp_ensure_capabilities( { on_attach = function(_, buffer) server_maps({buffer = buffer}) end, settings = settings } ) ) end 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"}}, {"Normal", {bg = "none"}}, {"SignColumn", {bg = "none"}}, {"StatusLine", {bg = "none", fg = "none"}}, {"StatusLineNc", {bg = "none", fg = "none"}}, {"NvimTreeWinSeparator", {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 vim.g.mapleader = " " keymap.set("n", "e", ToggleVExplorer, {desc = "Toggle VExplorer"}) keymap.set("n", "z", [[:%s/\<\>//gI]]) keymap.set("n", "a", "ggVG") keymap.set("n", "y", "cc") keymap.set("n", "", "yy") keymap.set("n", "", "p") keymap.set("n", "", "u") keymap.set("v", "J", ":m '>+1gv=gv") keymap.set("n", "j", "5j") keymap.set("n", "k", "5k") keymap.set("v", "K", ":m '<-2gv=gv") keymap.set("n", "f", "Telescope find_files") keymap.set("n", "g", "Telescope live_grep") keymap.set("n", "d", vim.lsp.buf.definition, opts) keymap.set("n", "k", vim.lsp.buf.hover, opts)