diff --git a/home/features/coding/default.nix b/home/features/coding/default.nix index f3f814b..83835d9 100644 --- a/home/features/coding/default.nix +++ b/home/features/coding/default.nix @@ -1,6 +1,6 @@ {pkgs, ...}: { imports = [ - ./nvim.nix + ./nvim ./vscode.nix ./intellij.nix ]; diff --git a/home/features/coding/nvim.nix b/home/features/coding/nvim.nix deleted file mode 100644 index 241bd75..0000000 --- a/home/features/coding/nvim.nix +++ /dev/null @@ -1,34 +0,0 @@ -{ - config, - lib, - pkgs, - vars, - ... -}: let -in { - programs.neovim = { - enable = true; - }; - - home = { - file.".config/nvim/lua/custom/" = { - source = ../../../rsc/config/nvim; - recursive = true; - }; - - packages = with pkgs; [ - gcc - black - python310Packages.debugpy # is this working? - mypy - ruff - nodePackages.pyright - clang-tools_16 - rnix-lsp - rust-analyzer - nodePackages.eslint_d - nodePackages.jsonlint - alejandra - ]; - }; -} diff --git a/home/features/coding/nvim/default.nix b/home/features/coding/nvim/default.nix new file mode 100644 index 0000000..6f089d4 --- /dev/null +++ b/home/features/coding/nvim/default.nix @@ -0,0 +1,154 @@ +{ + config, + lib, + pkgs, + # vars, + ... +}: let + vars = import ../../../../vars.nix; + colors = config.colorScheme.colors; +in { + programs.neovim = { + enable = true; + + viAlias = true; + vimAlias = true; + vimdiffAlias = true; + + extraPackages = with pkgs; [ + # LSP + lua-language-server + lua + rnix-lsp # nix + + # Formatters + stylua # lua + black # pyton + alejandra # nix + clang-tools_16 # c/c++ + + # Linters + ruff # python + nodePackages.jsonlint # json + nodePackages.eslint_d # javascript + + # Tools + xclip + wl-clipboard + fzf + gcc + ]; + + plugins = with pkgs.vimPlugins; [ + { + plugin = neodev-nvim; + type = "lua"; + config = '' + require("neodev").setup({ + override = function(root_dir, library) + if root_dir:find("/home/${vars.user + "/" + vars.dir_name}", 1, true) == 1 then + library.enabled = true + library.plugins = true + end + end, + }) + ''; + } + + { + plugin = nvim-lspconfig; + config = builtins.readFile ./plugin/lsp.lua; + type = "lua"; + } + + { + plugin = comment-nvim; + config = "require('Comment').setup()"; + type = "lua"; + } + + nvim-cmp + { + plugin = nvim-cmp; + config = builtins.readFile ./plugin/cmp.lua; + type = "lua"; + } + + { + plugin = telescope-nvim; + config = builtins.readFile ./plugin/telescope.lua; + type = "lua"; + } + + telescope-fzf-native-nvim + telescope-ui-select-nvim + + cmp_luasnip + cmp-nvim-lsp + + luasnip + friendly-snippets + + { + plugin = nvim-treesitter.withAllGrammars; + config = builtins.readFile ./plugin/treesitter.lua; + type = "lua"; + } + + vim-nix + + { + plugin = nvim-base16; + config = '' + require('base16-colorscheme').setup({ + base00 = '#${colors.base00}', base01 = '#${colors.base01}', base02 = '#${colors.base02}', base03 = '#${colors.base03}', + base04 = '#${colors.base04}', base05 = '#${colors.base05}', base06 = '#${colors.base06}', base07 = '#${colors.base07}', + base08 = '#${colors.base08}', base09 = '#${colors.base09}', base0A = '#${colors.base0A}', base0B = '#${colors.base0B}', + base0C = '#${colors.base0C}', base0D = '#${colors.base0D}', base0E = '#${colors.base0E}', base0F = '#${colors.base0F}', + })''; + type = "lua"; + } + + { + plugin = lualine-nvim; + config = builtins.readFile ./plugin/lualine.lua; + type = "lua"; + } + + nvim-web-devicons + plenary-nvim + nui-nvim + { + plugin = neo-tree-nvim; + type = "lua"; + } + + { + plugin = gitsigns-nvim; + config = "require('gitsigns').setup()"; + type = "lua"; + } + + diffview-nvim + lazygit-nvim + + { + plugin = todo-comments-nvim; + config = builtins.readFile ./plugin/todo.lua; + type = "lua"; + } + + { + plugin = alpha-nvim; + config = builtins.readFile ./plugin/alpha.lua; + type = "lua"; + } + + { + plugin = none-ls-nvim; + config = builtins.readFile ./plugin/none-ls.lua; + type = "lua"; + } + ]; + }; +} diff --git a/home/features/coding/nvim/options.lua b/home/features/coding/nvim/options.lua new file mode 100644 index 0000000..eebabfa --- /dev/null +++ b/home/features/coding/nvim/options.lua @@ -0,0 +1,18 @@ +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +vim.o.clipboard = "unnamedplus" + +vim.o.number = true +vim.o.relativenumber = true + +vim.o.signcolumn = "yes" + +vim.o.tabstop = 4 +vim.o.shiftwidth = 4 + +vim.o.updatetime = 300 + +vim.o.termguicolors = true + +vim.o.mouse = "a" diff --git a/home/features/coding/nvim/plugin/alpha.lua b/home/features/coding/nvim/plugin/alpha.lua new file mode 100644 index 0000000..2c1b43d --- /dev/null +++ b/home/features/coding/nvim/plugin/alpha.lua @@ -0,0 +1,32 @@ +local dashboard = require("alpha.themes.dashboard") +local function button(sc, txt, keybind, keybind_opts) + local b = dashboard.button(sc, txt, keybind, keybind_opts) + b.opts.hl = "Identifier" + b.opts.hl_shortcut = "Identifier" + return b +end + +dashboard.section.buttons.val = { + button("r", " > Recent files", ":Telescope oldfiles"), + button("n", " > New file", ":ene startinsert "), + button("f", " > Find files", ":Telescope find_files hidden=true"), + button("u", " > Update plugins", ":PackerSync"), + button("q", " > Quit Neovim", ":qa"), +} +dashboard.section.footer.val = require("alpha.fortune") +dashboard.section.header.val = { + [[ ███▄ █ ▓█████ ▒█████ ██▒ █▓ ██▓ ███▄ ▄███▓]], + [[ ██ ▀█ █ ▓█ ▀ ▒██▒ ██▒▓██░ █▒▓██▒▓██▒▀█▀ ██▒]], + [[▓██ ▀█ ██▒▒███ ▒██░ ██▒ ▓██ █▒░▒██▒▓██ ▓██░]], + [[▓██▒ ▐▌██▒▒▓█ ▄ ▒██ ██░ ▒██ █░░░██░▒██ ▒██ ]], + [[▒██░ ▓██░░▒████▒░ ████▓▒░ ▒▀█░ ░██░▒██▒ ░██▒]], + [[░ ▒░ ▒ ▒ ░░ ▒░ ░░ ▒░▒░▒░ ░ ▐░ ░▓ ░ ▒░ ░ ░]], + [[░ ░░ ░ ▒░ ░ ░ ░ ░ ▒ ▒░ ░ ░░ ▒ ░░ ░ ░]], + [[ ░ ░ ░ ░ ░ ░ ░ ▒ ░░ ▒ ░░ ░ ]], + [[ ░ ░ ░ ░ ░ ░ ░ ░ ]], + [[ ░ ]], +} + +dashboard.section.header.opts.hl = "Function" +dashboard.section.footer.opts.hl = "Function" +require("alpha").setup(require("alpha.themes.dashboard").opts) diff --git a/home/features/coding/nvim/plugin/cmp.lua b/home/features/coding/nvim/plugin/cmp.lua new file mode 100644 index 0000000..8a009cc --- /dev/null +++ b/home/features/coding/nvim/plugin/cmp.lua @@ -0,0 +1,46 @@ +local cmp = require("cmp") +local luasnip = require("luasnip") + +require("luasnip.loaders.from_vscode").lazy_load() +luasnip.config.setup({}) + +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete({}), + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }), + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + }, +}) diff --git a/home/features/coding/nvim/plugin/lsp.lua b/home/features/coding/nvim/plugin/lsp.lua new file mode 100644 index 0000000..9fe3f1a --- /dev/null +++ b/home/features/coding/nvim/plugin/lsp.lua @@ -0,0 +1,45 @@ +local on_attach = function(_, bufnr) + local bufmap = function(keys, func) + vim.keymap.set("n", keys, func, { buffer = bufnr }) + end + + bufmap("r", vim.lsp.buf.rename) + bufmap("a", vim.lsp.buf.code_action) + + bufmap("gd", vim.lsp.buf.definition) + bufmap("gD", vim.lsp.buf.declaration) + bufmap("gI", vim.lsp.buf.implementation) + bufmap("D", vim.lsp.buf.type_definition) + + bufmap("gr", require("telescope.builtin").lsp_references) + bufmap("s", require("telescope.builtin").lsp_document_symbols) + bufmap("S", require("telescope.builtin").lsp_dynamic_workspace_symbols) + + bufmap("K", vim.lsp.buf.hover) + + vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_) + vim.lsp.buf.format() + end, {}) +end + +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) + +require("lspconfig").lua_ls.setup({ + on_attach = on_attach, + capabilities = capabilities, + root_dir = function() + return vim.loop.cwd() + end, + settings = { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + }, + }, +}) + +require("lspconfig").rnix.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) diff --git a/home/features/coding/nvim/plugin/lualine.lua b/home/features/coding/nvim/plugin/lualine.lua new file mode 100644 index 0000000..8116074 --- /dev/null +++ b/home/features/coding/nvim/plugin/lualine.lua @@ -0,0 +1,10 @@ +local lualine = require("lualine") + +local config = { + options = { + theme = "base16", + globalstatus = true, + }, +} + +lualine.setup(config) diff --git a/home/features/coding/nvim/plugin/none-ls.lua b/home/features/coding/nvim/plugin/none-ls.lua new file mode 100644 index 0000000..6ae5eb0 --- /dev/null +++ b/home/features/coding/nvim/plugin/none-ls.lua @@ -0,0 +1,37 @@ +local null_ls = require("null-ls") +local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + +local opts = { + sources = { + -- Lua + null_ls.builtins.formatting.stylua, + -- Python + null_ls.builtins.formatting.black, + null_ls.builtins.diagnostics.ruff, + -- Javascript + null_ls.builtins.diagnostics.eslint_d, + null_ls.builtins.diagnostics.jsonlint, + -- C/C++ + null_ls.builtins.formatting.clang_format, + -- Nix + null_ls.builtins.formatting.alejandra, + }, + on_attach = function(client, bufnr) + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ + group = augroup, + buffer = bufnr, + }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ bufnr = bufnr }) + end, + }) + end + end, +} + +null_ls.setup(opts) +vim.keymap.set("n", "gf", vim.lsp.buf.format, {}) diff --git a/home/features/coding/nvim/plugin/other.lua b/home/features/coding/nvim/plugin/other.lua new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/home/features/coding/nvim/plugin/other.lua @@ -0,0 +1 @@ + diff --git a/home/features/coding/nvim/plugin/telescope.lua b/home/features/coding/nvim/plugin/telescope.lua new file mode 100644 index 0000000..88d3eba --- /dev/null +++ b/home/features/coding/nvim/plugin/telescope.lua @@ -0,0 +1,20 @@ +require("telescope").setup({ + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, -- override the generic sorter + override_file_sorter = true, -- override the file sorter + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + -- the default case_mode is "smart_case" + ["ui-select"] = { + require("telescope.themes").get_dropdown({}), + }, + }, + }, +}) + +require("telescope").load_extension("fzf") +require("telescope").load_extension("ui-select") +local builtin = require("telescope.builtin") +vim.keymap.set("n", "", builtin.find_files, {}) +vim.keymap.set("n", "fg", builtin.live_grep, {}) diff --git a/home/features/coding/nvim/plugin/todo.lua b/home/features/coding/nvim/plugin/todo.lua new file mode 100644 index 0000000..bd6863f --- /dev/null +++ b/home/features/coding/nvim/plugin/todo.lua @@ -0,0 +1,55 @@ +require("todo-comments").setup({ + signs = true, + sign_priority = 8, + keywords = { + FIX = { + icon = " ", -- icon used for the sign, and in search results + color = "error", -- can be a hex color, or a named color (see below) + alt = { "FIXME", "BUG", "FIXIT", "ISSUE" }, -- a set of other keywords that all map to this FIX keywords + -- signs = false, -- configure signs for some keywords individually + }, + TODO = { icon = " ", color = "info" }, + HACK = { icon = " ", color = "warning" }, + WARN = { icon = " ", color = "warning", alt = { "WARNING", "XXX" } }, + PERF = { icon = "󰑮 ", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } }, + NOTE = { icon = " ", color = "hint", alt = { "INFO" } }, + TEST = { icon = "󰤑 ", color = "test", alt = { "TESTING", "PASSED", "FAILED" } }, + }, + gui_style = { + fg = "NONE", -- The gui style to use for the fg highlight group. + bg = "BOLD", -- The gui style to use for the bg highlight group. + }, + merge_keywords = true, -- when true, custom keywords will be merged with the defaults + highlight = { + multiline = true, -- enable multine todo comments + multiline_pattern = "^.", -- lua pattern to match the next multiline from the start of the matched keyword + multiline_context = 10, -- extra lines that will be re-evaluated when changing a line + before = "", -- "fg" or "bg" or empty + keyword = "wide", -- "fg", "bg", "wide", "wide_bg", "wide_fg" or empty. (wide and wide_bg is the same as bg, but will also highlight surrounding characters, wide_fg acts accordingly but with fg) + after = "fg", -- "fg" or "bg" or empty + pattern = [[.*<(KEYWORDS)\s*:]], -- pattern or table of patterns, used for highlighting (vim regex) + comments_only = true, -- uses treesitter to match keywords in comments only + max_line_len = 400, -- ignore lines longer than this + exclude = {}, -- list of file types to exclude highlighting + }, + colors = { + error = { "DiagnosticError", "ErrorMsg", "#DC2626" }, + warning = { "DiagnosticWarn", "WarningMsg", "#FBBF24" }, + info = { "DiagnosticInfo", "#2563EB" }, + hint = { "DiagnosticHint", "#10B981" }, + default = { "Identifier", "#7C3AED" }, + test = { "Identifier", "#FF00FF" }, + }, + search = { + command = "rg", + args = { + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + }, + -- pattern = [[\b(KEYWORDS):]], -- ripgrep regex + pattern = [[\b(KEYWORDS)\b]], -- match without the extra colon. + }, +}) diff --git a/home/features/coding/nvim/plugin/treesitter.lua b/home/features/coding/nvim/plugin/treesitter.lua new file mode 100644 index 0000000..1a873cf --- /dev/null +++ b/home/features/coding/nvim/plugin/treesitter.lua @@ -0,0 +1,9 @@ +require("nvim-treesitter.configs").setup({ + ensure_installed = {}, + + auto_install = false, + + highlight = { enable = true }, + + indent = { enable = true }, +})