Full refactor of codebase and usage of lazyvim opts setting. Also split code in custom plugins

This commit is contained in:
2025-08-29 12:30:41 +02:00
parent 524673abfc
commit e37215ae97
33 changed files with 1075 additions and 1381 deletions

View File

@@ -0,0 +1,15 @@
return {
"ellisonleao/gruvbox.nvim",
config = function()
-- Useful for terminal emulators with a transparent background
local function transparentBackground()
vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
end
vim.cmd.colorscheme("gruvbox")
transparentBackground()
end
}

26
lua/plugins/custom.lua Normal file
View File

@@ -0,0 +1,26 @@
-- Custom modules
--- @param name string
--- @return string
local function get_dir(name)
return vim.fn.stdpath("config") .. "/lua/custom/" .. name
end
return {
{
dir = get_dir("todo"),
name = "todo",
dependencies = { "nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim" },
config = function()
require("custom.todo").setup()
end,
},
{
dir = vim.fn.stdpath("config") .. "/lua/custom", -- folder containing typst.lua
name = "typst",
dependencies = { "nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim" },
keys = {
{ "<leader>tw", function() require("custom.typst").Watch_and_open() end, desc = "Watch Typst" },
},
},
}

View File

@@ -1,27 +0,0 @@
return {
{"sindrets/diffview.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons",
},
},
{
-- this is the nvim tree but I dont use it yet
"nvim-tree/nvim-tree.lua",
},
{
'nvim-lualine/lualine.nvim',
-- dependencies = { 'nvim-tree/nvim-web-devicons' }
},
{
"ellisonleao/gruvbox.nvim",
},
{
"folke/which-key.nvim",
event = "VeryLazy",
opts = {
icons = {mappings = false,},
delay = 1500,
},
},
};

92
lua/plugins/git.lua Normal file
View File

@@ -0,0 +1,92 @@
return {
{
"kdheepak/lazygit.nvim",
lazy = true,
cmd = {
"LazyGit",
"LazyGitConfig",
"LazyGitCurrentFile",
"LazyGitFilter",
"LazyGitFilterCurrentFile",
},
dependencies = {
"nvim-lua/plenary.nvim", -- Floating boarders
},
keys = {
{ "<leader>lg", "<cmd>LazyGit<cr>", desc = "LazyGit" }
}
},
{
'lewis6991/gitsigns.nvim',
config = function()
local gitsigns = require("gitsigns")
local function on_attach(bufnr)
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
map('n', ']c', function()
if vim.wo.diff then
vim.cmd.normal({ ']c', bang = true })
else
gitsigns.nav_hunk('next')
end
vim.cmd("normal! zz") -- center cursor
end, { silent = true })
map('n', '[c', function()
if vim.wo.diff then
vim.cmd.normal({ '[c', bang = true })
else
gitsigns.nav_hunk('prev')
end
vim.cmd("normal! zz") -- center cursor
end, { silent = true })
-- Actions
map('n', '<leader>hs', gitsigns.stage_hunk)
map('n', '<leader>hr', gitsigns.reset_hunk)
map('v', '<leader>hs', function()
gitsigns.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') })
end)
map('v', '<leader>hr', function()
gitsigns.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') })
end)
map('n', '<leader>hS', gitsigns.stage_buffer)
map('n', '<leader>hR', gitsigns.reset_buffer)
map('n', '<leader>hp', gitsigns.preview_hunk)
map('n', '<leader>hi', gitsigns.preview_hunk_inline)
map('n', '<leader>hb', function()
gitsigns.blame_line({ full = true })
end)
map('n', '<leader>hd', gitsigns.diffthis)
map('n', '<leader>hD', function()
gitsigns.diffthis('~')
end)
map('n', '<leader>hQ', function() gitsigns.setqflist('all') end)
map('n', '<leader>hq', gitsigns.setqflist)
-- Toggles
map('n', '<leader>tb', gitsigns.toggle_current_line_blame)
map('n', '<leader>tw', gitsigns.toggle_word_diff)
-- Text object
map({ 'o', 'x' }, 'ih', gitsigns.select_hunk)
end
gitsigns.setup({ on_attach = on_attach })
end
}
}

View File

@@ -1,9 +0,0 @@
local plugins = {}
if vim.g.diffm then
vim.list_extend(plugins, require("plugins.diff"))
else
vim.list_extend(plugins, require("plugins.main"))
end
return plugins

123
lua/plugins/lsp.lua Normal file
View File

@@ -0,0 +1,123 @@
return {
{ "stevearc/aerial.nvim", opts = {} },
{
"nvimdev/lspsaga.nvim",
opts = {
lightbulb = {
enable = false,
enable_in_insert = false,
sign = false,
virtual_text = false,
},
},
},
{
"neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"nvimdev/lspsaga.nvim",
"hrsh7th/cmp-path",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
},
config = function()
local lspconfig = require("lspconfig")
-- Declarative important have npm and other tools installed
local servers = { "gopls", "pyright", "lua_ls", "rust_analyzer", "clangd" }
-- Custom overwrites for servers
local server_settings = {
lua_ls = {
settings = {
Lua = {
diagnostics = { globals = { "vim" } },
},
},
},
}
local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args) require("luasnip").lsp_expand(args.body) end,
},
mapping = cmp.mapping.preset.insert({
["<C-Space>"] = cmp.mapping.complete(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping.select_next_item(),
["<S-Tab>"] = cmp.mapping.select_prev_item(),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
}, {
{ name = "buffer" },
{ name = "path" },
}),
})
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local on_attach = function(_, bufnr)
local opts = { buffer = bufnr, noremap = true, silent = true }
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
--vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, opts)
vim.keymap.set("n", "<leader>lq", vim.diagnostic.setloclist, opts)
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set("n", "<leader>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set("n", "<leader>ff", function()
vim.lsp.buf.format({ async = true })
end, opts)
end
-- Setup servers manually
for _, server in ipairs(servers) do
local config = {
capabilities = capabilities,
on_attach = on_attach,
}
if server_settings[server] then
config = vim.tbl_deep_extend("force", config, server_settings[server])
end
lspconfig[server].setup(config)
end
-- Mason for autoinstall of servers
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = servers,
automatic_installation = true,
})
-- Add text in diagnostics
vim.diagnostic.config({
virtual_text = true,
})
end,
},
}

17
lua/plugins/luasnip.lua Normal file
View File

@@ -0,0 +1,17 @@
return {
{
"L3MON4D3/LuaSnip",
version = "v2.*",
build = "make install_jsregexp",
event = "InsertEnter",
config = function()
local ls = require("luasnip")
ls.config.setup({
enable_autosnippets = true,
store_selection_keys = '<Tab>',
})
vim.keymap.set({ "i", "s" }, "<C-L>", function() ls.jump(1) end, { silent = true })
vim.keymap.set({ "i", "s" }, "<C-H>", function() ls.jump(-1) end, { silent = true })
end,
},
}

View File

@@ -1,238 +0,0 @@
return {
{
"ThePrimeagen/harpoon",
},
{ "akinsho/toggleterm.nvim", config = true },
{ "nvimdev/lspsaga.nvim", config = true },
{
"kdheepak/lazygit.nvim",
lazy = true,
cmd = {
"LazyGit",
"LazyGitConfig",
"LazyGitCurrentFile",
"LazyGitFilter",
"LazyGitFilterCurrentFile",
},
-- optional for floating window border decoration
dependencies = {
"nvim-lua/plenary.nvim",
},
-- setting the keybinding for LazyGit with 'keys' is recommended in
-- order to load the plugin when the command is run for the first time
keys = {
{ "<leader>lg", "<cmd>LazyGit<cr>", desc = "LazyGit" }
}},
{
-- treesitter
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
-- prio is needed for this
--
-- not needed cmd = { "NvimTreeToggle", "NvimTreeOpen" }, -- load only when you call these commands
priority = 1000,
config = function ()
local configs = require("nvim-treesitter.configs")
configs.setup({
ensure_installed = {"css", "typst", "bash", "markdown", "lua", "python", "rust", "c", "nix"},
sync_install = false,
highlight = { enable = true },
indent = { enable = true },
})
end
},
{
-- great typstar works only with luasnip
ft = {"typst"},
"Ascyii/typstar",
dev = true,
config = function()
require("typstar").setup({
typstarRoot = "~/projects/typstar",
rnote = {
assetsDir = 'assets',
-- can be modified to e.g. export full pages; default is to try to export strokes only and otherwise export the entire document
exportCommand = 'rnote-cli export selection --no-background --no-pattern --on-conflict overwrite --output-file %s all %s || rnote-cli export doc --no-background --no-pattern --on-conflict overwrite --output-file %s %s',
filename = 'drawing-%Y-%m-%d-%H-%M-%S',
fileExtension = '.rnote',
fileExtensionInserted = '.rnote.svg', -- valid rnote export type
uriOpenCommand = 'xdg-open', -- see comment above for excalidraw
templatePath = {},
},
})
end,
},
{'romgrk/barbar.nvim',
dependencies = {
'lewis6991/gitsigns.nvim', -- OPTIONAL: for git status
--'nvim-tree/nvim-web-devicons', -- OPTIONAL: for file icons
},
init = function() vim.g.barbar_auto_setup = false end,
cmd = {"BufferNext", "BufferPrevious" },
opts = {
clickable = false,
tabpages = false,
animations = false,
icons = { filetype = { enabled = false } }
},
version = '^1.0.0', -- optional: only update when a new 1.x version is released
},
-- Does not work in nvim ?
-- {"freitass/todo.txt-vim"},
-- {
-- 'windwp/nvim-autopairs',
-- enable = false,
-- event = "InsertEnter",
-- config = true
-- -- use opts = {} for passing setup options
-- -- this is equivalent to setup({}) function
-- },
{
'nvim-lualine/lualine.nvim',
-- dependencies = { 'nvim-tree/nvim-web-devicons' }
},
{
"ibhagwan/fzf-lua",
-- optional for icon support
-- dependencies = { "nvim-tree/nvim-web-devicons" },
-- or if using mini.icons/mini.nvim
-- dependencies = { "echasnovski/mini.icons" },
opts = {},
cmd = { "FzfLua" }, -- load when you call :Telekasten
},
{
-- this is the nvim tree but I dont use it yet
"nvim-tree/nvim-tree.lua",
},
{
"nvim-telescope/telescope.nvim", tag = '0.1.8',
dependencies = { "nvim-lua/plenary.nvim" },
},
{
"ellisonleao/gruvbox.nvim",
},
-- Will see how this integrates with the existing workflow and what features I can impleemtn by
-- {
-- "nvim-neorg/neorg",
-- lazy = false, -- Disable lazy loading as some `lazy.nvim` distributions set `lazy = true` by default
-- version = "*", -- Pin Neorg to the latest stable release
-- config = true,
-- },
-- Disable lsp stuff
--{
-- -- lsp stuff
-- "williamboman/mason.nvim",
-- -- TODO: implement things like rename variables and stuff
-- "williamboman/mason-lspconfig.nvim",
-- "neovim/nvim-lspconfig",
--},
{
-- LuaSnip configuration
"L3MON4D3/LuaSnip",
version = "v2.*",
build = "make install_jsregexp",
event = "InsertEnter",
config = function()
local ls = require("luasnip")
ls.config.setup({
enable_autosnippets = true,
store_selection_keys = '<Tab>',
})
vim.keymap.set({"i", "s"}, "<C-L>", function() ls.jump(1) end, {silent = true})
vim.keymap.set({"i", "s"}, "<C-H>", function() ls.jump(-1) end, {silent = true})
end,
},
-- {
-- "hrsh7th/nvim-cmp",
-- event = "InsertEnter",
-- dependencies = {
-- "hrsh7th/cmp-nvim-lsp",
-- "hrsh7th/cmp-buffer",
-- "hrsh7th/cmp-path",
-- "hrsh7th/cmp-cmdline",
-- "L3MON4D3/LuaSnip",
-- "saadparwaiz1/cmp_luasnip",
-- },
-- config = function()
-- local cmp = require("cmp")
-- local luasnip = require("luasnip")
--
-- cmp.setup({
-- completion = {
-- autocomplete = false,
-- },
-- snippet = {
-- expand = function(args)
-- require("luasnip").lsp_expand(args.body)
-- end,
-- },
-- mapping = {
-- ["<Tab>"] = cmp.mapping(function(fallback)
-- if cmp.visible() then
-- cmp.select_next_item()
-- elseif luasnip.expand_or_jumpable() then
-- luasnip.expand_or_jump()
-- else
-- cmp.complete()
-- vim.defer_fn(function()
-- if cmp.visible() then cmp.select_next_item() end
-- end, 10)
-- end
-- end, { "i", "s" }),
-- ["<S-Tab>"] = cmp.mapping(function(fallback)
-- if cmp.visible() then
-- cmp.select_prev_item()
-- elseif luasnip.jumpable(-1) then
-- luasnip.jump(-1)
-- else
-- fallback()
-- end
-- end, { "i", "s" }),
-- ["<CR>"] = cmp.mapping.confirm({ select = true }),
-- },
-- sources = cmp.config.sources({
-- { name = "nvim_lsp" },
-- { name = "luasnip" },
-- }, {
-- { name = "buffer" },
-- }),
-- })
-- end,
-- },
{
'Ascyii/telekasten.nvim',
dev = true,
},
{
"folke/which-key.nvim",
event = "VeryLazy",
opts = {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
icons = {mappings = false,},
-- set this delay so that its only used for
delay = 1500,
},
},
-- LSP support
{ "neovim/nvim-lspconfig" },
{ "stevearc/aerial.nvim", opts = {} },
{ "williamboman/mason.nvim", config = true },
{ "williamboman/mason-lspconfig.nvim" },
-- Autocompletion
{ "hrsh7th/nvim-cmp" },
{ "hrsh7th/cmp-nvim-lsp" },
{ "hrsh7th/cmp-buffer" },
{ "hrsh7th/cmp-path" },
{ "saadparwaiz1/cmp_luasnip" },
-- UI improvements
--{ "nvimdev/lspsaga.nvim", config = true },
--{ "folke/trouble.nvim", opts = {} },
--{ "j-hui/fidget.nvim", tag = "legacy", config = true },
};

26
lua/plugins/misc.lua Normal file
View File

@@ -0,0 +1,26 @@
local base_zet = "~/synced/brainstore/zettelkasten"
return {
{ "ThePrimeagen/harpoon" },
{ "akinsho/toggleterm.nvim", config = true },
{
'Ascyii/telekasten.nvim',
dev = true,
opts = {
home = vim.fn.expand(base_zet),
dailies = vim.fn.expand(base_zet .. "/daily"),
image_subdir = vim.fn.expand(base_zet .. "/media"),
weeklies = vim.fn.expand(base_zet .. "/weekly"),
templates = vim.fn.expand(base_zet .. "/templates"),
template_new_note = vim.fn.expand(base_zet .. "/templates/note.md"),
template_new_daily = vim.fn.expand(base_zet .. "/templates/daily.md"),
template_new_weekly = vim.fn.expand(base_zet .. "/templates/weekly.md"),
filename_format = "%Y%m%d%H%M-%title%",
new_note_filename = "uuid-title",
uuid_type = "%Y%m%d%H%M",
uuid_separator = "-",
}
},
};

57
lua/plugins/nvimtree.lua Normal file
View File

@@ -0,0 +1,57 @@
return {
"nvim-tree/nvim-tree.lua",
opts = {
sort_by = "case_sensitive",
view = {
width = 35,
side = "right",
preserve_window_proportions = true,
number = false,
relativenumber = false,
},
update_focused_file = {
enable = false,
},
renderer = {
group_empty = true,
highlight_git = true,
highlight_opened_files = "name",
indent_markers = {
enable = true,
},
icons = {
show = {
file = false,
folder = false,
folder_arrow = true,
git = false,
modified = false,
hidden = false,
diagnostics = false,
},
},
},
filters = {
dotfiles = false,
git_clean = false,
no_buffer = false,
custom = { ".git" },
},
git = {
enable = true,
ignore = false,
},
actions = {
open_file = {
quit_on_open = false,
resize_window = true,
},
},
}
}

11
lua/plugins/searching.lua Normal file
View File

@@ -0,0 +1,11 @@
return {
{
"ibhagwan/fzf-lua",
dependencies = { "nvim-tree/nvim-web-devicons" },
cmd = { "FzfLua" },
},
{
"nvim-telescope/telescope.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
},
}

View File

@@ -0,0 +1,14 @@
return {
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
priority = 1000, -- Load before everything else
config = function()
local configs = require("nvim-treesitter.configs")
configs.setup({
sync_install = true,
ensure_installed = { "typst" },
})
end
},
}

38
lua/plugins/typstar.lua Normal file
View File

@@ -0,0 +1,38 @@
return {
{
"Ascyii/typstar",
dependencies = {
"L3MON4D3/LuaSnip",
"nvim-treesitter/nvim-treesitter",
},
dev = true,
ft = { "typst" },
keys = {
{
"<M-t>",
"<Cmd>TypstarToggleSnippets<CR>",
mode = { "n", "i" },
},
{
"<M-j>",
"<Cmd>TypstarSmartJump<CR>",
mode = { "s", "i" },
},
{
"<M-k>",
"<Cmd>TypstarSmartJumpBack<CR>",
mode = { "s", "i" },
},
},
config = function()
local typstar = require("typstar")
typstar.setup({
add_undo_breakpoints = true,
typstarRoot = "~/projects/typstar",
rnote = {
assetsDir = 'typst-assets',
},
})
end,
},
}

76
lua/plugins/ui.lua Normal file
View File

@@ -0,0 +1,76 @@
--- @return string
local function get_cwd()
local cwd = vim.fn.getcwd()
local home = os.getenv("HOME")
if cwd:sub(1, #home) == home then
return "~" .. cwd:sub(#home + 1)
else
return cwd
end
end
return {
{
"folke/which-key.nvim",
event = "VeryLazy",
opts = {
icons = { mappings = false, },
delay = 1500,
},
},
{
'nvim-lualine/lualine.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' },
opts = {
options = {
icons_enabled = false,
theme = 'gruvbox',
component_separators = { left = '', right = '' },
section_separators = { left = '', right = '' },
always_divide_middle = true,
always_show_tabline = true,
globalstatus = false,
refresh = {
statusline = 300,
tabline = 300,
winbar = 300,
}
},
sections = {
lualine_a = { 'mode' },
lualine_b = { 'branch', 'diff', 'diagnostics' },
lualine_c = { get_cwd, 'filename' },
lualine_x = { 'encoding', 'fileformat', 'filetype' },
lualine_y = { 'progress' },
lualine_z = { 'location' }
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = { 'filename' },
lualine_x = { 'location' },
lualine_y = {},
lualine_z = {}
},
extensions = { "nvim-tree" }
}
},
{
'romgrk/barbar.nvim',
dependencies = {
'lewis6991/gitsigns.nvim',
'nvim-tree/nvim-web-devicons',
},
init = function() vim.g.barbar_auto_setup = false end,
cmd = { "BufferNext", "BufferPrevious" },
opts = {
clickable = false,
tabpages = false,
animations = false,
icons = { filetype = { enabled = false } }
},
version = '^1.0.0', -- only update when a new 1.x version is released
},
}