From 10e3123b7f7f7661f712bb3a31170ecd7edf4378 Mon Sep 17 00:00:00 2001 From: Salar Rahmanian Date: Sun, 5 Oct 2025 15:47:32 -0700 Subject: [PATCH] re-organize nixvim --- programs/fish/default.nix | 5 - programs/nixvim/README.md | 163 ++++++++++++++++++ programs/nixvim/_plugins/default.nix | 106 ------------ programs/nixvim/_plugins/lsp.nix | 106 ------------ programs/nixvim/default.nix | 4 +- programs/nixvim/plugins/ai.nix | 11 ++ .../nixvim/{_plugins => plugins}/avante.nix | 0 .../nixvim/{_plugins => plugins}/conform.nix | 0 programs/nixvim/plugins/default.nix | 24 +++ programs/nixvim/plugins/editing.nix | 44 +++++ .../nixvim/{_plugins => plugins}/floaterm.nix | 0 programs/nixvim/plugins/git.nix | 17 ++ programs/nixvim/plugins/lsp/default.nix | 9 + programs/nixvim/plugins/lsp/formatting.nix | 19 ++ programs/nixvim/plugins/lsp/keymaps.nix | 43 +++++ programs/nixvim/plugins/lsp/servers.nix | 79 +++++++++ .../nixvim/{_plugins => plugins}/lualine.nix | 0 .../nixvim/{_plugins => plugins}/neo-tree.nix | 0 .../{_plugins => plugins}/telescope.nix | 0 .../{_plugins => plugins}/treesitter.nix | 0 programs/nixvim/plugins/ui.nix | 40 +++++ programs/nixvim/plugins/utility.nix | 29 ++++ 22 files changed, 480 insertions(+), 219 deletions(-) create mode 100644 programs/nixvim/README.md delete mode 100644 programs/nixvim/_plugins/default.nix delete mode 100644 programs/nixvim/_plugins/lsp.nix create mode 100644 programs/nixvim/plugins/ai.nix rename programs/nixvim/{_plugins => plugins}/avante.nix (100%) rename programs/nixvim/{_plugins => plugins}/conform.nix (100%) create mode 100644 programs/nixvim/plugins/default.nix create mode 100644 programs/nixvim/plugins/editing.nix rename programs/nixvim/{_plugins => plugins}/floaterm.nix (100%) create mode 100644 programs/nixvim/plugins/git.nix create mode 100644 programs/nixvim/plugins/lsp/default.nix create mode 100644 programs/nixvim/plugins/lsp/formatting.nix create mode 100644 programs/nixvim/plugins/lsp/keymaps.nix create mode 100644 programs/nixvim/plugins/lsp/servers.nix rename programs/nixvim/{_plugins => plugins}/lualine.nix (100%) rename programs/nixvim/{_plugins => plugins}/neo-tree.nix (100%) rename programs/nixvim/{_plugins => plugins}/telescope.nix (100%) rename programs/nixvim/{_plugins => plugins}/treesitter.nix (100%) create mode 100644 programs/nixvim/plugins/ui.nix create mode 100644 programs/nixvim/plugins/utility.nix diff --git a/programs/fish/default.nix b/programs/fish/default.nix index 37c75e9..9f7ec13 100644 --- a/programs/fish/default.nix +++ b/programs/fish/default.nix @@ -54,7 +54,6 @@ set -xg TOOLCHAINS swift - # set -xg DEVELOPER_DIR "/Library/Developer/CommandLineTools" set -xg OPENAI_API_KEY (cat ~/.openai) set -xg ANTHROPIC_API_KEY (cat ~/.anthropic) ''; @@ -80,12 +79,9 @@ ghauth = "gh auth login --with-token < ~/.ghauth"; gitpurgemain = ''git branch --merged | grep -v "\*" | grep -v "main" | xargs -n 1 git branch -d''; gitpurgemaster = ''git branch --merged | grep -v "\*" | grep -v "master" | xargs -n 1 git branch -d''; - giscala = "gitignore scala,vim,java,sbt > .gitignore"; gforksync = "git fetch upstream && git merge upstream/master && git push origin master"; grep = "grep --color=auto"; - hg = "kitten hyperlinked-grep"; lg = "lazygit"; - new-sbt = "sbt new scala/scala-seed.g8"; nixc = "cd ~/.config/nixpkgs"; nixre = "nix build && sudo ./result/activate"; nixinfo = "nix-shell -p nix-info --run \"nix-info -m\""; @@ -93,7 +89,6 @@ nixq = "nix-env -qa"; nixstorerepair = "nix-store --repair --verify --check-contents"; nixupgrade = "nix upgrade-nix"; - o = "echo (ollama run qwen2.5-coder \"Provide only the MacOS terminal command (without markdown) to: $argv\")"; rmxcodederived = "rm -fr ~/Library/Developer/Xcode/DerivedData"; v = "nvim"; sshhcloud1 = "ssh salar@hcloud1.softinio.net"; diff --git a/programs/nixvim/README.md b/programs/nixvim/README.md new file mode 100644 index 0000000..03efadd --- /dev/null +++ b/programs/nixvim/README.md @@ -0,0 +1,163 @@ +# Nixvim Configuration + +This directory contains a modular Neovim configuration managed through [nixvim](https://github.com/nix-community/nixvim). + +## Directory Structure + +``` +nixvim/ +├── default.nix # Main entry point +├── options.nix # Core Neovim options (line numbers, tabs, etc.) +├── keymappings.nix # Global key mappings +├── autocommands.nix # Auto commands for various events +├── completion.nix # Completion configuration (nvim-cmp) +└── plugins/ # Plugin configurations + ├── default.nix # Plugin imports + ├── ui.nix # UI enhancements (colorscheme, icons, etc.) + ├── git.nix # Git integration + ├── editing.nix # Editing enhancements + ├── utility.nix # Utility plugins + ├── ai.nix # AI assistants (Copilot, Avante) + ├── lsp/ # Language Server Protocol + │ ├── default.nix # LSP imports + │ ├── servers.nix # Language server configurations + │ ├── keymaps.nix # LSP-specific key mappings + │ └── formatting.nix # Auto-formatting settings + ├── avante.nix # Avante AI configuration + ├── conform.nix # Code formatting + ├── floaterm.nix # Floating terminal + ├── lualine.nix # Status line + ├── neo-tree.nix # File explorer + ├── telescope.nix # Fuzzy finder + └── treesitter.nix # Syntax highlighting +``` + +## Configuration Categories + +### Core Settings (`options.nix`) +- Editor options (line numbers, indentation, etc.) +- Update time and performance settings +- Clipboard configuration +- Leader key mappings + +### Key Mappings (`keymappings.nix`) +- Window navigation +- Buffer management +- Text manipulation +- Custom shortcuts + +### Auto Commands (`autocommands.nix`) +- FileType-specific settings +- Auto-formatting rules +- UI behavior modifications + +### Completion (`completion.nix`) +- nvim-cmp configuration +- Snippet support +- LSP integration +- Multiple completion sources + +### Plugins + +#### UI Enhancements (`ui.nix`) +- **Colorscheme**: Tokyo Night theme with custom background +- **Icons**: File type icons via web-devicons +- **Visual aids**: Indent guides, color highlighting, markdown preview + +#### Git Integration (`git.nix`) +- **Gitsigns**: Shows git changes in the gutter + +#### Editing (`editing.nix`) +- **Auto-pairs**: Automatic bracket/quote closing +- **Flash**: Enhanced jump/search +- **Trim**: Whitespace management +- **Image support**: Clipboard image pasting + +#### Utilities (`utility.nix`) +- **Oil**: File manager +- **Todo-comments**: Highlight TODO/FIXME comments +- **Trouble**: Diagnostics list +- **Which-key**: Show available keybindings + +#### AI Assistants (`ai.nix`) +- **Copilot**: GitHub Copilot integration +- **Avante**: Advanced AI assistant + +#### LSP (`lsp/`) +- **Language Servers**: Support for 15+ languages +- **Key mappings**: Go-to-definition, references, hover docs +- **Auto-formatting**: Format on save for all supported languages + +## Adding New Configurations + +### Adding a New Plugin + +1. Create a new file in `plugins/` or add to an existing category file +2. Add the import to `plugins/default.nix` +3. Configure the plugin following nixvim documentation + +Example: +```nix +# plugins/my-plugin.nix +{ ... }: +{ + programs.nixvim.plugins.my-plugin = { + enable = true; + settings = { + # Plugin-specific settings + }; + }; +} +``` + +### Adding a New Language Server + +Edit `plugins/lsp/servers.nix` and add your server configuration: +```nix +my_language_ls = { + enable = true; + settings = { + # Server-specific settings + }; +}; +``` + +### Adding Key Mappings + +- **Global mappings**: Add to `keymappings.nix` +- **LSP mappings**: Add to `plugins/lsp/keymaps.nix` +- **Plugin-specific**: Add to the plugin's configuration file + +## Applying Changes + +After making changes, rebuild your nix configuration: +```bash +nixre # Alias for darwin-rebuild switch --flake ~/.config/nixpkgs#salarm3max +``` + +## Performance Tuning + +Key performance settings: +- `updatetime`: Controls LSP/diagnostic update speed (currently 100ms) +- `performance.debounce`: Completion debounce time (60ms) +- `performance.throttle`: Completion throttle time (30ms) + +Adjust these in `options.nix` and `completion.nix` respectively. + +## Troubleshooting + +### LSP Not Working +1. Check if language server is installed: `:LspInfo` +2. Verify keymaps are loaded: `:map gd` +3. Check for errors: `:messages` + +### Slow Performance +1. Increase `updatetime` in `options.nix` +2. Adjust completion performance settings in `completion.nix` +3. Disable unused language servers in `lsp/servers.nix` + +## Resources + +- [Nixvim Documentation](https://nix-community.github.io/nixvim/) +- [Neovim Documentation](https://neovim.io/doc/) +- [LSP Specification](https://microsoft.github.io/language-server-protocol/) \ No newline at end of file diff --git a/programs/nixvim/_plugins/default.nix b/programs/nixvim/_plugins/default.nix deleted file mode 100644 index b89a7cb..0000000 --- a/programs/nixvim/_plugins/default.nix +++ /dev/null @@ -1,106 +0,0 @@ -{ ... }: - -{ - imports = [ - ./avante.nix - ./conform.nix - ./floaterm.nix - ./lsp.nix - ./lualine.nix - ./neo-tree.nix - ./telescope.nix - ./treesitter.nix - ]; - - # Global plugin configurations can go here - programs.nixvim = { - colorschemes.tokyonight = { - enable = true; - settings = { - style = "night"; - on_colors.__raw = "function(colors) colors.bg = \"#000000\" end"; - }; - }; - - plugins = { - # Lazy loading - lz-n.enable = true; - - web-devicons.enable = true; - - gitsigns = { - enable = true; - settings.signs = { - add.text = "+"; - change.text = "~"; - delete.text = "_"; - topdelete.text = "‾"; - changedelete.text = "~"; - }; - }; - - nvim-autopairs.enable = true; - - colorizer = { - enable = true; - settings.user_default_options.names = false; - }; - - copilot-vim.enable = true; - - fidget.enable = true; - - flash.enable = true; - - img-clip = { - enable = true; - settings = { - default = { - embed_image_as_base64 = false; - prompt_for_file_name = false; - drag_and_drop = { - insert_mode = true; - }; - use_absolute_path = true; - }; - }; - }; - - indent-blankline.enable = true; - - markview.enable = true; - - nui.enable = true; - - oil = { - enable = true; - lazyLoad.settings.cmd = "Oil"; - }; - - snacks.enable = true; - - todo-comments = { - enable = true; - keymaps.todoTelescope.key = "t"; - }; - - trim = { - enable = true; - settings = { - highlight = true; - ft_blocklist = [ - "checkhealth" - "floaterm" - "lspinfo" - "neo-tree" - "TelescopePrompt" - ]; - }; - }; - - trouble.enable = true; - typst-preview.enable = true; - which-key.enable = true; - }; - }; -} diff --git a/programs/nixvim/_plugins/lsp.nix b/programs/nixvim/_plugins/lsp.nix deleted file mode 100644 index 4558e29..0000000 --- a/programs/nixvim/_plugins/lsp.nix +++ /dev/null @@ -1,106 +0,0 @@ -{ lib, ... }: - -{ - programs.nixvim = { - diagnostic.settings.virtual_text = true; - - lsp = { - inlayHints.enable = true; - servers = { - basedpyright = { - enable = true; - settings.settings.basedpyright = { - analysis = { - autoImportCompletions = true; - autoSearchPaths = true; - inlayHints = { - callArgumentNames = true; - }; - diagnosticMode = "openFilesOnly"; - reportMissingImports = true; - reportMissingParameterType = true; - reportUnnecessaryComparison = true; - reportUnnecessaryContains = true; - reportUnusedClass = true; - reportUnusedFunction = true; - reportUnsedImports = true; - reportUnsusedVariables = true; - typeCheckingMode = "recommended"; - useLibraryCodeForTypes = true; - }; - }; - }; - bashls.enable = true; - html.enable = true; - jqls.enable = true; - jsonls.enable = true; - lua_ls = { - enable = true; - settings.settings.diagnostics.globals = [ "vim" ]; - }; - marksman.enable = true; - metals.enable = true; - nil_ls.enable = true; - nixd.enable = true; - rust_analyzer.enable = true; - sourcekit = { - enable = true; - settings = { - cmd = [ - "xcrun" - "sourcekit-lsp" - ]; - }; - }; - tinymist.enable = true; - ts_ls.enable = true; - yamlls.enable = true; - }; - - keymaps = [ - { - key = "k"; - action.__raw = "function() vim.diagnostic.jump({ count=-1, float=true }) end"; - } - { - key = "j"; - action.__raw = "function() vim.diagnostic.jump({ count=1, float=true }) end"; - } - { - key = "gd"; - lspBufAction = "definition"; - } - { - key = "gD"; - lspBufAction = "references"; - } - { - key = "gt"; - lspBufAction = "type_definition"; - } - { - key = "gi"; - lspBufAction = "implementation"; - } - { - key = "K"; - lspBufAction = "hover"; - } - { - key = ""; - lspBufAction = "rename"; - } - ]; - }; - - plugins = { - lsp-format = { - enable = true; - lspServersToEnable = "all"; - }; - - # Sane defaults for all servers - lspconfig.enable = true; - }; - }; -} diff --git a/programs/nixvim/default.nix b/programs/nixvim/default.nix index 7143ccf..90938d1 100644 --- a/programs/nixvim/default.nix +++ b/programs/nixvim/default.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ ... }: { imports = [ @@ -6,7 +6,7 @@ ./completion.nix ./keymappings.nix ./options.nix - ./_plugins + ./plugins ]; programs.nixvim = { diff --git a/programs/nixvim/plugins/ai.nix b/programs/nixvim/plugins/ai.nix new file mode 100644 index 0000000..ad9c454 --- /dev/null +++ b/programs/nixvim/plugins/ai.nix @@ -0,0 +1,11 @@ +{ ... }: + +{ + programs.nixvim.plugins = { + # GitHub Copilot + copilot-vim.enable = true; + + # Avante AI assistant (imported from separate file) + # avante config is in avante.nix + }; +} \ No newline at end of file diff --git a/programs/nixvim/_plugins/avante.nix b/programs/nixvim/plugins/avante.nix similarity index 100% rename from programs/nixvim/_plugins/avante.nix rename to programs/nixvim/plugins/avante.nix diff --git a/programs/nixvim/_plugins/conform.nix b/programs/nixvim/plugins/conform.nix similarity index 100% rename from programs/nixvim/_plugins/conform.nix rename to programs/nixvim/plugins/conform.nix diff --git a/programs/nixvim/plugins/default.nix b/programs/nixvim/plugins/default.nix new file mode 100644 index 0000000..6fb88e1 --- /dev/null +++ b/programs/nixvim/plugins/default.nix @@ -0,0 +1,24 @@ +{ ... }: + +{ + imports = [ + # Core plugin categories + ./ui.nix + ./git.nix + ./editing.nix + ./utility.nix + ./ai.nix + + # LSP configuration + ./lsp + + # Individual plugin configurations + ./avante.nix + ./conform.nix + ./floaterm.nix + ./lualine.nix + ./neo-tree.nix + ./telescope.nix + ./treesitter.nix + ]; +} \ No newline at end of file diff --git a/programs/nixvim/plugins/editing.nix b/programs/nixvim/plugins/editing.nix new file mode 100644 index 0000000..8ad8c13 --- /dev/null +++ b/programs/nixvim/plugins/editing.nix @@ -0,0 +1,44 @@ +{ ... }: + +{ + programs.nixvim.plugins = { + # Auto-close brackets and quotes + nvim-autopairs.enable = true; + + # Flash jump/search enhancement + flash.enable = true; + + # Image clipboard support + img-clip = { + enable = true; + settings = { + default = { + embed_image_as_base64 = false; + prompt_for_file_name = false; + drag_and_drop = { + insert_mode = true; + }; + use_absolute_path = true; + }; + }; + }; + + # Trim trailing whitespace + trim = { + enable = true; + settings = { + highlight = true; + ft_blocklist = [ + "checkhealth" + "floaterm" + "lspinfo" + "neo-tree" + "TelescopePrompt" + ]; + }; + }; + + # Collection of small useful plugins + snacks.enable = true; + }; +} \ No newline at end of file diff --git a/programs/nixvim/_plugins/floaterm.nix b/programs/nixvim/plugins/floaterm.nix similarity index 100% rename from programs/nixvim/_plugins/floaterm.nix rename to programs/nixvim/plugins/floaterm.nix diff --git a/programs/nixvim/plugins/git.nix b/programs/nixvim/plugins/git.nix new file mode 100644 index 0000000..d2874ee --- /dev/null +++ b/programs/nixvim/plugins/git.nix @@ -0,0 +1,17 @@ +{ ... }: + +{ + programs.nixvim.plugins = { + # Git signs in the gutter + gitsigns = { + enable = true; + settings.signs = { + add.text = "+"; + change.text = "~"; + delete.text = "_"; + topdelete.text = "‾"; + changedelete.text = "~"; + }; + }; + }; +} \ No newline at end of file diff --git a/programs/nixvim/plugins/lsp/default.nix b/programs/nixvim/plugins/lsp/default.nix new file mode 100644 index 0000000..d0fd37d --- /dev/null +++ b/programs/nixvim/plugins/lsp/default.nix @@ -0,0 +1,9 @@ +{ ... }: + +{ + imports = [ + ./servers.nix + ./keymaps.nix + ./formatting.nix + ]; +} \ No newline at end of file diff --git a/programs/nixvim/plugins/lsp/formatting.nix b/programs/nixvim/plugins/lsp/formatting.nix new file mode 100644 index 0000000..5e8ea47 --- /dev/null +++ b/programs/nixvim/plugins/lsp/formatting.nix @@ -0,0 +1,19 @@ +{ ... }: + +{ + programs.nixvim = { + # Diagnostics display + diagnostic.settings.virtual_text = true; + + plugins = { + # Auto-format on save + lsp-format = { + enable = true; + lspServersToEnable = "all"; + }; + + # Sane defaults for all servers + lspconfig.enable = true; + }; + }; +} \ No newline at end of file diff --git a/programs/nixvim/plugins/lsp/keymaps.nix b/programs/nixvim/plugins/lsp/keymaps.nix new file mode 100644 index 0000000..4ad5c8d --- /dev/null +++ b/programs/nixvim/plugins/lsp/keymaps.nix @@ -0,0 +1,43 @@ +{ ... }: + +{ + programs.nixvim.lsp.keymaps = [ + # Diagnostics navigation + { + key = "k"; + action.__raw = "function() vim.diagnostic.jump({ count=-1, float=true }) end"; + } + { + key = "j"; + action.__raw = "function() vim.diagnostic.jump({ count=1, float=true }) end"; + } + + # LSP navigation + { + key = "gd"; + lspBufAction = "definition"; + } + { + key = "gD"; + lspBufAction = "references"; + } + { + key = "gt"; + lspBufAction = "type_definition"; + } + { + key = "gi"; + lspBufAction = "implementation"; + } + + # Documentation and refactoring + { + key = "K"; + lspBufAction = "hover"; + } + { + key = ""; + lspBufAction = "rename"; + } + ]; +} \ No newline at end of file diff --git a/programs/nixvim/plugins/lsp/servers.nix b/programs/nixvim/plugins/lsp/servers.nix new file mode 100644 index 0000000..6e35c82 --- /dev/null +++ b/programs/nixvim/plugins/lsp/servers.nix @@ -0,0 +1,79 @@ +{ ... }: + +{ + programs.nixvim.lsp = { + inlayHints.enable = true; + + servers = { + # Python + basedpyright = { + enable = true; + settings.settings.basedpyright = { + analysis = { + autoImportCompletions = true; + autoSearchPaths = true; + inlayHints = { + callArgumentNames = true; + }; + diagnosticMode = "openFilesOnly"; + reportMissingImports = true; + reportMissingParameterType = true; + reportUnnecessaryComparison = true; + reportUnnecessaryContains = true; + reportUnusedClass = true; + reportUnusedFunction = true; + reportUnsedImports = true; + reportUnsusedVariables = true; + typeCheckingMode = "recommended"; + useLibraryCodeForTypes = true; + }; + }; + }; + + # Shell scripting + bashls.enable = true; + + # Web development + html.enable = true; + jsonls.enable = true; + yamlls.enable = true; + ts_ls.enable = true; + + # Query languages + jqls.enable = true; + + # Lua + lua_ls = { + enable = true; + settings.settings.diagnostics.globals = [ "vim" ]; + }; + + # Documentation + marksman.enable = true; + + # Scala + metals.enable = true; + + # Nix + nil_ls.enable = true; + nixd.enable = true; + + # Rust + rust_analyzer.enable = true; + + # Swift/iOS development + sourcekit = { + enable = true; + settings = { + cmd = [ + "xcrun" + "sourcekit-lsp" + ]; + }; + }; + + # Typst + tinymist.enable = true; + }; + }; +} \ No newline at end of file diff --git a/programs/nixvim/_plugins/lualine.nix b/programs/nixvim/plugins/lualine.nix similarity index 100% rename from programs/nixvim/_plugins/lualine.nix rename to programs/nixvim/plugins/lualine.nix diff --git a/programs/nixvim/_plugins/neo-tree.nix b/programs/nixvim/plugins/neo-tree.nix similarity index 100% rename from programs/nixvim/_plugins/neo-tree.nix rename to programs/nixvim/plugins/neo-tree.nix diff --git a/programs/nixvim/_plugins/telescope.nix b/programs/nixvim/plugins/telescope.nix similarity index 100% rename from programs/nixvim/_plugins/telescope.nix rename to programs/nixvim/plugins/telescope.nix diff --git a/programs/nixvim/_plugins/treesitter.nix b/programs/nixvim/plugins/treesitter.nix similarity index 100% rename from programs/nixvim/_plugins/treesitter.nix rename to programs/nixvim/plugins/treesitter.nix diff --git a/programs/nixvim/plugins/ui.nix b/programs/nixvim/plugins/ui.nix new file mode 100644 index 0000000..937882f --- /dev/null +++ b/programs/nixvim/plugins/ui.nix @@ -0,0 +1,40 @@ +{ ... }: + +{ + programs.nixvim = { + # Colorscheme + colorschemes.tokyonight = { + enable = true; + settings = { + style = "night"; + on_colors.__raw = "function(colors) colors.bg = \"#000000\" end"; + }; + }; + + plugins = { + # Icons for file types + web-devicons.enable = true; + + # Color highlighter (shows colors in code) + colorizer = { + enable = true; + settings.user_default_options.names = false; + }; + + # Indentation guides + indent-blankline.enable = true; + + # Markdown preview with live rendering + markview.enable = true; + + # UI component library + nui.enable = true; + + # Loading/progress indicators + fidget.enable = true; + + # Status line (imported from separate file) + # lualine is in lualine.nix + }; + }; +} \ No newline at end of file diff --git a/programs/nixvim/plugins/utility.nix b/programs/nixvim/plugins/utility.nix new file mode 100644 index 0000000..9ddf0a2 --- /dev/null +++ b/programs/nixvim/plugins/utility.nix @@ -0,0 +1,29 @@ +{ ... }: + +{ + programs.nixvim.plugins = { + # Lazy loading support + lz-n.enable = true; + + # File manager + oil = { + enable = true; + lazyLoad.settings.cmd = "Oil"; + }; + + # TODO comment highlighting + todo-comments = { + enable = true; + keymaps.todoTelescope.key = "t"; + }; + + # Diagnostics list + trouble.enable = true; + + # Typst language preview + typst-preview.enable = true; + + # Key binding help + which-key.enable = true; + }; +} \ No newline at end of file