-- Only required if you have packer configured as `opt` local ensure_packer = function() local fn = vim.fn local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim' if fn.empty(fn.glob(install_path)) > 0 then fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }) vim.cmd [[packadd packer.nvim]] return true end return false end local packer_bootstrap = ensure_packer() -- Use a protected call so we don't error out on first use local status_ok, packer = pcall(require, "packer") if not status_ok then return end -- Have packer use a popup window packer.init({ display = { open_fn = function() return require("packer.util").float({ border = "rounded" }) end, }, }) packer.startup(function(use) -- Packer can manage itself use 'wbthomason/packer.nvim' use 'nvim-lua/plenary.nvim' use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make', cond = vim.fn.executable 'make' == 1 } use { 'marko-cerovac/material.nvim', config = function() vim.g.material_style = "palenight" vim.cmd [[colorscheme material]] end } use { 'nvim-treesitter/nvim-treesitter', run = function() local ts_update = require('nvim-treesitter.install').update({ with_sync = true }) ts_update() end } use { -- Additional text objects via treesitter 'nvim-treesitter/nvim-treesitter-textobjects', after = 'nvim-treesitter', } use 'neovim/nvim-lspconfig' use { 'simrat39/rust-tools.nvim', config = function() local rt = require("rust-tools") rt.setup({ server = { 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 } use { 'WhoIsSethDaniel/toggle-lsp-diagnostics.nvim', config = function() require'toggle_lsp_diagnostics'.init() vim.keymap.set('n', 'e', vim.cmd.ToggleDiag) end } use { 'nvim-telescope/telescope.nvim', tag = '0.1.0', requires = { {'nvim-lua/plenary.nvim'} } } use 'mfussenegger/nvim-dap' use { "rcarriga/nvim-dap-ui", requires = {"mfussenegger/nvim-dap"}, config = function() require("dapui").setup() end, } use 'mbbill/undotree' use { 'numToStr/Comment.nvim', config = function() require('Comment').setup() end } use { "kylechui/nvim-surround", tag = "*", -- Use for stability; omit to use `main` branch for the latest features config = function() require("nvim-surround").setup({}) end } use { 'm4xshen/autoclose.nvim', config = function() require("autoclose").setup({}) end } -- use { 'TimUntersberger/neogit', requires = 'nvim-lua/plenary.nvim' } end) if packer_bootstrap then require('packer').sync() end local autocmd = vim.api.nvim_create_autocmd local augroup = vim.api.nvim_create_augroup autocmd(('BufWritePost'), { group = augroup('packer_user_config', { clear = true }), pattern = "plugins.lua", once = true, callback = function() vim.cmd('source ~/.config/nvim/lua/plugins.lua') packer.compile() end }) require('nvim-treesitter.configs').setup { -- Add languages to be installed here that you want installed for treesitter ensure_installed = { 'c', 'cpp', 'go', 'lua', 'bash', 'rust', 'go', 'help', 'haskell', 'ocaml' }, highlight = { enable = true, additional_vim_regex_highlighting = false }, indent = { enable = true }, incremental_selection = { enable = true, keymaps = { init_selection = '', node_incremental = '', scope_incremental = '', node_decremental = '', }, }, textobjects = { select = { enable = true, lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim keymaps = { -- You can use the capture groups defined in textobjects.scm ['aa'] = '@parameter.outer', ['ia'] = '@parameter.inner', ['af'] = '@function.outer', ['if'] = '@function.inner', ['ac'] = '@class.outer', ['ic'] = '@class.inner', }, }, move = { enable = true, set_jumps = true, -- whether to set jumps in the jumplist goto_next_start = { [')'] = '@function.outer', [']]'] = '@class.outer', }, goto_next_end = { [']M'] = '@function.outer', [']['] = '@class.outer', }, goto_previous_start = { ['('] = '@function.outer', ['[['] = '@class.outer', }, goto_previous_end = { ['[M'] = '@function.outer', ['[]'] = '@class.outer', }, }, -- TODO: Fix this swap = { enable = true, swap_next = { ['a'] = '@parameter.inner', }, swap_previous = { ['A'] = '@parameter.inner', }, }, }, } local dap = require('dap') dap.adapters.lldb = { type = 'executable', command = '/usr/bin/lldb-vscode', -- adjust as needed, must be absolute path name = 'lldb' } dap.configurations.rust = { { name = 'Launch', type = 'lldb', request = 'launch', program = function() return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') end, cwd = '${workspaceFolder}', stopOnEntry = false, args = {}, }, } -- If you want to use this for Rust and C, add something like this: dap.configurations.c = dap.configurations.rust dap.configurations.cpp = dap.configurations.rust local on_attach = function(client, bufnr) -- Enable completion triggered by vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') vim.diagnostic.config({ virtual_text = true, signs = true, underline = true, update_in_insert = false, severity_sort = false, }) -- Mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions local bufopts = { noremap=true, silent=true, buffer=bufnr } vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) vim.keymap.set('n', 'wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, bufopts) vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) end require('lspconfig')['rust_analyzer'].setup{ on_attach = on_attach, flags = lsp_flags, settings = { ["rust-analyzer"] = {} } } local hints = false show_hints = false toggle_hints = function() local hints = require("rust-tools").inlay_hints if show_hints then hints.enable() else hints.disable() end show_hints = not show_hints end vim.keymap.set("n", "li", toggle_hints)