--@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.hlsearch = true vim.opt.incsearch = true vim.opt.updatetime = 50 vim.opt.laststatus = 0 vim.opt.signcolumn = "number" vim.opt.clipboard = "unnamedplus" vim.opt.termguicolors = true vim.opt.fillchars = "eob: " vim.opt.autoindent = true vim.opt.lazyredraw = false vim.opt.updatetime = 300 vim.opt.timeoutlen = 500 -- Format on save vim.api.nvim_create_autocmd( "BufWritePre", { callback = function() vim.lsp.buf.format({silent = true}) end } ) vim.api.nvim_create_augroup("RunPfOnSave", {clear = true}) vim.api.nvim_create_autocmd( "BufWritePost", { group = "RunPfOnSave", pattern = {"*.js", "*.ts", "*.jsx", "*.json", "*.tsx", "*.css", "*.html", "*.yaml", "*.md", "*.svelte, *.lua"}, command = "silent! !prettier --write %" } ) vim.api.nvim_create_autocmd( "BufWritePost", { group = "RunPfOnSave", pattern = "*.tex", command = "silent! !pdflatex --shell-escape %" } ) -- 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 } ) -- Toggle VExplorer function ToggleVExplorer() if vim.t.expl_buf_num then local expl_win_num = vim.fn.bufwinnr(vim.t.expl_buf_num) if expl_win_num ~= -1 then if vim.fn.winnr('$') > 1 then local cur_win_id = vim.fn.win_getid() vim.cmd(expl_win_num .. "windo close") local prev_win_num = vim.fn.win_id2win(cur_win_id) if prev_win_num ~= 0 then vim.cmd(prev_win_num .. "wincmd w") end else vim.cmd("enew") end end vim.t.expl_buf_num = nil else vim.cmd("topleft " .. vim.g.netrw_winsize .. "vsplit") vim.cmd("Explore") vim.t.expl_buf_num = vim.fn.bufnr("%") vim.cmd("wincmd h") 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 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"}}, {"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 end vim.cmd("colorscheme default") vim.api.nvim_set_hl(0, "Normal", { bg = "#000c18" }) vim.o.background = "dark" function color_mode() if vim.o.background == "dark" then vim.o.background = "light" vim.api.nvim_set_hl(0, "Normal", {bg = "none"}) else vim.o.background = "dark" end set_highlights() 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( { { "ibhagwan/fzf-lua", opts = {} }, {"airblade/vim-gitgutter"}, {"norcalli/nvim-colorizer.lua"}, { "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" } end } } ) require("colorizer").setup() vim.api.nvim_create_autocmd( "BufWritePre", { callback = function() vim.lsp.buf.format() end } ) local lsp_servers = { clangd = { filetypes = {"c", "cpp", "objc", "objcpp"} }, svelte = { filetypes = {"svelte"} }, ts_ls = { filetypes = {"typescript", "typescriptreact", "javascript", "javascriptreact"} }, rust_analyzer = { filetypes = {"rust"} } } 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 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, opts) vim.keymap.set("n", "df", function() vim.diagnostic.open_float() end, opts) vim.keymap.set("n", "k", vim.lsp.buf.hover, opts) vim.keymap.set("n", "ca", function() vim.lsp.buf.code_action() end, opts) 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})