-- functions for auto-complete local has_words_before = function() local line, col = unpack(vim.api.nvim_win_get_cursor(0)) return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1] :sub(col, col):match("%s") == nil end local feedkey = function(key, mode) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) end -- plugins definition local function manage_plugins() local plugins = { ["https://github.com/faerryn/plogins.nvim.git"] = {}, ["https://github.com/tpope/vim-sensible.git"] = {}, ["https://github.com/neovim/nvim-lspconfig.git"] = {}, ["https://github.com/ojroques/nvim-hardline.git"] = { packadd_hook = function() require('hardline').setup() end }, ["https://github.com/EdenEast/nightfox.nvim.git"] = { packadd_hook = function() require('nightfox').setup({ options = { modules = { gitgutter = true, } }, palettes = { nightfox = { bg0 = '#121212', bg1 = '#161616', bg2 = '#222222', bg3 = '#282828', bg4 = '#404040', sel0 = "#2a2a2a", sel1 = "#525253", } }, specs = { nightfox = { syntax = { func = "red", } } }, }) vim.o.termguicolors = true vim.cmd("colorscheme nightfox") end }, -- Auto-completion ["https://github.com/hrsh7th/cmp-nvim-lsp.git"] = {}, ["https://github.com/hrsh7th/cmp-buffer.git"] = {}, ["https://github.com/hrsh7th/cmp-path.git"] = {}, ["https://github.com/hrsh7th/cmp-cmdline.git"] = {}, ["https://github.com/hrsh7th/cmp-vsnip.git"] = {}, ["https://github.com/hrsh7th/vim-vsnip.git"] = {}, ["https://github.com/hrsh7th/nvim-cmp.git"] = { packadd_after = { ["https://github.com/hrsh7th/cmp-nvim-lsp.git"] = true, ["https://github.com/hrsh7th/cmp-buffer.git"] = true, ["https://github.com/hrsh7th/cmp-path.git"] = true, ["https://github.com/hrsh7th/cmp-cmdline.git"] = true, ["https://github.com/hrsh7th/cmp-vsnip.git"] = true, ["https://github.com/hrsh7th/vim-vsnip.git"] = true, }, packadd_hook = function() vim.o.completeopt = "menu,menuone,noselect" local cmp = require("cmp") cmp.setup({ snippet = { -- snippet engine is required expand = function(args) vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. end, }, window = { -- completion = cmp.config.window.bordered(), -- documentation = cmp.config.window.bordered(), }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif vim.fn["vsnip#available"](1) == 1 then feedkey("(vsnip-expand-or-jump)", "") elseif has_words_before() then cmp.complete() else -- The fallback function sends a already mapped key. -- In this case, it's probably ``. fallback() end end, { "i", "s" }), [""] = cmp.mapping(function() if cmp.visible() then cmp.select_prev_item() elseif vim.fn["vsnip#jumpable"](-1) == 1 then feedkey("(vsnip-jump-prev)", "") end end, { "i", "s" }), }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'vsnip' }, }, { { name = 'buffer' }, }) }) -- Set configuration for specific filetype. cmp.setup.filetype('gitcommit', { sources = cmp.config.sources({ { name = 'cmp_git' }, }, { { name = 'buffer' }, }) }) -- Use buffer source for `/` and `?` cmp.setup.cmdline({ '/', '?' }, { mapping = cmp.mapping.preset.cmdline(), sources = { { name = 'buffer' } } }) -- Use cmdline & path source for ':' cmp.setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } }) }) end }, -- LSP servers ["https://github.com/simrat39/rust-tools.nvim.git"] = { packadd_after = { ["https://github.com/neovim/nvim-lspconfig.git"] = true, ["https://github.com/hrsh7th/nvim-cmp.git"] = true, }, packadd_hook = function() local rt = require("rust-tools") local capabilities = require("cmp_nvim_lsp").default_capabilities() rt.setup({ server = { capabilities = capabilities, on_attach = function(_, bufnr) -- Hover actions --vim.keymap.set("n", "", --rt.hover_actions.hover_actions, { buffer = bufnr }) ---- Code action groups --vim.keymap.set("n", "a", --rt.code_action_group.code_action_group, { buffer = bufnr }) end, }, }) end }, -- Git integration ["https://github.com/tpope/vim-fugitive.git"] = {}, ["https://github.com/airblade/vim-gitgutter.git"] = { packadd_after = { ["https://github.com/EdenEast/nightfox.nvim.git"] = true }, packadd_hook = function() -- put sign in number column to avoid screen-shifting vim.cmd('set signcolumn=number') end }, -- Syntax highlight ["https://github.com/nvim-treesitter/nvim-treesitter.git"] = { packadd_hook = function() local conf = require("nvim-treesitter.configs") conf.setup { -- only enable tested parsers ensure_installed = { "c", "cpp", "lua", "rust" }, -- Install parsers synchronously (only applied to `ensure_installed`) sync_install = false, -- Automatically install missing parsers when entering buffer auto_install = false, -- List of parsers to ignore installing (for "all") ignore_install = {}, highlight = { -- `false` will disable the whole extension enable = true, -- list of language that will be disabled disable = {}, -- disable slow treesitter highlight for large files disable = function(lang, buf) local max_filesize = 100 * 1024 -- 100 KB 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, -- run `:h syntax` and tree-sitter at the same time. additional_vim_regex_highlighting = false, } } end }, } local manager = require("plogins").manage(plugins) vim.api.nvim_create_user_command("PloginsUpgrade", manager.upgrade, {}) vim.api.nvim_create_user_command("PloginsAutoremove", manager.autoremove, {}) end local plogins_source = "https://github.com/faerryn/plogins.nvim.git" local plogins_name = plogins_source:gsub("/", "%%") local plogins_dir = ("%s/site/pack/plogins/opt/%s"):format((vim.fn.stdpath("data")), plogins_name) if not vim.loop.fs_stat(plogins_dir) then vim.loop.spawn("git", { args = { "clone", "--depth", "1", plogins_source, plogins_dir } }, function(code, signal) vim.defer_fn(function() vim.cmd(("packadd %s"):format(vim.fn.fnameescape(plogins_name))) manage_plugins() end, 0) end) else vim.cmd(("packadd %s"):format(vim.fn.fnameescape(plogins_name))) manage_plugins() end