dotfiles/nvim/.config/nvim/init.lua
2025-12-28 19:44:16 +01:00

114 lines
4.1 KiB
Lua

vim.g.mapleader = " "
vim.opt.clipboard:append("unnamedplus")
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git", "clone", "--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
lazypath
})
end
vim.opt.rtp:prepend(lazypath)
-- Plugin-Setup
require("lazy").setup("plugins")
-- Ensure nvim-lspconfig is loaded
local lspconfig = require('lspconfig')
-- Define the corrected command to run Perl::LanguageServer inside the Distrobox
-- Replace 'perl-ls-debian' with the actual name of your Distrobox container
local perl_ls_cmd = {
'distrobox',
'enter',
'perl-ls-debian',
'--', -- This separates distrobox commands from the command to run inside
'perl',
'-MPerl::LanguageServer',
'-e',
[[Perl::LanguageServer->run("--stdio")]] -- Use Lua long string literal
}
-- Configure perlpls (Perl::LanguageServer)
lspconfig.perlpls.setup({
cmd = perl_ls_cmd,
settings = {
pls = {
inc = {
"${workspaceFolder}/lib",
"${workspaceFolder}/os-autoinst/lib",
},
perlcritic = {
enabled = true,
perlcriticrc = '${workspaceFolder}/.perlcriticrc',
},
perltidy = {
perltidyrc = '${workspaceFolder}/.perltidyrc',
},
}
},
on_attach = function(client, bufnr)
-- IMPORTANT: Remove the line `require('lspconfig.util').default_on_attach(client, bufnr)`
-- Set options for the buffer (e.g., enable completion, formatting)
-- Many of these are now handled by Neovim's LSP client automatically,
-- but you can explicitly enable them if needed.
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- for C-x C-o completion
-- Basic LSP keymaps (you can customize these)
local opts = { noremap=true, silent=true }
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>f', '<cmd>lua vim.lsp.buf.format()<CR>', opts)
-- Example: Set up automatic formatting on save (if the LSP server supports it)
if client.supports_method('textDocument/formatting') then
vim.api.nvim_create_autocmd('BufWritePre', {
group = vim.api.nvim_create_augroup('LspFormatting' .. bufnr, { clear = true }),
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ bufnr = bufnr, async = false })
end,
})
end
-- You can add more client capabilities here, for example with nvim-cmp:
-- require('cmp_nvim_lsp').setup_client(client)
end,
})
vim.api.nvim_create_user_command('OrgYtDl', function()
local url = vim.fn.expand('<cfile>')
if url:match('^https?://') then
vim.fn.jobstart({ 'yt-dlp', url }, {
stdout_buffered = true,
on_stdout = function(_, data)
if data then
print(table.concat(data, '\n'))
end
end,
on_stderr = function(_, data)
if data then
print('[yt-dlp] error:', table.concat(data, '\n'))
end
end,
})
else
print('No link under cursor.')
end
end, {})
-- Kopiert visuell markierten Text ins Clipboard mit <leader>y
vim.keymap.set("v", "<leader>y", '"+y', { desc = "Yank selection to system clipboard" })
vim.keymap.set('n', '<leader>oy', ':OrgYtDl<CR>', { desc = 'yt-dlp link under cursor' })