vim.opt.number = true vim.opt.relativenumber = true vim.opt.expandtab = true vim.opt.tabstop = 8 vim.opt.softtabstop = 0 vim.opt.shiftwidth = 4 vim.opt.smarttab = true vim.opt.autoindent = true vim.opt.mouse = "a" vim.opt.undofile = true vim.opt.ignorecase = true vim.opt.smartcase = true local plugins = { { source = "neovim/nvim-lspconfig", }, { source = "hrsh7th/nvim-cmp", depends = { "hrsh7th/cmp-nvim-lsp" } }, { source = "andweeb/presence.nvim" }, { source = "nvim-treesitter/nvim-treesitter", }, { source = "Mofiqul/vscode.nvim", } } local servers = { clangd = { cmd = { "clangd", "-header-insertion=never" } }, gopls = {}, nim_langserver = {}, rust_analyzer = {}, cssls = { cmd = { "vscode-css-language-server", "--stdio" } }, html = { cmd = { "vscode-html-language-server", "--stdio" } }, jsonls = { cmd = { "vscode-json-language-server", "--stdio" } } } -- Install plugin manager local mini_path = vim.fn.stdpath("data") .. "/site/pack/deps/start/mini.nvim" if not vim.loop.fs_stat(mini_path) then vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/echasnovski/mini.nvim", mini_path }) vim.cmd("packadd mini.nvim | helptags ALL") end require("mini.deps").setup({ path = { package = path_package } }) -- mini.completion is missing snippet support so waiting for that, once added can get rid of cmp -- require("mini.completion").setup() -- is Ctrl+/ local comment_keybind = "" require("mini.comment").setup({ mappings = { comment = comment_keybind, comment_line = comment_keybind, comment_visual = comment_keybind, textobject = comment_keybind, }, }) -- Install plugins for plugin in pairs(plugins) do MiniDeps.add(plugins[plugin]) end -- Setup completion local cmp = require("cmp") cmp.setup({ snippet = { expand = function(args) vim.snippet.expand(args.body) end, }, mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.complete(), [""] = cmp.mapping.confirm({ select = true }) }), sources = cmp.config.sources({ { name = "nvim_lsp" }, }) }, { { name = "buffer" }, }); -- Setup servers and their configs local capabilities = require("cmp_nvim_lsp").default_capabilities() local lspconfig = require("lspconfig") for server in pairs(servers) do local config = servers[server] config.capabilities = config.capabilities or capabilities lspconfig[server].setup(config) end require("nvim-treesitter.configs").setup({ sync_install = false, auto_install = true, highlight = { enable = true, disable = function(lang, buf) local max_filesize = 100 * 1024 local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) if ok and stats and stats.size > max_filesize then return true end end, additional_vim_regex_highlighting = false, }, }) local c = require('vscode.colors').get_colors() require("vscode").setup({ group_overrides = { Comment = { fg=c.vscDarkBlue, bg=c.vscLightGreen, bold=true }, } }) vim.cmd("colorscheme vscode") -- Setup Discord rich presence require("presence").setup({ neovim_image_text = "Neovim", }) -- Binds to jump between snippets vim.keymap.set({ "i", "s" }, "", function() if vim.snippet.active({ direction = 1 }) then return "lua vim.snippet.jump(1)" else return "" end end, { expr = true }) vim.keymap.set({ "i", "s" }, "", function() if vim.snippet.active({ direction = -1 }) then return "lua vim.snippet.jump(-1)" else return "" end end, { expr = true }) vim.keymap.set({ "n" }, "gd", function() vim.lsp.buf.definition() end) vim.keymap.set({ "n" }, "a", function() vim.lsp.buf.code_action() end) vim.keymap.set({ "n" }, "e", function() vim.diagnostic.open_float() end) -- Session saving and restoring local session_file = vim.fn.stdpath("data") .. "/sessions/" .. vim.fn.fnamemodify(vim.fn.getcwd(), ':t') .. "/session.vim" vim.api.nvim_create_autocmd("VimLeavePre", { pattern = "*", callback = function() vim.fn.mkdir(vim.fn.fnamemodify(session_file, ":h"), "p") vim.cmd("mksession! " .. session_file) vim.v.this_session = session_file end, }) vim.api.nvim_create_autocmd("VimEnter", { nested = true, once = true, callback = function() if vim.fn.filereadable(session_file) == 1 and #vim.fn.argv() == 0 then vim.cmd("silent! %bwipeout!") vim.cmd("silent! source " .. session_file) vim.v.this_session = session_file end end }) vim.api.nvim_create_autocmd("BufWritePre", { callback = function() vim.lsp.buf.format({ async = false }) end })