nvim: Stuff

This commit is contained in:
2025-08-02 12:00:01 +02:00
parent e63b1fd2e6
commit 594b3d667b
8 changed files with 696 additions and 572 deletions

View File

@ -22,7 +22,9 @@ vim.opt.rtp:prepend(lazypath)
-- TODO: get colored renders working -- TODO: get colored renders working
vim.g.rustaceanvim = { vim.g.rustaceanvim = {
-- Plugin configuration -- Plugin configuration
tools = {}, tools = {
float_win_config = { border = 'rounded' },
},
-- LSP configuration -- LSP configuration
server = { server = {
@ -36,7 +38,12 @@ vim.g.rustaceanvim = {
end, end,
default_settings = { default_settings = {
['rust-analyzer'] = { ['rust-analyzer'] = {
checkOnSave = { overrideCommand = "cargo check --message-format=json-diagnostic-rendered-ansi" }, checkOnSave = true,
check = {
overrideCommand = {
"cargo", "check", "--message-format=json-diagnostic-rendered-ansi",
}
},
}, },
}, },
settings = function(project_root) settings = function(project_root)
@ -91,13 +98,22 @@ require("mason").setup({
}, },
ensure_installed = language_servers, ensure_installed = language_servers,
}) })
require("mason-lspconfig").setup() require("mason-lspconfig").setup {
automatic_enable = {
exclude = {
-- rust_analyzer is managed by rustaceanvim
"rust_analyzer",
}
}
}
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
for _,l in pairs(language_servers) do for _, l in pairs(language_servers) do
lspconfig[l].setup {} lspconfig[l].setup {}
end end
require('dapui').setup();
local compare = require "cmp.config.compare" local compare = require "cmp.config.compare"
require('cmp').setup.filetype({ "rust" }, { require('cmp').setup.filetype({ "rust" }, {
sorting = { sorting = {
@ -127,7 +143,7 @@ require('cmp').setup.filetype({ "rust" }, {
vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]] vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]]
-- Completion Plugin Setup -- Completion Plugin Setup
local cmp = require'cmp' local cmp = require 'cmp'
cmp.setup({ cmp.setup({
-- Enable LSP snippets -- Enable LSP snippets
snippet = { snippet = {
@ -154,20 +170,20 @@ cmp.setup({
sources = { sources = {
{ name = 'path' }, -- file paths { name = 'path' }, -- file paths
{ name = 'nvim_lsp', keyword_length = 3 }, -- from language server { name = 'nvim_lsp', keyword_length = 3 }, -- from language server
{ name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized { 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 = 'nvim_lua', keyword_length = 2 }, -- complete neovim's Lua runtime API such vim.lsp.*
{ name = 'buffer', keyword_length = 2 }, -- source current buffer { name = 'buffer', keyword_length = 2 }, -- source current buffer
{ name = 'vsnip', keyword_length = 2 }, -- nvim-cmp source for vim-vsnip { name = 'vsnip', keyword_length = 2 }, -- nvim-cmp source for vim-vsnip
{ name = 'calc'}, -- source for math calculation { name = 'calc' }, -- source for math calculation
}, },
window = { window = {
completion = cmp.config.window.bordered(), completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(),
}, },
formatting = { formatting = {
fields = {'menu', 'abbr', 'kind'}, fields = { 'menu', 'abbr', 'kind' },
format = function(entry, item) format = function(entry, item)
local menu_icon ={ local menu_icon = {
nvim_lsp = 'λ', nvim_lsp = 'λ',
vsnip = '', vsnip = '',
buffer = 'Ω', buffer = 'Ω',
@ -186,7 +202,7 @@ require('nvim-treesitter.configs').setup {
auto_install = true, auto_install = true,
highlight = { highlight = {
enable = true, enable = true,
additional_vim_regex_highlighting=false, additional_vim_regex_highlighting = false,
}, },
ident = { enable = true }, ident = { enable = true },
rainbow = { rainbow = {

View File

@ -8,7 +8,7 @@ dap.adapters.codelldb = {
port = "${port}", port = "${port}",
executable = { executable = {
command = codelldb_bin, command = codelldb_bin,
args = {"--port", "${port}"}, args = { "--port", "${port}" },
} }
} }
@ -33,7 +33,7 @@ dap.configurations.cpp = {
handle:close() handle:close()
-- Trim the result -- Trim the result
pid = pid:match( "^%s*(.-)%s*$" ) pid = pid:match("^%s*(.-)%s*$")
return pid return pid
end, end,
stopOnEntry = true, stopOnEntry = true,
@ -75,7 +75,7 @@ dap.configurations.cpp = {
handle:close() handle:close()
-- Trim the result -- Trim the result
pid = pid:match( "^%s*(.-)%s*$" ) pid = pid:match("^%s*(.-)%s*$")
return pid return pid
end, end,
initCommands = { initCommands = {

View File

@ -1,15 +1,96 @@
local telescope = require('telescope.builtin') local telescope = require('telescope.builtin')
local wk = require('which-key') local wk = require('which-key')
local harpoon = require("harpoon")
local telescope_conf = require("telescope.config").values
harpoon:setup()
vim.keymap.set('n', '<leader>f', telescope.find_files, { desc = "File picker" }) vim.keymap.set('n', '<leader>f', telescope.find_files, { desc = "File picker" })
vim.keymap.set('n', '<leader>g', telescope.live_grep, { desc = "Grep recursively" }) vim.keymap.set('n', '<leader>g', telescope.live_grep, { desc = "Grep recursively" })
vim.keymap.set('n', '<leader>b', telescope.buffers, { desc = "Buffer picker" }) vim.keymap.set('n', '<leader>b', telescope.buffers, { desc = "Buffer picker" })
vim.keymap.set('n', '<leader>?', telescope.help_tags, { desc = "Help tags picker" }) vim.keymap.set('n', '<leader>?', telescope.help_tags, { desc = "Help tags picker" })
vim.keymap.set('n', '<leader>s', telescope.treesitter, { desc = "Treesitter symbol picker" }) vim.keymap.set('n', '<leader>s', telescope.treesitter, { desc = "Treesitter symbol picker" })
vim.keymap.set('n', '<leader>j', telescope.jumplist, { desc = "Jumplist" })
vim.keymap.set('n', '<leader>u', ":TodoTelescope<Enter>", { desc = "Grep for TODOs" }) vim.keymap.set('n', '<leader>u', ":TodoTelescope<Enter>", { desc = "Grep for TODOs" })
vim.keymap.set('n', 'U', ":redo<Enter>", {}) vim.keymap.set('n', 'U', ":redo<Enter>", {})
vim.keymap.set('n', '<leader>p', ":b#<Enter>", { desc = "Go to last buffer" }) vim.keymap.set('n', '<leader>p', ":b#<Enter>", { desc = "Go to last buffer" })
local function toggle_telescope(harpoon_files)
local displayer = require("telescope.pickers.entry_display").create({
separator = " | ",
items = {
--{ width = 0.1 },
{ width = 0.9 },
}
})
local harpoons = {}
for _, item in ipairs(harpoon_files.items) do
table.insert(harpoons, {
filepath = item.value,
col = item.context.col,
row = item.context.row,
})
end
require("telescope.pickers").new({}, {
prompt_title = "Harpoon",
finder = require("telescope.finders").new_table({
results = harpoons,
entry_maker = function(entry)
--vim.print("mapping entry")
--vim.print(entry)
local filepath_with_row = string.format("%s:%d", entry.filepath, entry.row)
return {
-- Value to display. Required. type=any
--value = { "foo", entry.filepath, },
value = entry,
-- Whether to display the entry. Optional. type=bool
valid = true,
-- Optional. type=string|function
--display = entry.filepath,
display = function(entry)
return displayer({
-- NOTE: the number of elements must match the
-- configuration passed to `displayer` above
--{ "foobar" },
{ filepath_with_row }
})
end,
-- Used for filtering. Optional. type=string
ordinal = filepath_with_row,
-- File to open when pressing enter. Optional. type=string
filename = entry.filepath,
-- Buffer to open when pressing enter. Optional. type=number
-- bufnr = 0,
-- Line number of file/buffer to open. Optional. type=number
lnum = entry.row,
-- Line number of file/buffer to open. Optional. type=number
col = entry.row,
}
end
}),
previewer = telescope_conf.grep_previewer({}),
sorter = telescope_conf.generic_sorter({}),
}):find()
end
vim.keymap.set("n", "<leader>h", function() toggle_telescope(harpoon:list()) end,
{ desc = "Open harpoon window" })
vim.keymap.set("n", "<leader>H", function() harpoon:list():add() end,
{ desc = "Launch harpoon" })
-- Toggle previous & next buffers stored within Harpoon list
--vim.keymap.set("n", "<C-S-P>", function() harpoon:list():prev() end)
--vim.keymap.set("n", "<C-S-N>", function() harpoon:list():next() end)
-- Use LspAttach autocommand to only map the following keys -- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer -- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', { vim.api.nvim_create_autocmd('LspAttach', {
@ -22,14 +103,19 @@ vim.api.nvim_create_autocmd('LspAttach', {
-- See `:help vim.lsp.*` for documentation on any of the below functions -- See `:help vim.lsp.*` for documentation on any of the below functions
vim.keymap.set('n', '<leader>ld', telescope.lsp_definitions, { desc = "Show definitons", buffer = ev.buf }) vim.keymap.set('n', '<leader>ld', telescope.lsp_definitions, { desc = "Show definitons", buffer = ev.buf })
vim.keymap.set('n', '<leader>lr', telescope.lsp_references, { desc = "Show references", buffer = ev.buf }) vim.keymap.set('n', '<leader>lr', telescope.lsp_references, { desc = "Show references", buffer = ev.buf })
vim.keymap.set('n', '<leader>li', telescope.lsp_implementations, { desc = "Show implementations", buffer = ev.buf }) vim.keymap.set('n', '<leader>li', telescope.lsp_implementations,
vim.keymap.set('n', '<leader>lt', telescope.lsp_type_definitions, { desc = "Show type definitions", buffer = ev.buf }) { desc = "Show implementations", buffer = ev.buf })
vim.keymap.set('n', '<leader>lt', telescope.lsp_type_definitions,
{ desc = "Show type definitions", buffer = ev.buf })
vim.keymap.set('n', '<leader>le', telescope.diagnostics, { desc = "Show diagnostics", buffer = ev.buf }) vim.keymap.set('n', '<leader>le', telescope.diagnostics, { desc = "Show diagnostics", buffer = ev.buf })
vim.keymap.set('n', '<leader>ls', telescope.lsp_workspace_symbols, { desc = "Show workspace symbols", buffer = ev.buf }) vim.keymap.set('n', '<leader>ls', telescope.lsp_workspace_symbols,
{ desc = "Show workspace symbols", buffer = ev.buf })
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = ev.buf }) vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = ev.buf })
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, { buffer = ev.buf }) vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, { buffer = ev.buf })
vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, { desc = "Add workspace folder", buffer = ev.buf }) vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder,
vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, { desc = "Remove workspace folder", buffer = ev.buf }) { desc = "Add workspace folder", buffer = ev.buf })
vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder,
{ desc = "Remove workspace folder", buffer = ev.buf })
vim.keymap.set('n', '<leader>wl', function() vim.keymap.set('n', '<leader>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, { desc = "List workspace folders", buffer = ev.buf }) end, { desc = "List workspace folders", buffer = ev.buf })
@ -40,7 +126,6 @@ vim.api.nvim_create_autocmd('LspAttach', {
{ "<leader>l", desc = "Language server stuff" }, { "<leader>l", desc = "Language server stuff" },
{ "<leader>w", desc = "Workspace stuff" }, { "<leader>w", desc = "Workspace stuff" },
}) })
end, end,
}) })

View File

@ -1,7 +1,7 @@
local opt = vim.opt local opt = vim.opt
-- Use system clipboard -- Use system clipboard
vim.opt.clipboard="unnamedplus" vim.opt.clipboard = "unnamedplus"
-- [[ Context ]] -- [[ Context ]]
opt.colorcolumn = '100' -- str: Show col for max line length opt.colorcolumn = '100' -- str: Show col for max line length
@ -13,7 +13,7 @@ opt.signcolumn = "yes" -- str: Show the sign column
-- [[ Filetypes ]] -- [[ Filetypes ]]
opt.encoding = 'utf8' -- str: String encoding to use opt.encoding = 'utf8' -- str: String encoding to use
-- opt.fileencoding = 'utf8' -- str: File encoding to use -- opt.fileencoding = 'utf8' -- str: File encoding to use
vim.filetype.add({extension = {wgsl = "wgsl"}}) vim.filetype.add({ extension = { wgsl = "wgsl" } })
-- [[ Theme ]] -- [[ Theme ]]
opt.syntax = "ON" -- str: Allow syntax highlighting opt.syntax = "ON" -- str: Allow syntax highlighting
@ -43,11 +43,10 @@ opt.splitbelow = true -- bool: Place new window below the current one
-- noselect: Do not select, force to select one from the menu -- noselect: Do not select, force to select one from the menu
-- shortness: avoid showing extra messages when using completion -- shortness: avoid showing extra messages when using completion
-- updatetime: set updatetime for CursorHold -- updatetime: set updatetime for CursorHold
vim.opt.completeopt = {'menuone', 'noselect', 'noinsert'} vim.opt.completeopt = { 'menuone', 'noselect', 'noinsert' }
vim.opt.shortmess = vim.opt.shortmess + { c = true} vim.opt.shortmess = vim.opt.shortmess + { c = true }
vim.api.nvim_set_option('updatetime', 300) vim.api.nvim_set_option('updatetime', 300)
-- Uncomment to enable treesitter folding by default -- Uncomment to enable treesitter folding by default
--vim.wo.foldmethod = 'expr' --vim.wo.foldmethod = 'expr'
--vim.wo.foldexpr = 'nvim_treesitter#foldexpr()' --vim.wo.foldexpr = 'nvim_treesitter#foldexpr()'

View File

@ -48,6 +48,20 @@ require("lazy").setup({
words = { enabled = true }, words = { enabled = true },
}, },
}, },
{
"folke/flash.nvim",
event = "VeryLazy",
---@type Flash.Config
opts = {},
-- stylua: ignore
keys = {
{ "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" },
{ "S", mode = { "n", "x", "o" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" },
{ "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" },
{ "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" },
{ "<c-s>", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" },
},
},
-- -- language server stuff -- -- language server stuff
{ 'williamboman/mason.nvim' }, { 'williamboman/mason.nvim' },
@ -55,10 +69,13 @@ require("lazy").setup({
{ 'neovim/nvim-lspconfig' }, { 'neovim/nvim-lspconfig' },
{ {
'mrcjkb/rustaceanvim', 'mrcjkb/rustaceanvim',
version = '^4', version = '^6',
lazy = false, -- This plugin is already lazy lazy = false, -- This plugin is already lazy
}, },
{ 'mfussenegger/nvim-dap' }, { 'mfussenegger/nvim-dap' },
{ 'rcarriga/nvim-dap-ui', dependencies = { 'mfussenegger/nvim-dap', 'nvim-neotest/nvim-nio' } },
{ 'theHamsta/nvim-dap-virtual-text' },
{ 'jay-babu/mason-nvim-dap.nvim' },
-- -- nushell support -- -- nushell support
-- --use { 'LhKipp/nvim-nu', run = function() vim.fn[':TSInstall nu'] end} } -- --use { 'LhKipp/nvim-nu', run = function() vim.fn[':TSInstall nu'] end} }
@ -79,9 +96,16 @@ require("lazy").setup({
{ 'hrsh7th/vim-vsnip' }, { 'hrsh7th/vim-vsnip' },
{ 'ryo33/nvim-cmp-rust' }, { 'ryo33/nvim-cmp-rust' },
{ 'nvim-telescope/telescope.nvim', branch = '0.1.x', {
'nvim-telescope/telescope.nvim',
branch = '0.1.x',
dependencies = { 'nvim-lua/plenary.nvim' } dependencies = { 'nvim-lua/plenary.nvim' }
}, },
{
"ThePrimeagen/harpoon",
branch = "harpoon2",
dependencies = { "nvim-lua/plenary.nvim" }
},
-- -- status line -- -- status line
{ 'linrongbin16/lsp-progress.nvim' }, { 'linrongbin16/lsp-progress.nvim' },
@ -93,6 +117,6 @@ require("lazy").setup({
-- automatically check for plugin updates -- automatically check for plugin updates
checker = { checker = {
enabled = true, enabled = true,
notify=false, notify = false,
}, },
}) })

View File

@ -16,8 +16,8 @@ require('lualine').setup {
options = { options = {
icons_enabled = true, icons_enabled = true,
theme = 'auto', theme = 'auto',
component_separators = { left = '', right = ''}, component_separators = { left = '', right = '' },
section_separators = { left = '', right = ''}, section_separators = { left = '', right = '' },
disabled_filetypes = { disabled_filetypes = {
statusline = {}, statusline = {},
winbar = {}, winbar = {},
@ -32,22 +32,22 @@ require('lualine').setup {
} }
}, },
sections = { sections = {
lualine_a = {'mode'}, lualine_a = { 'mode' },
lualine_b = {'branch', 'diff', 'diagnostics'}, lualine_b = { 'branch', 'diff', 'diagnostics' },
lualine_c = {'filename'}, lualine_c = { 'filename' },
lualine_x = { lualine_x = {
function() function()
return require('lsp-progress').progress() return require('lsp-progress').progress()
end end
}, },
lualine_y = {'encoding', 'fileformat', 'filetype'}, lualine_y = { 'encoding', 'fileformat', 'filetype' },
lualine_z = {'location'} lualine_z = { 'location' }
}, },
inactive_sections = { inactive_sections = {
lualine_a = {}, lualine_a = {},
lualine_b = {}, lualine_b = {},
lualine_c = {'filename'}, lualine_c = { 'filename' },
lualine_x = {'location'}, lualine_x = { 'location' },
lualine_y = {}, lualine_y = {},
lualine_z = {} lualine_z = {}
}, },