--@diagnostic disable: undefined-global, local option = vim.opt -- local vim.keymap = vim.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 = 0 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 = true 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", "*.svelte, *.lua"}, 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" vim.opt_local.buflisted = false 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 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.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 = {} require('lspconfig').clangd.setup({ filetypes = { "c", "cpp", "objc", "objcpp" }, }) require('lspconfig').svelte.setup({ filetypes = { "svelte" }, }) require('lspconfig').ts_ls.setup({ filetypes = { "typescript", "typescriptreact", "javascript", "javascriptreact" }, }) require('lspconfig').rust_analyzer.setup({ 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("v", "J", ":m '>+1gv=gv") vim.keymap.set("n", "j", "5j") vim.keymap.set("n", "k", "5k") vim.keymap.set("v", "K", ":m '<-2gv=gv") 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", "k", vim.lsp.buf.hover, 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('t', '', function() vim.cmd([[stopinsert]]) vim.cmd([[b#]]) end, { noremap = true, silent = true })