Integrate neovim config into home-manager, separate external configs under config/

This commit is contained in:
2026-04-07 18:32:08 +02:00
parent d9ef3b056e
commit 5403b4988e
49 changed files with 7286 additions and 50 deletions
+105
View File
@@ -0,0 +1,105 @@
vim.g.run__cmd = function(cmd, opts)
-- Runs a command either locally on a server using ssh. For running on a server define the 'server' option. The
-- 'server_cwd' option might be set as well to define the working directory on the server.
--@param cmd table
--@param opt table
opts = opts or {};
opts.server_cwd = (opts.server_cwd or "~");
if opts.server ~= nil then
local cmdstr = table.concat(cmd, " ");
cmd = { "ssh", opts.server, "cd " .. opts.server_cwd .. " && " .. cmdstr };
end
local result = vim.system(cmd, { text = true }):wait();
if result.code ~= 0 then
error("\n" .. result.code .. "\n" .. result.stdout .. "\n" .. result.stderr);
end
vim.print(result.stdout);
end
vim.g.run__gen_path = function(identifier)
-- Generates a path in /tmp/ based on the identifier and a hash function.
--@param identifier string
local hash = vim.fn.sha256(identifier);
return "/tmp/rsyncrun/" .. string.sub(hash, 1, 12) .. "/";
end
vim.g.run__file = function(filename, opts)
-- Executes a file based on the vim file type and predefined commands. Options might be set that will be parsed
-- to the vim.g.run__cmd function.
--@param filename string
--@param opts table
local cmd = {
python = function() vim.g.run__cmd({ "python3", filename }, opts) end,
go = function() vim.g.run__cmd({ "go", "run", filename }, opts) end,
lua = function()
vim.cmd("source " .. filename); vim.print("Sourced current file.");
end,
};
local ft = vim.filetype.match({ filename = filename })
if cmd[ft] == nil
then
print("No run command defined for filetype '" .. vim.bo.filetype .. "'.");
else
cmd[vim.bo.filetype]();
end
end
vim.g.run__current_file = function(opts)
-- Executes the currently opened file based on the vim file type and predefined commands. Options might be set
-- that will be parsed to the vim.g.run__cmd function.
--@param opts table
local filename = vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf());
if filename == "" then return; end;
vim.cmd.write();
vim.g.run__file(filename, opts);
end
vim.g.run__file_on_server = function(filename, opts)
-- Runs a given file on a server after rsyncing the current directory to the server. The cmd is executed in the
-- rsync directory on the server. Use the 'rsync_dst_host' option to define the server. The command to run is
-- defined by the vim.g.run__file function.
--@param filename string
--@param opts table
local rsync_opts = {};
opts = opts or {};
rsync_opts.rsync_src_dir = (opts.rsync_src_dir or vim.loop.cwd());
rsync_opts.rsync_dst_dir = (opts.rsync_dst_dir or vim.g.run__gen_path(rsync_opts.rsync_src_dir));
rsync_opts.rsync_dst_host = (opts.rsync_dst_host or error("rsync_dst_host option is required"));
vim.print("syncing to server...");
vim.g.run__cmd({ "mkdir", "-p", rsync_opts.rsync_dst_dir }, { server = rsync_opts.rsync_dst_host });
vim.g.run__cmd(
{ "rsync", "-r", rsync_opts.rsync_src_dir .. "/", rsync_opts.rsync_dst_host ..
":" .. rsync_opts.rsync_dst_dir .. "/" }, {});
vim.print("...done.");
vim.g.run__file(filename, { server = rsync_opts.rsync_dst_host, server_cwd = rsync_opts.rsync_dst_dir });
end
vim.g.run__current_file_on_server = function(opts)
-- Runs the currently opened file on a server after rsyncing the current directory to the server. The cmd is
-- executed in the rsync directory on the server. Use the 'rsync_dst_host' option to define the server. The
-- command to run is defined by the vim.g.run__file function.
--@param opts table
local filename = vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf());
if filename == "" then return; end;
vim.cmd.write();
filename = filename:match("^.+/(.+)$") or filename
vim.g.run__file_on_server(filename, opts);
end
+33
View File
@@ -0,0 +1,33 @@
local vim = vim
local Plug = vim.fn["plug#"]
vim.call("plug#begin")
---------
Plug("morhetz/gruvbox") -- Theme
Plug("vimwiki/vimwiki")
Plug("tpope/vim-fugitive") -- Git support
Plug("ThePrimeagen/harpoon")
Plug("nvim-lua/plenary.nvim") -- required for telescope
Plug("nvim-telescope/telescope.nvim")
Plug("junegunn/goyo.vim")
Plug("nvim-treesitter/nvim-treesitter", { ["do"] = ":TSUpdate" })
-- LSP
Plug("neovim/nvim-lspconfig")
Plug("hrsh7th/cmp-nvim-lsp")
Plug("hrsh7th/cmp-buffer")
Plug("hrsh7th/cmp-path")
Plug("hrsh7th/cmp-cmdline")
Plug("hrsh7th/nvim-cmp")
-- Debugger
Plug("mfussenegger/nvim-dap")
Plug("mfussenegger/nvim-dap-python")
Plug("nvim-neotest/nvim-nio") -- required by dap-ui
Plug("rcarriga/nvim-dap-ui")
---------
vim.call("plug#end")
+22
View File
@@ -0,0 +1,22 @@
vim.keymap.set("n", "<leader>pv", vim.cmd.Ex)
vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<C-u>", "<C-u>zz")
vim.keymap.set("n", "n", "nzzzv")
vim.keymap.set("n", "N", "Nzzzv")
vim.keymap.set("n", "<leader>d", "\"_d")
vim.keymap.set("v", "<leader>d", "\"_d")
vim.keymap.set("n", "<leader>f", vim.lsp.buf.format)
vim.keymap.set("n", "<leader>s", ":%s/\\<<C-r><C-w>\\>/<C-r><C-w>/gI<Left><Left><Left>")
vim.keymap.set("n", "<leader>x", "<cmd>!chmod +x %<CR>", { silent = true })
-- spell checking
vim.keymap.set("n", "<leader>o", "<cmd>setlocal spell! spelllang=de_de<CR>")
vim.keymap.set("n", "<leader>e", "<cmd>setlocal spell! spelllang=en_en<CR>")
vim.keymap.set("n", "<leader>O", "<cmd>setlocal nospell!<CR>")
-- script run command
vim.keymap.set("n", "<leader>r", vim.g.run__current_file, { noremap = true, silent = true })
+29
View File
@@ -0,0 +1,29 @@
vim.opt.nu = true
vim.opt.relativenumber = true
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.smartindent = true
vim.opt.incsearch = true
vim.opt.scrolloff = 8
vim.opt.signcolumn = "yes"
vim.opt.isfname:append("@-@")
vim.opt.updatetime = 50
vim.opt.colorcolumn = "120"
vim.opt.clipboard = "unnamedplus"
vim.g.mapleader = " "
vim.opt.completeopt = {'menu', 'menuone', 'noselect'}
-- Enable filetype detection
vim.cmd('filetype on')
vim.cmd('filetype plugin on')