diff --git a/bash/.bashrc b/bash/.bashrc index 265eef9..ce19e6f 100644 --- a/bash/.bashrc +++ b/bash/.bashrc @@ -5,6 +5,9 @@ # Add ~/bin and ~/bin/scripts to my path export PATH=$PATH:$HOME/bin/:$HOME/bin/scripts/ +# Set editor to neovim. +export EDITOR=nvim + # Prompt stuff # # LINEAGE: diff --git a/nvim/init.lua b/nvim/init.lua index b7f6a85..d93212e 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -19,13 +19,26 @@ vim.opt.modeline = true vim.opt.undofile = true vim.g.mapleader = ' ' +vim.opt.completeopt = {'menuone', 'noselect', 'noinsert'} +vim.opt.shortmess = vim.opt.shortmess + { c = true} +vim.api.nvim_set_option('updatetime', 100) + +-- Fixed column for diagnostics to appear +-- Show autodiagnostic popup on cursor hover_range +-- Goto previous / next diagnostic warning / error +-- Show inlay_hints more frequently +vim.cmd([[ +set signcolumn=yes +autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) +]]) + -- Load utilities require('kalle.utils') -- Load plugins require('kalle.plugins') -vim.cmd('colorscheme nightfox') +vim.cmd('colorscheme carbonfox') -- Load config require('kalle.config') diff --git a/nvim/lua/kalle/config/keybinds.lua b/nvim/lua/kalle/config/keybinds.lua index b38934b..fb102aa 100644 --- a/nvim/lua/kalle/config/keybinds.lua +++ b/nvim/lua/kalle/config/keybinds.lua @@ -38,5 +38,32 @@ Keybind.g({ -- [ space + o + f] Open file { 'n', 'of', 'Telescope git_files', { noremap = true, desc = 'Open file' } }, - + -- [ space + c] Code + { 'n', 'c', '', {noremap = true, desc = '+Code' } }, + -- [ space + c + a] Code actions + { 'n', 'ca', 'lua vim.lsp.buf.code_action()', {noremap = true, desc = 'Code actions' } }, + -- [ space + c] + { 'n', 'cr', 'Telescope lsp_references', {noremap = true, desc = 'References' } }, + -- [ space + c] + { 'n', 'cd', 'Telescope lsp_definitions', {noremap = true, desc = 'Definitions' } }, + + -- [space + F9] Launch vimspector + { 'n', '', 'call vimspector#Launch()', {noremap = true, desc = "Launch vimspector"}}, + -- [F5] Step over + { 'n', '', 'call vimspector#StepOver()', {noremap = true, desc = "Step over"}}, + -- [space + F8] Reset vimspector + { 'n', '', 'call vimspector#Reset()', {noremap = true, desc = "Reset vimspector"}}, + -- [F12] Step out + { 'n', '', 'call vimspector#StepOut()', {noremap = true, desc = "Step out"}}, + -- [F11] Continue + { 'n', '', 'call vimspector#Continue()', {noremap = true, desc = "Continue"} }, + -- [F10] Step into + { 'n', '', 'call vimspector#StepInto()', {noremap = true, desc = "Step into"}}, + + -- [ D + b] Toggle breakpoint + {'n', "Db", ":call vimspector#ToggleBreakpoint()", {noremap = true, desc = "Toggle breakpoint"}}, + -- [ D + w] Add watch + {'n', "Dw", ":call vimspector#AddWatch()", {noremap = true, desc = "Add watch"}}, + -- [ D + e] Evaluate + {'n', "De", ":call vimspector#Evaluate()", {noremap = true, desc = "Evaluate"}}, }) diff --git a/nvim/lua/kalle/config/plugin-config.lua b/nvim/lua/kalle/config/plugin-config.lua index c1ed09a..b708305 100644 --- a/nvim/lua/kalle/config/plugin-config.lua +++ b/nvim/lua/kalle/config/plugin-config.lua @@ -84,21 +84,51 @@ local cmp = require'cmp' cmp.setup({ snippet = { expand = function(args) - require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + vim.fn["vsnip#anonymous"](args.body) end, }, mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + -- Add tab support + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }) }), sources = cmp.config.sources({ + { name = 'path' }, -- file paths + { name = 'nvim_lsp', keyword_length = 3 }, -- from language server + { name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized + { name = 'nvim_lua', keyword_length = 2}, -- complete neovim's Lua runtime API such vim.lsp.* + { name = 'buffer', keyword_length = 2 }, -- source current buffer + { name = 'vsnip', keyword_length = 2 }, -- nvim-cmp source for vim-vsnip + { name = 'calc'}, -- source for math calculation { name = 'nvim_lsp' }, - }, { - { name = 'buffer' }, - }) + }), + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + formatting = { + fields = {'menu', 'abbr', 'kind'}, + format = function(entry, item) + local menu_icon ={ + nvim_lsp = 'λ', + vsnip = '⋗', + buffer = 'Ω', + path = '🖫', + } + item.menu = menu_icon[entry.source.name] + return item + end, + }, }) cmp.setup.filetype('gitcommit', { @@ -164,6 +194,8 @@ require("mason-lspconfig").setup_handlers({ end, }) +require('mason-nvim-dap').setup() + require('gitsigns').setup { current_line_blame = true, } @@ -171,6 +203,7 @@ require('gitsigns').setup { require('marks').setup {} require('nvim-treesitter.configs').setup { + ensure_installed = { "lua", "rust", "toml" }, auto_install = true, highlight = { enable = true, @@ -179,4 +212,85 @@ require('nvim-treesitter.configs').setup { indent = { enable = true }, + rainbow = { + enable = true, + extended_mode = true, + max_file_lines = nil, + } } + +-- Treesitter folding +vim.wo.foldmethod = 'expr' +vim.wo.foldexpr = 'nvim_treesitter#foldexpr()' +vim.o.foldenable = false + +require('Comment').setup() +require('illuminate').configure() + + +local rt_config = { + server = { + settings = { + on_attach = function(_, bufnr) + -- Hover actions + vim.keymap.set("n", "", rt_config.hover_actions.hover_actions, { buffer = bufnr }) + -- Code action groups + vim.keymap.set("n", "a", rt_config.code_action_group.code_action_group, { buffer = bufnr }) + require 'illuminate'.on_attach(client) + end, + ["rust-analyzer"] = { + checkOnSave = { + command = "clippy" + }, + }, + } + }, +} + +require('rust-tools').setup() + +-- LSP Diagnostics Options Setup +local sign = function(opts) + vim.fn.sign_define(opts.name, { + texthl = opts.name, + text = opts.text, + numhl = '' + }) +end + +sign({name = 'DiagnosticSignError', text = ''}) +sign({name = 'DiagnosticSignWarn', text = ''}) +sign({name = 'DiagnosticSignHint', text = ''}) +sign({name = 'DiagnosticSignInfo', text = ''}) + +vim.diagnostic.config({ + virtual_text = false, + signs = true, + update_in_insert = true, + underline = true, + severity_sort = false, + float = { + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, +}) + +vim.cmd([[ +set signcolumn=yes +autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) +]]) + +-- Vimspector options +vim.cmd([[ +let g:vimspector_sidebar_width = 85 +let g:vimspector_bottombar_height = 15 +let g:vimspector_terminal_maxwidth = 70 +]]) + +require('nvim-lightbulb').setup({autocmd = {enabled = true}}) + +require("telescope").load_extension("ui-select") + +require("todo-comments").setup {} diff --git a/nvim/lua/kalle/plugins.lua b/nvim/lua/kalle/plugins.lua index aabc018..be62645 100644 --- a/nvim/lua/kalle/plugins.lua +++ b/nvim/lua/kalle/plugins.lua @@ -17,11 +17,20 @@ return require('packer').startup({function(use) use('EdenEast/nightfox.nvim') use('folke/which-key.nvim') + use('numToStr/Comment.nvim') + use('RRethy/vim-illuminate') + use { 'nvim-treesitter/nvim-treesitter', run = function() require('nvim-treesitter.install').update({ with_sync = true }) end, } + use('antoinemadec/FixCursorHold.nvim') + use { + 'kosayoda/nvim-lightbulb', + requires = 'antoinemadec/FixCursorHold.nvim', + } + use { 'kyazdani42/nvim-tree.lua', requires = { @@ -34,18 +43,27 @@ return require('packer').startup({function(use) "williamboman/mason-lspconfig.nvim", } + use('simrat39/rust-tools.nvim') + use('chentoast/marks.nvim') use('neovim/nvim-lspconfig') - use('L3MON4D3/LuaSnip') + use('mfussenegger/nvim-dap') + use('rcarriga/nvim-dap-ui') + use('theHamsta/nvim-dap-virtual-text') + use('nvim-telescope/telescope-dap.nvim') + use('jayp0521/mason-nvim-dap.nvim') use { 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline', + 'hrsh7th/cmp-nvim-lsp-signature-help', + 'hrsh7th/cmp-vsnip', 'hrsh7th/nvim-cmp', + 'hrsh7th/vim-vsnip', } use 'famiu/bufdelete.nvim' @@ -69,6 +87,11 @@ return require('packer').startup({function(use) }, } + use('nvim-telescope/telescope-ui-select.nvim') + + use('folke/todo-comments.nvim') + + -- Automatically set up your configuration after cloning packer.nvim -- Put this at the end after all plugins if packer_bootstrap then diff --git a/nvim/plugin/packer_compiled.lua b/nvim/plugin/packer_compiled.lua index 584a40d..7296b14 100644 --- a/nvim/plugin/packer_compiled.lua +++ b/nvim/plugin/packer_compiled.lua @@ -9,23 +9,26 @@ vim.api.nvim_command('packadd packer.nvim') local no_errors, error_msg = pcall(function() - local time - local profile_info - local should_profile = false - if should_profile then - local hrtime = vim.loop.hrtime - profile_info = {} - time = function(chunk, start) - if start then - profile_info[chunk] = hrtime() - else - profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 - end +_G._packer = _G._packer or {} +_G._packer.inside_compile = true + +local time +local profile_info +local should_profile = false +if should_profile then + local hrtime = vim.loop.hrtime + profile_info = {} + time = function(chunk, start) + if start then + profile_info[chunk] = hrtime() + else + profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 end - else - time = function(chunk, start) end end - +else + time = function(chunk, start) end +end + local function save_profiles(threshold) local sorted_times = {} for chunk_name, time_taken in pairs(profile_info) do @@ -38,8 +41,10 @@ local function save_profiles(threshold) results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms' end end + if threshold then + table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)') + end - _G._packer = _G._packer or {} _G._packer.profile_output = results end @@ -69,10 +74,15 @@ end time([[try_loadstring definition]], false) time([[Defining packer_plugins]], true) _G.packer_plugins = { - LuaSnip = { + ["Comment.nvim"] = { loaded = true, - path = "/home/kalle/.local/share/nvim/site/pack/packer/start/LuaSnip", - url = "https://github.com/L3MON4D3/LuaSnip" + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/Comment.nvim", + url = "https://github.com/numToStr/Comment.nvim" + }, + ["FixCursorHold.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/FixCursorHold.nvim", + url = "https://github.com/antoinemadec/FixCursorHold.nvim" }, ["bufdelete.nvim"] = { loaded = true, @@ -99,11 +109,21 @@ _G.packer_plugins = { path = "/home/kalle/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", url = "https://github.com/hrsh7th/cmp-nvim-lsp" }, + ["cmp-nvim-lsp-signature-help"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp-signature-help", + url = "https://github.com/hrsh7th/cmp-nvim-lsp-signature-help" + }, ["cmp-path"] = { loaded = true, path = "/home/kalle/.local/share/nvim/site/pack/packer/start/cmp-path", url = "https://github.com/hrsh7th/cmp-path" }, + ["cmp-vsnip"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/cmp-vsnip", + url = "https://github.com/hrsh7th/cmp-vsnip" + }, ["gitsigns.nvim"] = { loaded = true, path = "/home/kalle/.local/share/nvim/site/pack/packer/start/gitsigns.nvim", @@ -124,6 +144,11 @@ _G.packer_plugins = { path = "/home/kalle/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim", url = "https://github.com/williamboman/mason-lspconfig.nvim" }, + ["mason-nvim-dap.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/mason-nvim-dap.nvim", + url = "https://github.com/jayp0521/mason-nvim-dap.nvim" + }, ["mason.nvim"] = { loaded = true, path = "/home/kalle/.local/share/nvim/site/pack/packer/start/mason.nvim", @@ -144,6 +169,26 @@ _G.packer_plugins = { path = "/home/kalle/.local/share/nvim/site/pack/packer/start/nvim-cmp", url = "https://github.com/hrsh7th/nvim-cmp" }, + ["nvim-dap"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/nvim-dap", + url = "https://github.com/mfussenegger/nvim-dap" + }, + ["nvim-dap-ui"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/nvim-dap-ui", + url = "https://github.com/rcarriga/nvim-dap-ui" + }, + ["nvim-dap-virtual-text"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/nvim-dap-virtual-text", + url = "https://github.com/theHamsta/nvim-dap-virtual-text" + }, + ["nvim-lightbulb"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/nvim-lightbulb", + url = "https://github.com/kosayoda/nvim-lightbulb" + }, ["nvim-lspconfig"] = { loaded = true, path = "/home/kalle/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", @@ -174,11 +219,41 @@ _G.packer_plugins = { path = "/home/kalle/.local/share/nvim/site/pack/packer/start/plenary.nvim", url = "https://github.com/nvim-lua/plenary.nvim" }, + ["rust-tools.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/rust-tools.nvim", + url = "https://github.com/simrat39/rust-tools.nvim" + }, + ["telescope-dap.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/telescope-dap.nvim", + url = "https://github.com/nvim-telescope/telescope-dap.nvim" + }, + ["telescope-ui-select.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/telescope-ui-select.nvim", + url = "https://github.com/nvim-telescope/telescope-ui-select.nvim" + }, ["telescope.nvim"] = { loaded = true, path = "/home/kalle/.local/share/nvim/site/pack/packer/start/telescope.nvim", url = "https://github.com/nvim-telescope/telescope.nvim" }, + ["todo-comments.nvim"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/todo-comments.nvim", + url = "https://github.com/folke/todo-comments.nvim" + }, + ["vim-illuminate"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/vim-illuminate", + url = "https://github.com/RRethy/vim-illuminate" + }, + ["vim-vsnip"] = { + loaded = true, + path = "/home/kalle/.local/share/nvim/site/pack/packer/start/vim-vsnip", + url = "https://github.com/hrsh7th/vim-vsnip" + }, ["which-key.nvim"] = { loaded = true, path = "/home/kalle/.local/share/nvim/site/pack/packer/start/which-key.nvim", @@ -187,6 +262,13 @@ _G.packer_plugins = { } time([[Defining packer_plugins]], false) + +_G._packer.inside_compile = false +if _G._packer.needs_bufread == true then + vim.cmd("doautocmd BufRead") +end +_G._packer.needs_bufread = false + if should_profile then save_profiles() end end)