diff options
Diffstat (limited to 'modules/tools/neovim')
| -rw-r--r-- | modules/tools/neovim/config/default.nix | 4 | ||||
| -rw-r--r-- | modules/tools/neovim/config/keybindings.lua | 5 | ||||
| -rw-r--r-- | modules/tools/neovim/config/options.lua | 41 | ||||
| -rw-r--r-- | modules/tools/neovim/default.nix | 36 | ||||
| -rw-r--r-- | modules/tools/neovim/plugins/config/base16.mustache.lua | 12 | ||||
| -rw-r--r-- | modules/tools/neovim/plugins/config/comment.lua | 1 | ||||
| -rw-r--r-- | modules/tools/neovim/plugins/config/default.nix | 27 | ||||
| -rw-r--r-- | modules/tools/neovim/plugins/config/dressing.lua | 1 | ||||
| -rw-r--r-- | modules/tools/neovim/plugins/config/lsp-config.lua | 75 | ||||
| -rw-r--r-- | modules/tools/neovim/plugins/config/lualine.mustache.lua | 61 | ||||
| -rw-r--r-- | modules/tools/neovim/plugins/config/noice.mustache.lua | 10 | ||||
| -rw-r--r-- | modules/tools/neovim/plugins/config/nvim-tree.lua | 15 | ||||
| -rw-r--r-- | modules/tools/neovim/plugins/config/nvim-ufo.lua | 21 | ||||
| -rw-r--r-- | modules/tools/neovim/plugins/config/treesitter.nix | 13 | ||||
| -rw-r--r-- | modules/tools/neovim/plugins/config/which-key.lua | 5 | ||||
| -rw-r--r-- | modules/tools/neovim/plugins/default.nix | 31 |
16 files changed, 358 insertions, 0 deletions
diff --git a/modules/tools/neovim/config/default.nix b/modules/tools/neovim/config/default.nix new file mode 100644 index 0000000..4514d2f --- /dev/null +++ b/modules/tools/neovim/config/default.nix @@ -0,0 +1,4 @@ +'' +${builtins.readFile ./options.lua} +${builtins.readFile ./keybindings.lua} +'' diff --git a/modules/tools/neovim/config/keybindings.lua b/modules/tools/neovim/config/keybindings.lua new file mode 100644 index 0000000..3f2c9bf --- /dev/null +++ b/modules/tools/neovim/config/keybindings.lua @@ -0,0 +1,5 @@ +-- Navigate splits +vim.keymap.set("n", "<C-h>", ":wincmd h<CR>", { silent = true }); +vim.keymap.set("n", "<C-j>", ":wincmd j<CR>", { silent = true }); +vim.keymap.set("n", "<C-k>", ":wincmd k<CR>", { silent = true }); +vim.keymap.set("n", "<C-l>", ":wincmd l<CR>", { silent = true }); diff --git a/modules/tools/neovim/config/options.lua b/modules/tools/neovim/config/options.lua new file mode 100644 index 0000000..fc0b04c --- /dev/null +++ b/modules/tools/neovim/config/options.lua @@ -0,0 +1,41 @@ +vim.g.mapleader = " "; +vim.g.maplocalleader = " "; + +vim.o.clipboard = "unnamedplus"; + +vim.o.number = true; +vim.o.list = true; +vim.o.listchars = "tab:| ,trail:_,lead:_"; + +vim.o.laststatus = 3; + +vim.o.signcolumn = "auto"; +vim.opt.fillchars = { eob = " " }; + +vim.o.tabstop = 3; +vim.o.shiftwidth = 0; +vim.o.expandtab = false; + +vim.o.updatetime = 300; + +vim.o.mouse = "a"; + +-- Force all filetypes to use tabs +vim.api.nvim_create_autocmd("FileType", { + pattern = "*", + callback = function() + vim.bo.expandtab = false; + vim.bo.tabstop = 3; + vim.bo.shiftwidth = 0; + end, +}); + +-- Exception that use spaces +vim.api.nvim_create_autocmd("FileType", { + pattern = { "yaml" }, + callback = function() + vim.bo.expandtab = true; + vim.bo.tabstop = 2; + vim.bo.shiftwidth = 2; + end, +}); diff --git a/modules/tools/neovim/default.nix b/modules/tools/neovim/default.nix new file mode 100644 index 0000000..2c0b7aa --- /dev/null +++ b/modules/tools/neovim/default.nix @@ -0,0 +1,36 @@ +{ pkgs, config, lib, ... }: + +{ + options.tools.neovim = { + enable = lib.mkEnableOption "Enables neovim."; + profile = lib.mkOption { + type = lib.types.enum [ + "minimal" + "full" + ]; + default = "minimal"; + description = "The profile for neovim to use."; + }; + }; + + config = + let + plugins = import ./plugins { inherit config pkgs lib; }; + in lib.mkIf config.tools.neovim.enable { + programs.neovim.enable = true; + programs.neovim.viAlias = true; + programs.neovim.vimAlias = true; + programs.neovim.vimdiffAlias = true; + programs.neovim.defaultEditor = true; + + home.packages = plugins.requirements; + + programs.neovim.extraLuaConfig = + '' +${import ./config} +${plugins.configuration} + ''; + + programs.neovim.plugins = plugins.list; + }; +} diff --git a/modules/tools/neovim/plugins/config/base16.mustache.lua b/modules/tools/neovim/plugins/config/base16.mustache.lua new file mode 100644 index 0000000..3c13fcc --- /dev/null +++ b/modules/tools/neovim/plugins/config/base16.mustache.lua @@ -0,0 +1,12 @@ +vim.o.termguicolors = true; +vim.opt.termguicolors = true; +vim.o.background = "dark"; +vim.g.base16colorspace = 256 +vim.cmd.colorscheme("base16-scheme"); + +-- Overrides +-- disable the background of line numbers +vim.api.nvim_set_hl(0, "LineNr", { link = "Normal" }); + +-- change the color of the pane separator +vim.api.nvim_set_hl(0, "WinSeparator", { fg = "#{{base02-hex}}", bg = "None" }); diff --git a/modules/tools/neovim/plugins/config/comment.lua b/modules/tools/neovim/plugins/config/comment.lua new file mode 100644 index 0000000..9086261 --- /dev/null +++ b/modules/tools/neovim/plugins/config/comment.lua @@ -0,0 +1 @@ +require("Comment").setup(); diff --git a/modules/tools/neovim/plugins/config/default.nix b/modules/tools/neovim/plugins/config/default.nix new file mode 100644 index 0000000..9ae2485 --- /dev/null +++ b/modules/tools/neovim/plugins/config/default.nix @@ -0,0 +1,27 @@ +{ config }: + +let + fullExtra = if config.tools.neovim.profile == "full" then +'' +${builtins.readFile ./lsp-config.lua} +${builtins.readFile ./dressing.lua} +${builtins.readFile (config.scheme { + template = builtins.readFile ./noice.mustache.lua; +})} +${builtins.readFile ./nvim-ufo.lua} +${builtins.readFile ./which-key.lua} +'' + else ""; +in +'' +${builtins.readFile ./comment.lua} +${builtins.readFile (config.scheme { + template = builtins.readFile ./lualine.mustache.lua; +})} +${import ./treesitter.nix { inherit config; }} +${builtins.readFile (config.scheme { + template = builtins.readFile ./base16.mustache.lua; +})} +${builtins.readFile ./nvim-tree.lua} +${fullExtra} +'' diff --git a/modules/tools/neovim/plugins/config/dressing.lua b/modules/tools/neovim/plugins/config/dressing.lua new file mode 100644 index 0000000..6d14d47 --- /dev/null +++ b/modules/tools/neovim/plugins/config/dressing.lua @@ -0,0 +1 @@ +require("dressing").setup(); diff --git a/modules/tools/neovim/plugins/config/lsp-config.lua b/modules/tools/neovim/plugins/config/lsp-config.lua new file mode 100644 index 0000000..cca4116 --- /dev/null +++ b/modules/tools/neovim/plugins/config/lsp-config.lua @@ -0,0 +1,75 @@ +local lspconfig = require("lspconfig"); + +local filetype_to_lsp = { + lua = { server = "lua_ls", executable = "lua-language-server" }, + cpp = { server = "clangd", executable = "clangd" }, + c = { server = "clangd", executable = "clangd" }, + python = { server = "pyright", executable = "pyright-langserver" }, + javascript = { server = "tsserver", executable = "typescript-language-server" }, + typescript = { server = "tsserver", executable = "typescript-language-server" }, + go = { server = "gopls", executable = "gopls" }, + html = { server = "html", executable = "vscode-html-language-server" }, + css = { server = "cssls", executable = "vscode-css-language-server" }, + json = { server = "jsonls", executable = "vscode-json-language-server" }, + bash = { server = "bashls", executable = "bash-language-server" }, + graphql = { server = "graphql", executable = "graphql-lsp" }, + dockerfile = { server = "dockerls", executable = "docker-langserver" }, + php = { server = "phpactor", executable = "phpactor" }, + rust = { server = "rust_analyzer", executable = "rust-analyzer" }, + haskell = { server = "hls", executable = "haskell-language-server-wrapper" }, + deno = { server = "denols", executable = "deno" }, + vim = { server = "vimls", executable = "vim-language-server" }, + elixir = { server = "elixirls", executable = "elixir-ls" }, + clojure = { server = "clojure_lsp", executable = "clojure-lsp" }, + scala = { server = "scala_metals", executable = "metals" }, + ruby = { server = "sorbet", executable = "srb" }, + zig = { server = "zls", executable = "zls" }, + kotlin = { server = "kotlin_language_server", executable = "kotlin-language-server" }, + java = { server = "jdtls", executable = "jdtls" }, + dart = { server = "dartls", executable = "dart" }, + yaml = { server = "yamlls", executable = "yaml-language-server" }, + perl = { server = "perlls", executable = "perl" }, + r = { server = "r_language_server", executable = "R" }, + tex = { server = "texlab", executable = "texlab" }, + swift = { server = "sourcekit", executable = "sourcekit-lsp" }, + svelte = { server = "svelteserver", executable = "svelteserver" }, + terraform = { server = "terraformls", executable = "terraform-ls" }, + vue = { server = "vls", executable = "vls" }, + markdown = { server = "marksman", executable = "marksman" }, + yaml = { server = "yamlls", executable = "yaml-language-server" }, +}; + +-- Keeping track of all the lsps that have been already configured +local lsp_setup_done = {}; + +-- Function to setup LSP based on filetype +local function setup_lsp(filetype) + local lsp = filetype_to_lsp[filetype]; + if lsp ~= nil and not lsp_setup_done[lsp.server] then + lsp_setup_done[lsp.server] = true; + if vim.fn.executable(lsp.executable) == 1 then + lspconfig[lsp.server].setup({}); + end + end +end + +vim.api.nvim_create_autocmd("FileType", { + pattern = "*", -- Match all file types + callback = function() + setup_lsp(vim.bo.filetype); -- Call the setup_lsp function only if the filetype is in the mapping + end, +}); + +-- Show diagnostics in a floating window when hovering over the line +vim.api.nvim_create_autocmd("CursorHold", { + callback = function() + vim.diagnostic.open_float(nil, { focusable = false }) + end, +}) + +local lsp_keymap_opts = { noremap = true, silent = true }; + +vim.keymap.set("n", "<leader>d", vim.lsp.buf.definition, lsp_keymap_opts); +vim.keymap.set("n", "<leader>i", vim.lsp.buf.implementation, lsp_keymap_opts); +vim.keymap.set("n", "<leader>r", vim.lsp.buf.references, lsp_keymap_opts); +vim.keymap.set("n", "<leader>k", vim.lsp.buf.hover, lsp_keymap_opts); diff --git a/modules/tools/neovim/plugins/config/lualine.mustache.lua b/modules/tools/neovim/plugins/config/lualine.mustache.lua new file mode 100644 index 0000000..bf4f1d1 --- /dev/null +++ b/modules/tools/neovim/plugins/config/lualine.mustache.lua @@ -0,0 +1,61 @@ +local lualine_theme = { + normal = { + a = { fg = "#{{base0D-hex}}", bg = "none", gui = "bold" }, + b = { fg = "#{{base05-hex}}", bg = "none" }, + c = { fg = "#{{base05-hex}}", bg = "none" }, + }, + insert = { + a = { fg = "#{{base0B-hex}}", bg = "none", gui = "bold" }, + }, + visual = { + a = { fg = "#{{base0E-hex}}", bg = "none", gui = "bold" }, + }, + replace = { + a = { fg = "#{{base08-hex}}", bg = "none", gui = "bold" }, + }, + command = { + a = { fg = "#{{base0A-hex}}", bg = "none", gui = "bold" }, + }, + inactive = { + a = { fg = "#{{base04-hex}}", bg = "none" }, + b = { fg = "#{{base04-hex}}", bg = "none" }, + c = { fg = "#{{base04-hex}}", bg = "none" }, + }, +}; + +local function macro_recording() + local recording_register = vim.fn.reg_recording() + if recording_register ~= "" then + return "@" .. recording_register + else + return "" + end +end + +require("lualine").setup { + options = { + icons_enabled = true, + theme = lualine_theme, + section_separators = "", + component_separators = "", + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { + "branch", + { + "diff", + colored = true, + symbols = { + added = " ", + modified = " ", + removed = " ", + } + } + }, + lualine_c = { "filename" }, + lualine_x = { macro_recording, "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" }, + }, +}; diff --git a/modules/tools/neovim/plugins/config/noice.mustache.lua b/modules/tools/neovim/plugins/config/noice.mustache.lua new file mode 100644 index 0000000..a258c8e --- /dev/null +++ b/modules/tools/neovim/plugins/config/noice.mustache.lua @@ -0,0 +1,10 @@ +require("noice").setup(); + +vim.api.nvim_set_hl(0, "NoiceCommandOutput", { fg = "#{{base05-hex}}", bg = "#{{base00-hex}}" }); +vim.api.nvim_set_hl(0, "NoiceCmdline", { fg = "#{{base05-hex}}", bg = "#{{base00-hex}}" }); +vim.api.nvim_set_hl(0, "NoiceCmdlinePopup", { fg = "#{{base05-hex}}", bg = "#{{base00-hex}}" }); +vim.api.nvim_set_hl(0, "NoiceCmdlinePopupBorder", { fg = "#{{base03-hex}}", bg = "#{{base00-hex}}" }); +vim.api.nvim_set_hl(0, "NoiceError", { fg = "#{{base08-hex}}", bg = "#{{base00-hex}}" }); +vim.api.nvim_set_hl(0, "NoiceWarning", { fg = "#{{base0A-hex}}", bg = "#{{base00-hex}}" }); +vim.api.nvim_set_hl(0, "NoiceInfo", { fg = "#{{base0C-hex}}", bg = "#{{base00-hex}}" }); +vim.api.nvim_set_hl(0, "NoiceHint", { fg = "#{{base0B-hex}}", bg = "#{{base00-hex}}" }); diff --git a/modules/tools/neovim/plugins/config/nvim-tree.lua b/modules/tools/neovim/plugins/config/nvim-tree.lua new file mode 100644 index 0000000..cdbef6a --- /dev/null +++ b/modules/tools/neovim/plugins/config/nvim-tree.lua @@ -0,0 +1,15 @@ +require("nvim-tree").setup { + filters = { + enable = false + }, + renderer = { + indent_markers = { + enable = true + }, + root_folder_label = function(path) + return vim.fn.fnamemodify(path, ":t") + end, + }, +}; + +vim.keymap.set("n", "<C-n>", ":NvimTreeToggle<CR>", { silent = true }); diff --git a/modules/tools/neovim/plugins/config/nvim-ufo.lua b/modules/tools/neovim/plugins/config/nvim-ufo.lua new file mode 100644 index 0000000..641373f --- /dev/null +++ b/modules/tools/neovim/plugins/config/nvim-ufo.lua @@ -0,0 +1,21 @@ +require("ufo").setup { + provider_selector = function(bufnr, filetype, buftype) + return { + "treesitter", + "indent" + } + end, +}; + +vim.o.foldenable = true +vim.o.foldcolumn = '0' +vim.o.foldlevel = 99 -- Ensure all folds start open +vim.o.foldlevelstart = 99 + +-- press <Shift>K or capslockK +vim.keymap.set("n", "<S-K>", function() + local winid = ufo.peekFoldedLinesUnderCursor() + if not winid then + vim.lsp.buf.hover() + end +end) diff --git a/modules/tools/neovim/plugins/config/treesitter.nix b/modules/tools/neovim/plugins/config/treesitter.nix new file mode 100644 index 0000000..be0bdb6 --- /dev/null +++ b/modules/tools/neovim/plugins/config/treesitter.nix @@ -0,0 +1,13 @@ +{ config }: + +'' +require("nvim-treesitter.configs").setup { + auto_install = true, + highlight = { + enable = true, + }, + parser_install_dir = "${config.xdg.dataHome}/nvim", +}; + +vim.opt.runtimepath:append("${config.xdg.dataHome}/nvim"); +'' diff --git a/modules/tools/neovim/plugins/config/which-key.lua b/modules/tools/neovim/plugins/config/which-key.lua new file mode 100644 index 0000000..1290432 --- /dev/null +++ b/modules/tools/neovim/plugins/config/which-key.lua @@ -0,0 +1,5 @@ +local wk = require("which-key"); + +vim.keymap.set("n", "<leader>h", function() + wk.show({ global = true }) +end, { silent = true }); diff --git a/modules/tools/neovim/plugins/default.nix b/modules/tools/neovim/plugins/default.nix new file mode 100644 index 0000000..b06cb24 --- /dev/null +++ b/modules/tools/neovim/plugins/default.nix @@ -0,0 +1,31 @@ +{ config, pkgs, lib }: + +{ + configuration = import ./config { inherit config; }; + + list = with pkgs.vimPlugins; lib.mkMerge [ + [ + comment-nvim + lualine-nvim + nvim-treesitter + nvim-web-devicons + nvim-tree-lua + which-key-nvim + (base16-vim.overrideAttrs (old: { + patchPhase = "ln -s ${config.scheme base16-vim} colors/base16-scheme.vim"; + })) + ] + (if config.tools.neovim.profile == "full" then + [ + noice-nvim + dressing-nvim + nvim-lspconfig + nvim-ufo + ] + else []) + ]; + + requirements = with pkgs; [ + gcc # for treesitter + ]; +} |
