Compare commits

...

7 Commits

5 changed files with 302 additions and 153 deletions

7
.stylua.toml Normal file
View File

@ -0,0 +1,7 @@
column_width = 120
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferDouble"
call_parentheses = "Always"
collapse_simple_statement = "Never"

View File

@ -666,6 +666,22 @@
"type": "github" "type": "github"
} }
}, },
"nvim-treesitter-textsubjects": {
"flake": false,
"locked": {
"lastModified": 1676144693,
"narHash": "sha256-4jb9v0xpO17wp85dzojKUQ6hUdNBx3T2tB4fSWoANus=",
"owner": "RRethy",
"repo": "nvim-treesitter-textsubjects",
"rev": "b913508f503527ff540f7fe2dcf1bf1d1f259887",
"type": "github"
},
"original": {
"owner": "RRethy",
"repo": "nvim-treesitter-textsubjects",
"type": "github"
}
},
"pre-commit-hooks": { "pre-commit-hooks": {
"inputs": { "inputs": {
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
@ -757,6 +773,7 @@
"neovim": "neovim", "neovim": "neovim",
"nil": "nil", "nil": "nil",
"nixpkgs": "nixpkgs_8", "nixpkgs": "nixpkgs_8",
"nvim-treesitter-textsubjects": "nvim-treesitter-textsubjects",
"pre-commit-hooks": "pre-commit-hooks_3", "pre-commit-hooks": "pre-commit-hooks_3",
"stable": "stable", "stable": "stable",
"utils": "utils_2" "utils": "utils_2"

View File

@ -56,6 +56,11 @@
hyprland.url = "github:hyprwm/Hyprland"; hyprland.url = "github:hyprwm/Hyprland";
hyprpaper.url = "github:hyprwm/hyprpaper"; hyprpaper.url = "github:hyprwm/hyprpaper";
hypr-contrib.url = "github:hyprwm/contrib"; hypr-contrib.url = "github:hyprwm/contrib";
nvim-treesitter-textsubjects = {
url = "github:RRethy/nvim-treesitter-textsubjects";
flake = false;
};
}; };
outputs = outputs =

View File

@ -1,12 +1,27 @@
{ config { config
, lib , lib
, pkgs , pkgs
, inputs
, ... , ...
}: }:
with lib; with lib;
let let
cfg = config.my.programs.vim; cfg = config.my.programs.vim;
mkDate = longDate: (lib.concatStringsSep "-" [
(builtins.substring 0 4 longDate)
(builtins.substring 4 2 longDate)
(builtins.substring 6 2 longDate)
]);
mkVersionInput = input: mkDate (input.lastModifiedDate or "19700101") + "_" + (input.shortRev or "dirty");
nvim-treesitter-textsubjects = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "nvim-treesitter-textsubjects";
version = mkVersionInput inputs.nvim-treesitter-textsubjects;
src = inputs.nvim-treesitter-textsubjects;
};
in in
{ {
options.my.programs.vim = { options.my.programs.vim = {
@ -33,20 +48,26 @@ in
plugins = with pkgs.vimPlugins; [ plugins = with pkgs.vimPlugins; [
catppuccin-nvim catppuccin-nvim
cmp-nvim-lsp cmp-nvim-lsp
cmp_luasnip
comment-nvim
dashboard-nvim dashboard-nvim
lsp_lines-nvim
lualine-lsp-progress
lualine-nvim
luasnip
neogit neogit
noice-nvim noice-nvim
nui-nvim # for noice-nvim nui-nvim # for noice-nvim
nvim-cmp nvim-cmp
nvim-lspconfig nvim-lspconfig
nvim-surround
nvim-treesitter-textsubjects
nvim-treesitter.withAllGrammars nvim-treesitter.withAllGrammars
nvim-ts-context-commentstring
nvim-web-devicons # for dashboard-nvim nvim-web-devicons # for dashboard-nvim
plenary-nvim # for telescope, neogit plenary-nvim # for telescope, neogit
telescope-nvim telescope-nvim
which-key-nvim which-key-nvim
cmp_luasnip
luasnip
lsp_lines-nvim
]; ];
}; };
}; };

View File

@ -4,7 +4,7 @@ vim.g.maplocalleader = ","
-- FIX to create spell dir if not existent -- FIX to create spell dir if not existent
local spelldir = vim.fn.stdpath("data") .. "/site/spell" local spelldir = vim.fn.stdpath("data") .. "/site/spell"
if not vim.loop.fs_stat(spelldir) then if not vim.loop.fs_stat(spelldir) then
vim.fn.mkdir(spelldir, "p") vim.fn.mkdir(spelldir, "p")
end end
vim.opt.autoindent = true vim.opt.autoindent = true
@ -34,100 +34,103 @@ vim.opt_local.spell = true
vim.opt_local.spelllang = { "en", "de_20" } -- all English regions and new German spelling vim.opt_local.spelllang = { "en", "de_20" } -- all English regions and new German spelling
require("catppuccin").setup({ require("catppuccin").setup({
compile_path = vim.fn.stdpath("cache") .. "/catppuccin", -- fix issue of writing to nix store compile_path = vim.fn.stdpath("cache") .. "/catppuccin", -- fix issue of writing to nix store
integrations = { integrations = {
which_key = true, which_key = true,
}, },
}) })
vim.cmd.colorscheme("catppuccin-macchiato") vim.cmd.colorscheme("catppuccin-macchiato")
vim.o.timeout = true vim.o.timeout = true
vim.o.timeoutlen = 300 vim.o.timeoutlen = 500
local wk = require("which-key") local wk = require("which-key")
require("noice").setup({ require("noice").setup({
lsp = { lsp = {
-- override markdown rendering so that **cmp** and other plugins use **Treesitter** -- override markdown rendering so that **cmp** and other plugins use **Treesitter**
override = { override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true, ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true, ["vim.lsp.util.stylize_markdown"] = true,
["cmp.entry.get_documentation"] = true, ["cmp.entry.get_documentation"] = true,
}, },
}, progress = {
-- you can enable a preset for easier configuration enabled = false,
presets = { },
bottom_search = true, -- use a classic bottom cmdline for search },
command_palette = true, -- position the cmdline and popupmenu together -- you can enable a preset for easier configuration
long_message_to_split = true, -- long messages will be sent to a split presets = {
inc_rename = false, -- enables an input dialog for inc-rename.nvim bottom_search = true, -- use a classic bottom cmdline for search
lsp_doc_border = false, -- add a border to hover docs and signature help command_palette = true, -- position the cmdline and popupmenu together
}, long_message_to_split = true, -- long messages will be sent to a split
inc_rename = false, -- enables an input dialog for inc-rename.nvim
lsp_doc_border = false, -- add a border to hover docs and signature help
},
}) })
wk.register({ wk.register({
f = { f = {
name = "find", name = "find",
f = { "<cmd>Telescope find_files<cr>", "find file" }, f = { "<cmd>Telescope find_files<cr>", "find file" },
g = { "<cmd>Telescope live_grep<cr>", "live grep" }, g = { "<cmd>Telescope live_grep<cr>", "live grep" },
b = { "<cmd>Telescope buffers<cr>", "find buffer" }, b = { "<cmd>Telescope buffers<cr>", "find buffer" },
}, },
}, { prefix = "<leader>" }) }, { prefix = "<leader>" })
require("neogit").setup({ require("neogit").setup({
disable_commit_confirmation = true, disable_commit_confirmation = true,
}) })
wk.register({ wk.register({
g = { "<cmd>Neogit<cr>", "git" }, g = { "<cmd>Neogit<cr>", "git" },
}, { prefix = "<leader>" }) }, { prefix = "<leader>" })
require("nvim-treesitter.configs").setup({ require("nvim-treesitter.configs").setup({
sync_install = false, sync_install = false,
auto_install = false, auto_install = false,
highlight = { highlight = {
enable = true, enable = true,
additional_vim_regex_highlighting = true, additional_vim_regex_highlighting = true,
}, },
}) })
local cmp = require("cmp") local cmp = require("cmp")
local luasnip = require("luasnip") local luasnip = require("luasnip")
cmp.setup({ cmp.setup({
snippet = { snippet = {
-- REQUIRED - you must specify a snippet engine -- REQUIRED - you must specify a snippet engine
expand = function(args) expand = function(args)
require("luasnip").lsp_expand(args.body) require("luasnip").lsp_expand(args.body)
end, end,
}, },
mapping = cmp.mapping.preset.insert({ mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4), ["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4), ["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(), ["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(), ["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. ["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback) ["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump() luasnip.expand_or_jump()
else else
fallback() fallback()
end end
end, { "i", "s" }), end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback) ["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
elseif luasnip.jumpable(-1) then elseif luasnip.jumpable(-1) then
luasnip.jump(-1) luasnip.jump(-1)
else else
fallback() fallback()
end end
end, { "i", "s" }), end, { "i", "s" }),
}), }),
sources = { sources = {
{ name = "nvim_lsp" }, { name = "nvim_lsp" },
{ name = "luasnip" }, { name = "luasnip" },
{ name = "buffer" }, { name = "buffer" },
}, },
}) })
-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers.. -- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
@ -135,99 +138,195 @@ local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
local on_attach_def = function(_, bufnr) local on_attach_def = function(_, bufnr)
wk.register({ wk.register({
K = { vim.lsp.buf.hover, "show info" }, K = { vim.lsp.buf.hover, "show info" },
["<leader>l"] = { ["<leader>l"] = {
name = "lsp", name = "lsp",
d = { vim.diagnostic.open_float, "open diagnostic window" }, d = { vim.diagnostic.open_float, "open diagnostic window" },
n = { vim.diagnostic.goto_next, "next error" }, n = { vim.diagnostic.goto_next, "next error" },
p = { vim.diagnostic.goto_prev, "prev error" }, p = { vim.diagnostic.goto_prev, "prev error" },
c = { vim.lsp.buf.code_action, "code action" }, c = { vim.lsp.buf.code_action, "code action" },
r = { vim.lsp.buf.rename, "rename" }, r = { vim.lsp.buf.rename, "rename" },
f = { f = {
function() function()
vim.lsp.buf.format({ async = true }) vim.lsp.buf.format({ async = true })
end, end,
"format", "format",
}, },
}, },
g = { g = {
name = "goto", name = "goto",
r = { vim.lsp.buf.references, "references" }, r = { vim.lsp.buf.references, "references" },
d = { vim.lsp.buf.definition, "definition" }, d = { vim.lsp.buf.definition, "definition" },
D = { vim.lsp.buf.declaration, "declaration" }, D = { vim.lsp.buf.declaration, "declaration" },
i = { vim.lsp.buf.implementation, "implementation" }, i = { vim.lsp.buf.implementation, "implementation" },
t = { vim.lsp.buf.type_definition, "type defininition" }, t = { vim.lsp.buf.type_definition, "type defininition" },
}, },
}, { noremap = true, silent = true, buffer = bufnr }) }, { noremap = true, silent = true, buffer = bufnr })
end
---merge tables
---@param ... table[]
---@return table
local function table_merge(...)
local tables_to_merge = { ... }
assert(#tables_to_merge > 1, "There should be at least two tables to merge them")
for k, t in ipairs(tables_to_merge) do
assert(type(t) == "table", string.format("Expected a table as function parameter %d", k))
end
local result = tables_to_merge[1]
for i = 2, #tables_to_merge do
local from = tables_to_merge[i]
for k, v in pairs(from) do
if type(v) == "table" then
result[k] = result[k] or {}
result[k] = table_merge(result[k], v)
else
result[k] = v
end
end
end
return result
end
local lspconfig_default_options = {
on_attach = on_attach_def,
capabilities = capabilities,
flags = {
debounce_text_changes = 100,
},
}
---function to add default options to lspconfig
---@param lsp string
---@param options table
---@return nil
local function lspconfig_setup(lsp, options)
local final_options = table_merge(lspconfig_default_options, options)
lspconfig[lsp].setup(final_options)
end end
local servers = { "nil_ls", "pylsp" } local servers = { "nil_ls", "pylsp" }
for _, lsp in ipairs(servers) do for _, lsp in ipairs(servers) do
lspconfig[lsp].setup({ lspconfig_setup(lsp, {})
on_attach = on_attach_def,
capabilities = capabilities,
flags = {
debounce_text_changes = 100,
},
})
end end
lspconfig.sumneko_lua.setup({ lspconfig_setup("lua_ls", {
on_attach = on_attach_def, on_attach = on_attach_def,
capabilities = capabilities, capabilities = capabilities,
settings = { settings = {
Lua = { Lua = {
runtime = { runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT", version = "LuaJIT",
}, },
diagnostics = { diagnostics = {
-- Get the language server to recognize the `vim` global -- Get the language server to recognize the `vim` global
globals = { "vim" }, globals = { "vim" },
}, },
workspace = { workspace = {
-- Make the server aware of Neovim runtime files -- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true), library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false, checkThirdParty = false,
}, },
-- Do not send telemetry data containing a randomized but unique identifier -- Do not send telemetry data containing a randomized but unique identifier
telemetry = { telemetry = {
enable = false, enable = false,
}, },
format = { format = {
enable = true, enable = false,
-- Put format options here },
-- NOTE: the value should be STRING!! },
defaultConfig = { },
indent_style = "space",
indent_size = "2",
},
},
},
},
}) })
local lsp_lines = require("lsp_lines") local lsp_lines = require("lsp_lines")
lsp_lines.setup() lsp_lines.setup()
-- Disable virtual_text since it's redundant due to lsp_lines. -- Disable virtual_text since it's redundant due to lsp_lines.
vim.diagnostic.config({ vim.diagnostic.config({
virtual_text = false, virtual_text = false,
}) })
wk.register({ wk.register({
t = { t = {
name = "toggle", name = "toggle",
l = { lsp_lines.toggle, "lsp lines" }, l = { lsp_lines.toggle, "lsp lines" },
}, },
{ prefix = "<leader>" }, { prefix = "<leader>" },
}) })
require("dashboard").setup({ require("dashboard").setup({
theme = "hyper", theme = "hyper",
config = { config = {
packages = { enable = true }, packages = { enable = true },
week_header = { week_header = {
enable = true, enable = true,
}, },
}, },
})
require("lualine").setup({
options = {
icons_enabled = true,
theme = "auto",
component_separators = "|",
section_separators = { left = "", right = "" },
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
},
},
sections = {
lualine_a = {
{ "mode", separator = { left = "" }, right_padding = 2 },
},
lualine_b = { "branch", "diff", "diagnostics" },
lualine_c = { "filename", "lsp_progress" },
lualine_x = { "encoding", "fileformat", "filetype" },
lualine_y = { "progress" },
lualine_z = {
{ "location", separator = { right = "" }, left_padding = 2 },
},
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = { "filename" },
lualine_x = { "location" },
lualine_y = {},
lualine_z = {},
},
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {},
})
require("Comment").setup()
require("nvim-treesitter.configs").setup({
context_commentstring = {
enable = true,
},
})
require("nvim-surround").setup({})
require("nvim-treesitter.configs").setup({
textsubjects = {
enable = true,
prev_selection = ",", -- (Optional) keymap to select the previous selection
keymaps = { ["."] = "textsubjects-smart" },
},
}) })