### Nix Development Shell Setup Source: https://github.com/birnxnet/nixvim2/blob/main/README.md Clones the NixVim2 repository and enters the development shell using Nix. This is the primary setup for local development and contribution. ```bash git clone https://github.com/khaneliman/khanelivim.git cd khanelivim nix develop ``` -------------------------------- ### Example Commit Messages for Khanelivim Source: https://github.com/birnxnet/nixvim2/blob/main/CONTRIBUTING.md This snippet illustrates the component-based commit message convention used in Khanelivim. It shows examples of how to structure messages to clearly indicate the affected component and the nature of the change, promoting clarity and organization in the project's commit history. ```git # Update a deprecated setting in the conform module conform: update deprecated setting # Fix a duplicate package in the treesitter module treesitter: fix duplicate package # Update the flake.lock file flake.lock: update ``` -------------------------------- ### Integrate Khanelivim with Home Manager (Nix) Source: https://context7.com/birnxnet/nixvim2/llms.txt This Nix configuration integrates Khanelivim into your Home Manager setup. It specifies Nixpkgs and Home Manager as inputs and adds Khanelivim to your user's packages, ensuring it's available in your environment. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; home-manager.url = "github:nix-community/home-manager"; khanelivim.url = "github:khaneliman/khanelivim"; }; outputs = { nixpkgs, home-manager, khanelivim, ... }: { homeConfigurations.username = home-manager.lib.homeManagerConfiguration { pkgs = nixpkgs.legacyPackages.x86_64-linux; modules = [ { home.packages = [ khanelivim.packages.x86_64-linux.default ]; } ]; }; }; } ``` -------------------------------- ### Setup DAP Debugging Adapters and UI in NixVim Source: https://context7.com/birnxnet/nixvim2/llms.txt This Nix configuration sets up the Debug Adapter Protocol (DAP) in NixVim, enabling multi-language debugging with a user interface. It configures keybindings for debugging actions, enables the 'dap-ui' for enhanced visualization, and sets up debug adapters for Python (debugpy) and Node.js. Dependencies include pkgs.debugpy and pkgs.vscode-js-debug. This snippet focuses on editor configuration. ```nix # modules/nixvim/plugins/dap/default.nix plugins.dap = { enable = true; lazyLoad.settings.keys = [ { __unkeyed-1 = "db"; __unkeyed-2.__raw = ''function() require('dap').toggle_breakpoint() end''; desc = "Breakpoint toggle"; } { __unkeyed-1 = "dc"; __unkeyed-2.__raw = ''function() require('dap').continue() end''; desc = "Continue Debugging (Start)"; } { __unkeyed-1 = "di"; __unkeyed-2.__raw = ''function() require('dap').step_into() end''; desc = "Step Into"; } { __unkeyed-1 = "do"; __unkeyed-2.__raw = ''function() require('dap').step_over() end''; desc = "Step Over"; } { __unkeyed-1 = "dO"; __unkeyed-2.__raw = ''function() require('dap').step_out() end''; desc = "Step Out"; } { __unkeyed-1 = "dr"; __unkeyed-2.__raw = ''function() require('dap').repl.toggle() end''; desc = "Toggle REPL"; } { __unkeyed-1 = "dt"; __unkeyed-2.__raw = ''function() require('dap').terminate() end''; desc = "Terminate"; } ]; extensions = { dap-ui = { enable = config.khanelivim.editor.debugUI == "dap-ui"; controls = { enabled = true; element = "repl"; }; floating.border = "rounded"; layouts = [ { elements = [ { id = "scopes"; size = 0.25; } { id = "breakpoints"; size = 0.25; } { id = "stacks"; size = 0.25; } { id = "watches"; size = 0.25; } ]; position = "left"; size = 40; } { elements = [ { id = "repl"; size = 0.5; } { id = "console"; size = 0.5; } ]; position = "bottom"; size = 10; } ]; }; dap-virtual-text = { enable = true; virt_text_pos = "eol"; }; }; adapters = { servers = { # Python debugging debugpy = { port = 5678; executable = { command = "${lib.getExe pkgs.debugpy}"; args = [ "-m" "debugpy.adapter" ]; }; }; # Node.js debugging node2 = { type = "executable"; command = "node"; args = [ "${pkgs.vscode-js-debug}/js-debug/src/dapDebugServer.js" ]; }; }; }; configurations = { python = [ { type = "debugpy"; request = "launch"; name = "Launch file"; program = "\${file}"; pythonPath = "python"; } ]; javascript = [ { type = "node2"; request = "launch"; name = "Launch Program"; program = "\${file}"; } ]; }; }; ``` -------------------------------- ### Override Khanelivim Settings and Plugins (Nix) Source: https://context7.com/birnxnet/nixvim2/llms.txt This Nix configuration demonstrates how to extend the default Khanelivim setup. It allows disabling specific plugins, overriding their settings, changing core configuration options like pickers and completion engines, and adding custom Lua code for keybindings and editor settings. ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; home-manager.url = "github:nix-community/home-manager"; khanelivim.url = "github:khaneliman/khanelivim"; }; outputs = { nixpkgs, home-manager, khanelivim, ... }: { homeConfigurations.username = home-manager.lib.homeManagerConfiguration { pkgs = nixpkgs.legacyPackages.x86_64-linux; modules = [ { home.packages = [ (let baseConfig = khanelivim.nixvimConfigurations.x86_64-linux.khanelivim; extendedConfig = baseConfig.extendModules { modules = [ { # Disable specific plugins plugins.yazi.enable = false; plugins.copilot.enable = false; # Override plugin settings plugins.lualine.settings.options.theme = "gruvbox"; # Change configuration options khanelivim.picker.engine = "telescope"; khanelivim.completion.engine = "nvim-cmp"; khanelivim.editor.fileManager = "neo-tree"; # Add custom Lua configuration extraConfigLua = '' vim.opt.relativenumber = false vim.opt.colorcolumn = "120" -- Custom keybinding vim.keymap.set('n', 'x', ':wa', { desc = 'Save all files' }) ''; } ]; }; in extendedConfig.config.build.package) ]; } ]; }; }; } ``` -------------------------------- ### Generating New Plugin Templates with Nixvim Source: https://github.com/birnxnet/nixvim2/blob/main/CONTRIBUTING.md This command is used within the Nix development shell to generate new plugin templates. It takes the plugin name and a template type (`custom`, `custom-lazy`, or `nixvim`) as arguments, simplifying the setup for new plugins based on their configuration complexity and loading requirements. ```bash # Generate a new plugin template new-plugin # Example for a custom lazy-loaded plugin: # new-plugin my-awesome-plugin custom-lazy ``` -------------------------------- ### Build and Run Khanelivim Locally Source: https://github.com/birnxnet/nixvim2/blob/main/README.md This method involves cloning the Khanelivim repository locally and then using Nix to build and run the Neovim configuration. It's suitable for development or when you want to modify the configuration before running. ```bash git clone https://github.com/khaneliman/khanelivim.git cd khanelivim nix run ``` -------------------------------- ### Run Khanelivim with Nix (Easiest) Source: https://github.com/birnxnet/nixvim2/blob/main/README.md This command allows you to run the Khanelivim configuration directly from its GitHub repository using Nix. It requires the Nix command-line tool and flakes experimental features to be enabled. ```bash nix run --extra-experimental-features 'nix-command flakes' github:khaneliman/khanelivim ``` -------------------------------- ### Enter Nix Development Shell and Add New Plugins Source: https://github.com/birnxnet/nixvim2/blob/main/README.md This Bash snippet shows how to enter the Nix development shell for the project and how to use a provided script to add new plugins. The `new-plugin` script likely automates the process of integrating a new plugin into the Nixvim configuration. ```bash nix develop new-plugin ``` -------------------------------- ### Khanelivim Main Module Structure (Nix) Source: https://context7.com/birnxnet/nixvim2/llms.txt This Nix file defines the main module structure for Khanelivim. It automatically imports all plugin directories from the `./plugins` directory and includes several other configuration files for options, autocommands, dependencies, and more. It also sets up Nixpkgs overlays and configuration. ```nix # modules/nixvim/default.nix { lib, self, ... }: let inherit (builtins) readDir; inherit (lib.attrsets) foldlAttrs; inherit (lib.lists) optional; by-name = ./plugins; in { # Automatically import all plugin directories from plugins/ imports = (foldlAttrs ( prev: name: type: prev ++ optional (type == "directory") (by-name + "/${name}") ) [ ] (readDir by-name)) ++ [ ../khanelivim/options.nix ./autocommands.nix ./dependencies.nix ./diagnostics.nix ./ft.nix ./keymappings.nix ./lsp.nix ./lua.nix ./performance.nix ./usercommands.nix ]; nixpkgs = { overlays = lib.attrValues self.overlays; config = { allowAliases = false; allowUnfree = true; }; }; } ``` -------------------------------- ### Configure clangd LSP Server and Extensions in NixVim Source: https://context7.com/birnxnet/nixvim2/llms.txt This Nix configuration enables and sets up the clangd Language Server Protocol (LSP) for C/C++ development within NixVim. It includes options for completion, indexing, and a clangd extensions plugin for enhanced IDE features. Dependencies include pkgs.clang-tools. This snippet focuses on editor configuration. ```nix { config, lib, pkgs, ... }: { lsp.servers.clangd = { enable = config.khanelivim.lsp.cpp == "clangd"; config = { settings.init_options = { usePlaceholders = true; completeUnimported = true; clangdFileStatus = true; }; cmd = [ "${lib.getExe' pkgs.clang-tools "clangd"}" "--background-index" "--clang-tidy" "--header-insertion=iwyu" "--completion-style=detailed" "--function-arg-placeholders" "--fallback-style=llvm" ]; }; }; # Clangd extensions plugin plugins.clangd-extensions = { enable = config.khanelivim.lsp.cpp == "clangd"; enableOffsetEncodingWorkaround = true; ast = { roleIcons = { type = ""; declaration = ""; expression = ""; specifier = ""; statement = ""; templateArgument = ""; }; }; }; } ``` -------------------------------- ### Development Workflow Commands for NixVim Source: https://context7.com/birnxnet/nixvim2/llms.txt A collection of bash commands for managing the NixVim development environment. Includes commands for entering the development shell, generating plugins, formatting/linting code, checking the flake, building, and running Neovim. ```bash # Enter development shell nix develop # Generate new plugin from template new-plugin telescope-extensions nixvim new-plugin custom-ui custom-lazy # Format and lint code nix fmt deadnix -e statix fix . # Check flake nix flake check # Build and test nix build ./result/bin/nvim # Run directly nix run # Update dependencies nix flake update ``` -------------------------------- ### Integrate Khanelivim with Home Manager Source: https://github.com/birnxnet/nixvim2/blob/main/README.md This Nix code snippet demonstrates how to integrate Khanelivim into your Home Manager configuration. It shows how to include the default package or extend the configuration with custom settings and Lua code. ```nix { ... }: { home.packages = [ # Option A: Use default configuration khanelivim.packages.x86_64-linux.default # Option B: Extend with customizations (let baseConfig = khanelivim.nixvimConfigurations.x86_64-linux.khanelivim; extendedConfig = baseConfig.extendModules { modules = [ { # Disable specific plugins plugins.yazi.enable = false; # Override plugin settings plugins.lualine.settings.options.theme = "gruvbox"; # Add custom Lua configuration extraConfigLua = '' vim.opt.relativenumber = false ''; } ]; }; in extendedConfig.config.build.package) ]; } ``` -------------------------------- ### Build and Run Neovim from Nix Build Result Source: https://github.com/birnxnet/nixvim2/blob/main/README.md This command builds the project using Nix and then executes the Neovim binary located in the build result. It's useful for testing local changes to the Neovim configuration before committing. ```bash nix build && ./result/bin/nvim ``` -------------------------------- ### Rust-Analyzer Configuration with Detailed Inlay Hints Source: https://context7.com/birnxnet/nixvim2/llms.txt Configures the Rust-analyzer language server, enabling it when the 'rust' LSP setting is 'rust-analyzer'. It includes detailed settings for diagnostics, file exclusions, various types of inlay hints, proc macro support, cargo integration, and check-on-save functionality using 'clippy'. ```nix # modules/nixvim/lsp/rust-analyzer.nix { config, ... }: { lsp.servers.rust_analyzer = { enable = config.khanelivim.lsp.rust == "rust-analyzer"; config.settings = { diagnostics = { enable = true; styleLints.enable = true; }; files = { excludeDirs = [ ".direnv" "rust/.direnv" ]; }; inlayHints = { bindingModeHints.enable = true; closureStyle = "rust_analyzer"; closureReturnTypeHints.enable = "always"; discriminantHints.enable = "always"; expressionAdjustmentHints.enable = "always"; implicitDrops.enable = true; lifetimeElisionHints.enable = "always"; rangeExclusiveHints.enable = true; }; procMacro = { enable = true; }; cargo = { allFeatures = true; buildScripts.enable = true; }; checkOnSave = { command = "clippy"; }; }; }; } ``` -------------------------------- ### Nixvim LSP Global Settings and Keymaps Source: https://context7.com/birnxnet/nixvim2/llms.txt Configures global LSP settings, including inlay hints and a list of default language servers. It also defines keymaps for various LSP actions like definition, references, hover, and code actions, triggered by specific key combinations. ```nix { imports = [ ./lsp/ccls.nix ./lsp/clangd.nix ./lsp/harper-ls.nix ./lsp/helm-ls.nix ./lsp/lspconfig.nix ./lsp/nil-ls.nix ./lsp/nixd.nix ./lsp/rust-analyzer.nix ./lsp/typos-lsp.nix ]; lsp = { inlayHints.enable = true; servers = { # Global LSP settings "*" = { config = { capabilities = { textDocument = { semanticTokens = { multilineTokenSupport = true; }; }; }; root_markers = [ ".git" ]; }; }; # Language servers enabled by default angularls.enable = true; bashls.enable = true; cssls.enable = true; dockerls.enable = true; gopls.enable = true; helm_ls.enable = true; html.enable = true; jsonls.enable = true; lua_ls.enable = true; marksman.enable = true; pyright.enable = lib.elem "pyright" config.khanelivim.lsp.python; ruff.enable = lib.elem "ruff" config.khanelivim.lsp.python; sqls.enable = true; taplo.enable = true; yamlls.enable = true; }; }; # LSP keymaps attached on buffer keymapsOnEvents.LspAttach = [ { key = "gd"; mode = "n"; action = lib.nixvim.mkRaw "vim.lsp.buf.definition"; options = { silent = true; desc = "Goto Definition"; }; } { key = "gr"; mode = "n"; action = lib.nixvim.mkRaw "vim.lsp.buf.references"; options = { silent = true; desc = "Goto References"; }; } { key = "gi"; mode = "n"; action = lib.nixvim.mkRaw "vim.lsp.buf.implementation"; options = { silent = true; desc = "Goto Implementation"; }; } { key = "gy"; mode = "n"; action = lib.nixvim.mkRaw "vim.lsp.buf.type_definition"; options = { silent = true; desc = "Goto Type Definition"; }; } { key = "K"; mode = "n"; action = lib.nixvim.mkRaw "vim.lsp.buf.hover"; options = { silent = true; desc = "Hover Documentation"; }; } { key = "la"; mode = [ "n" "v" ]; action = lib.nixvim.mkRaw "vim.lsp.buf.code_action"; options = { silent = true; desc = "Code Action"; }; } { key = "lr"; mode = "n"; action = lib.nixvim.mkRaw "vim.lsp.buf.rename"; options = { silent = true; desc = "Rename Symbol"; }; } ]; } ``` -------------------------------- ### Blink Completion Engine Configuration (Nix) Source: https://context7.com/birnxnet/nixvim2/llms.txt Configures the Blink completion engine for NixVim, enabling it when the 'blink' option is selected. It sets up features like ghost text, documentation display, menu appearance, and fuzzy finding implementation. This configuration also defines custom kind icons and dynamic source selection logic, including specific handling for Copilot. ```nix # modules/nixvim/plugins/blink/default.nix plugins.blink-cmp = { enable = config.khanelivim.completion.engine == "blink"; lazyLoad.settings.event = [ "InsertEnter" "CmdlineEnter" ]; settings = { completion = { ghost_text.enabled = true; documentation = { auto_show = true; window.border = "rounded"; }; menu = { border = "rounded"; draw = { columns = [ { __unkeyed-1 = "label"; } { __unkeyed-1 = "kind_icon"; __unkeyed-2 = "kind"; gap = 1; } { __unkeyed-1 = "source_name"; } ]; }; }; }; fuzzy = { implementation = "rust"; prebuilt_binaries = { download = false; }; }; appearance = { use_nvim_cmp_as_default = true; kind_icons = { Copilot = ""; Text = ""; Method = ""; Function = ""; Constructor = ""; Field = ""; Variable = ""; Class = ""; Interface = ""; Module = ""; Property = ""; Unit = ""; Value = ""; Enum = ""; Keyword = ""; Snippet = ""; Color = ""; File = ""; Reference = ""; Folder = ""; EnumMember = ""; Constant = ""; Struct = ""; Event = ""; Operator = ""; TypeParameter = ""; }; }; sources = { # Dynamic source selection based on context default.__raw = '' function(ctx) local base_sources = { 'buffer', 'lsp', 'path', 'snippets' } local common_sources = vim.deepcopy(base_sources) if vim.bo.filetype == 'gitcommit' then return { 'buffer', 'spell', 'dictionary' } else return common_sources end end ''; providers = { lsp.score_offset = 4; copilot = { name = "copilot"; module = "blink-copilot"; async = true; score_offset = 100; transform_items.__raw = '' function(_, items) local CompletionItemKind = require("blink.cmp.types").CompletionItemKind local kind_idx = #CompletionItemKind + 1 CompletionItemKind[kind_idx] = "Copilot" for _, item in ipairs(items) do item.kind = kind_idx end return items end ''; }; }; }; keymap = { preset = "default"; "" = [ "select_prev" "fallback" ]; "" = [ "select_next" "fallback" ]; }; }; }; ``` -------------------------------- ### Configure Gitsigns Keymaps for Hunk Navigation and Staging Source: https://context7.com/birnxnet/nixvim2/llms.txt Sets up keybindings for navigating between git hunks and staging/resetting them. It includes mappings for previous/next hunk navigation, staging/resetting hunks, and undoing staged hunks. These keymaps are conditionally enabled based on the gitsigns plugin being active. ```nix keymaps = lib.mkIf config.plugins.gitsigns.enable [ # Navigate hunks { mode = "n"; key = "]c"; action.__raw = '' function() if vim.wo.diff then return ']c' end vim.schedule(function() require('gitsigns').nav_hunk('next') end) return '' end ''; options = { expr = true; desc = "Next git hunk"; }; } { mode = "n"; key = "[c"; action.__raw = '' function() if vim.wo.diff then return '[c' end vim.schedule(function() require('gitsigns').nav_hunk('prev') end) return '' end ''; options = { expr = true; desc = "Previous git hunk"; }; } # Stage/reset hunks { mode = [ "n" "v" ]; key = "hs"; action = ":Gitsigns stage_hunk"; options = { desc = "Stage hunk"; }; } { mode = [ "n" "v" ]; key = "hr"; action = ":Gitsigns reset_hunk"; options = { desc = "Reset hunk"; }; } { mode = "n"; key = "hu"; action = "Gitsigns undo_stage_hunk"; options = { desc = "Undo stage hunk"; }; } # Buffer operations { mode = "n"; key = "hS"; action = "Gitsigns stage_buffer"; options = { desc = "Stage buffer"; }; } { mode = "n"; key = "hR"; action = "Gitsigns reset_buffer"; options = { desc = "Reset buffer"; }; } # Preview and blame { mode = "n"; key = "hp"; action = "Gitsigns preview_hunk"; options = { desc = "Preview hunk"; }; } { mode = "n"; key = "hb"; action.__raw = ''function() require('gitsigns').blame_line({ full = true }) end''; options = { desc = "Blame line"; }; } { mode = "n"; key = "tb"; action = "Gitsigns toggle_current_line_blame"; options = { desc = "Toggle line blame"; }; } # Diff viewing { mode = "n"; key = "hd"; action = "Gitsigns diffthis"; options = { desc = "Diff this"; }; } ]; ``` -------------------------------- ### NixVim Configuration Options (Nix) Source: https://context7.com/birnxnet/nixvim2/llms.txt Defines configuration options for NixVim, including AI provider and chat enablement, completion engine, picker implementation, editor features such as file manager, motion plugin, search plugin, and snippet engine, and LSP configurations for C++, Nix, Rust, and TypeScript. These options use Nix's lib.mkOption for type, default, and description. ```nix options.khanelivim = { ai = { provider = lib.mkOption { type = lib.types.enum [ "copilot" "windsurf" "none" ]; default = "copilot"; description = "AI completion provider to use"; }; chatEnable = lib.mkEnableOption "AI chat functionality" // { default = true; }; }; completion.engine = lib.mkOption { type = lib.types.enum [ "blink" "nvim-cmp" "none" ]; default = "blink"; description = "Completion engine to use"; }; picker.engine = lib.mkOption { type = lib.types.enum [ "snacks" "telescope" "fzf" "none" ]; default = "snacks"; description = "Fuzzy finder implementation"; }; editor = { fileManager = lib.mkOption { type = lib.types.enum [ "neo-tree" "yazi" "mini-files" "none" ]; default = "yazi"; }; motionPlugin = lib.mkOption { type = lib.types.enum [ "flash" "hop" "none" ]; default = "flash"; }; searchPlugin = lib.mkOption { type = lib.types.enum [ "spectre" "grug-far" "none" ]; default = "grug-far"; }; snippetEngine = lib.mkOption { type = lib.types.enum [ "luasnip" "mini-snippets" "none" ]; default = "mini-snippets"; }; }; lsp = { cpp = lib.mkOption { type = lib.types.enum [ "clangd" "ccls" "none" ]; default = "clangd"; }; nix = lib.mkOption { type = lib.types.enum [ "nixd" "nil-ls" "none" ]; default = "nixd"; }; rust = lib.mkOption { type = lib.types.enum [ "rust-analyzer" "rustaceanvim" "none" ]; default = "rust-analyzer"; }; typescript = lib.mkOption { type = lib.types.enum [ "typescript-tools" "ts_ls" "none" ]; default = "typescript-tools"; }; }; }; ``` -------------------------------- ### Manage Nix Flake Dependencies and Formatting Source: https://github.com/birnxnet/nixvim2/blob/main/README.md A collection of Bash commands for managing Nix flake dependencies, checking for issues, and formatting code. These commands are essential for maintaining a consistent and error-free Nix-based development environment. ```bash # Update flake dependencies nix flake update # Check flake for issues nix flake check # Format/lint code nix fmt deadnix -e statix fix . ``` -------------------------------- ### Define fzf-lua Keymaps for File and LSP Operations Source: https://context7.com/birnxnet/nixvim2/llms.txt This Nix code defines a list of keymaps for the fzf-lua plugin, specifically for navigating files, buffers, and LSP actions. These keymaps are enabled only when the 'fzf' picker engine is active. It includes mappings for finding files, recent files, live grep, buffers, help tags, keymaps, LSP definitions, and references. ```nix keymaps = lib.mkIf (config.khanelivim.picker.engine == "fzf") [ { mode = "n"; key = ""; action = "FzfLua files"; options = { desc = "Find files"; }; } { mode = "n"; key = "ff"; action = "FzfLua files"; options = { desc = "Find files"; }; } { mode = "n"; key = "fo"; action = "FzfLua oldfiles"; options = { desc = "Recent files"; }; } { mode = "n"; key = "fw"; action = "FzfLua live_grep"; options = { desc = "Live grep"; }; } { mode = "n"; key = "fb"; action = "FzfLua buffers"; options = { desc = "Find buffers"; }; } { mode = "n"; key = "fh"; action = "FzfLua help_tags"; options = { desc = "Help tags"; }; } { mode = "n"; key = "fk"; action = "FzfLua keymaps"; options = { desc = "Keymaps"; }; } { mode = "n"; key = "f/"; action = "FzfLua blines"; options = { desc = "Buffer fuzzy find"; }; } # LSP pickers { mode = "n"; key = "ld"; action = "FzfLua lsp_definitions"; options = { desc = "Goto Definition"; }; } { mode = "n"; key = "lr"; action = "FzfLua lsp_references"; options = { desc = "References"; }; } { mode = "n"; key = "ls"; action = "FzfLua lsp_document_symbols"; options = { desc = "Document Symbols"; }; } # Git pickers { mode = "n"; key = "gs"; action = "FzfLua git_status"; options = { desc = "Git status"; }; } { mode = "n"; key = "gc"; action = "FzfLua git_commits"; options = { desc = "Git commits"; }; } ]; ``` -------------------------------- ### Nixd Language Server Configuration with Flake Integration Source: https://context7.com/birnxnet/nixvim2/llms.txt Configures the Nixd language server, enabling it when the 'nix' LSP setting is 'nixd'. It provides a wrapper to generate Nix expressions for nixd evaluation, including configurations for nixpkgs and option completions for flake modules. ```nix # modules/nixvim/lsp/nixd.nix { config, lib, pkgs, self, ... }: { lsp.servers.nixd = { enable = config.khanelivim.lsp.nix == "nixd"; config.settings.nixd = let # Generate Nix expression for nixd evaluation wrapper = builtins.toFile "expr.nix" '' import ${./_nixd-expr.nix} { self = ${builtins.toJSON self}; system = ${builtins.toJSON pkgs.stdenv.hostPlatform.system}; } ''; withFlakes = expr: "with import ${wrapper}; " + expr; in { # Configure nixpkgs for completions nixpkgs.expr = withFlakes '' import (if local ? lib.version then local else local.inputs.nixpkgs or global.inputs.nixpkgs) { } ''; formatting = { command = [ "${lib.getExe pkgs.nixfmt}" ]; }; # Provide option completions for flake modules options = { flake-parts.expr = withFlakes "local.debug.options or global.debug.options"; nixvim.expr = withFlakes "global.nixvimConfigurations.${system}.default.options"; }; }; }; } ``` -------------------------------- ### Configure treesitter for Syntax Highlighting and Incremental Selection Source: https://context7.com/birnxnet/nixvim2/llms.txt Enables and configures the treesitter plugin for advanced syntax highlighting and incremental selection within NixVim. It includes settings for grammar package inclusion/exclusion, highlighting options, and keymaps for incremental selection actions. ```nix # modules/nixvim/plugins/treesitter/default.nix plugins.treesitter = { enable = true; folding = true; # Include most grammars except heavyweight ones grammarPackages = let excludedGrammars = [ "agda-grammar" "cuda-grammar" "d-grammar" "fortran-grammar" "haskell-grammar" "julia-grammar" "scala-grammar" ]; in lib.filter ( g: !(lib.elem g.pname excludedGrammars) ) config.plugins.treesitter.package.passthru.allGrammars ++ [ self.packages.${system}.tree-sitter-norg-meta ]; nixvimInjections = true; settings = { highlight = { additional_vim_regex_highlighting = true; enable = true; # Disable highlighting for large files (>10000 lines) disable = '' function(lang, bufnr) return vim.api.nvim_buf_line_count(bufnr) > 10000 end ''; }; incremental_selection = { enable = true; keymaps = { init_selection = "gnn"; node_incremental = "grn"; scope_incremental = "grc"; node_decremental = "grm"; }; }; indent = { enable = true; }; }; }; # Treesitter-based plugins plugins = { treesitter-context.enable = true; treesitter-refactor.enable = true; ts-autotag.enable = true; ts-context-commentstring.enable = true; }; ``` -------------------------------- ### Configure conform.nvim for Code Formatting in NixVim Source: https://context7.com/birnxnet/nixvim2/llms.txt Sets up the conform.nvim plugin for automatic code formatting. It includes configuration for auto-installation of formatters, defining formatters by file type, and setting up keymaps for toggling and manual formatting. It also handles timeout logic for slow formatters. ```nix plugins.conform-nvim = { enable = true; autoInstall = { enable = true; overrides = { # Platform-specific overrides swift_format = lib.mkIf pkgs.stdenv.hostPlatform.isLinux null; }; }; lazyLoad.settings = { cmd = [ "ConformInfo" ]; event = [ "BufWritePre" ]; }; settings = { default_format_opts = { lsp_format = "fallback"; }; # Format on save with timeout handling format_on_save = '' function(bufnr) -- Skip formatting if disabled globally or for buffer if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then return end -- Check if this filetype is slow to format local function on_format(err) if err and err:match("timeout$") then slow_format_filetypes[vim.bo[bufnr].filetype] = true end end return { timeout_ms = 500, lsp_format = "fallback" }, on_format end ''; # Formatters by file type formatters_by_ft = { "_" = [ "trim_whitespace" ]; bash = [ "shellcheck" "shellharden" "shfmt" ]; c = [ "clang_format" ]; cpp = [ "clang_format" ]; css = [ "prettierd" ]; go = [ "goimports" "golines" ]; html = [ "prettierd" ]; java = [ "google-java-format" ]; javascript = [ { __unkeyed-1 = "prettierd"; __unkeyed-2 = "biome"; } ]; json = [ "biome" ]; lua = [ "stylua" ]; markdown = [ "prettierd" ]; nix = [ "nixfmt" ]; python = [ "isort" "ruff_fix" "ruff_format" ]; rust = [ "rustfmt" ]; typescript = [ { __unkeyed-1 = "prettierd"; __unkeyed-2 = "biome"; } ]; yaml = [ "yamlfmt" ]; }; formatters = { nixfmt = { command = lib.getExe pkgs.nixfmt; }; shfmt = { prepend_args = [ "-i" "2" "-ci" ]; }; }; }; }; # Toggle formatting on/off keymaps = [ { mode = "n"; key = "uf"; action.__raw = '' function() vim.b.disable_autoformat = not vim.b.disable_autoformat vim.notify( "Autoformat " .. (vim.b.disable_autoformat and "disabled" or "enabled"), vim.log.levels.INFO ) end ''; options = { desc = "Toggle format on save"; }; } { mode = [ "n" "v" ]; key = "lf"; action.__raw = '' function() require("conform").format({ async = true, lsp_format = "fallback" }) end ''; options = { desc = "Format buffer"; }; } ]; ``` -------------------------------- ### Configure fzf-lua Plugin Settings Source: https://context7.com/birnxnet/nixvim2/llms.txt This Nix code configures the fzf-lua plugin, enabling it when the 'fzf' picker engine is active. It sets up options for old files, window appearance, file searching with git and file icons, and grep arguments. It also defines lazy loading for the 'FzfLua' command. ```nix plugins.fzf-lua = { enable = config.khanelivim.picker.engine == "fzf"; profile = "telescope"; lazyLoad.settings.cmd = [ "FzfLua" ]; settings = { oldfiles = { cwd_only = true; include_current_session = true; }; winopts = { preview = { default = "bat"; border = "rounded"; wrap = "nowrap"; }; height = 0.85; width = 0.80; row = 0.35; col = 0.50; }; files = { git_icons = true; file_icons = true; color_icons = true; }; grep = { rg_opts = "--hidden --column --line-number --no-heading --color=always --smart-case --max-columns=4096"; }; }; }; ``` -------------------------------- ### Add New NixVim2 Plugin using Nix Source: https://github.com/birnxnet/nixvim2/blob/main/README.md Command to generate a new plugin template within the NixVim2 project. It supports different template types for custom or NixVim integrated plugins. ```bash new-plugin ``` -------------------------------- ### Configure Neovim Clipboard with Nix Source: https://context7.com/birnxnet/nixvim2/llms.txt Sets up the Neovim clipboard behavior, enabling 'unnamedplus' register and conditionally providing 'wl-copy' for Linux and 'pbcopy' for macOS. This ensures seamless copy-pasting between Neovim and the system clipboard. ```nix { clipboard = { register = "unnamedplus"; providers = { wl-copy = lib.mkIf pkgs.stdenv.hostPlatform.isLinux { enable = true; package = pkgs.wl-clipboard; }; pbcopy = lib.mkIf pkgs.stdenv.hostPlatform.isDarwin { enable = true; }; }; }; } ``` -------------------------------- ### Nix Development Shell and Testing Commands Source: https://github.com/birnxnet/nixvim2/blob/main/CONTRIBUTING.md These commands facilitate the development workflow for Nix-based projects. `nix develop` enters a specialized development environment, `nix flake update` refreshes dependencies, `nix flake check` validates the configuration, and `nix run` activates the configuration for testing purposes. ```bash # Enter the development shell nix develop # Update Nix flake dependencies nix flake update # Validate the Nix flake configuration nix flake check # Activate the configuration for testing nix run ``` -------------------------------- ### Nix Code Formatting and Linting Tools Source: https://github.com/birnxnet/nixvim2/blob/main/CONTRIBUTING.md This snippet shows the commands for formatting and linting Nix code using `nixfmt`, `statix`, and `deadnix`. `nixfmt` ensures consistent code style, `statix` checks for linting errors, and `deadnix` identifies unused code. These tools are crucial for maintaining code quality in Nix projects. ```bash # Format Nix code nixfmt # Lint Nix code and fix issues statix fix . # Remove unused code deadnix -e ``` -------------------------------- ### Configure Neovim File Handling and Indentation with Nix Source: https://context7.com/birnxnet/nixvim2/llms.txt Defines settings for file handling and text indentation in Neovim. This includes specifying file encoding and format, as well as configuring tab width, shift width, soft tab stop, and auto/smart indentation behavior. ```nix { opts = { # Files fileencoding = "utf-8"; fileformat = "unix"; # Indentation tabstop = 2; shiftwidth = 2; softtabstop = 0; expandtab = true; autoindent = true; smartindent = true; }; } ```