From 68488e306bf0cdc1e05b86102259b7f80ebaefd9 Mon Sep 17 00:00:00 2001 From: Mykhailo Nikiforov Date: Fri, 24 Oct 2025 10:35:01 +0300 Subject: [PATCH] feat: nixvim configuration init --- config/modules/plugins/blink-cmp.nix | 53 ++++++- config/modules/plugins/conform-nvim.nix | 190 +++++++++++++++++++++++- config/modules/plugins/snacks.nix | 1 + 3 files changed, 242 insertions(+), 2 deletions(-) diff --git a/config/modules/plugins/blink-cmp.nix b/config/modules/plugins/blink-cmp.nix index f991fde..c9976e5 100644 --- a/config/modules/plugins/blink-cmp.nix +++ b/config/modules/plugins/blink-cmp.nix @@ -1,3 +1,54 @@ { - plugins.blink-cmp.enable = true; + plugins.blink-cmp = { + enable = true; + settings = { + appearance = { + nerd_font_variant = "normal"; + use_nvim_cmp_as_default = true; + }; + completion = { + accept = { + auto_brackets = { + enabled = true; + semantic_token_resolution = { + enabled = false; + }; + }; + }; + trigger = { + show_on_keyword = true; + show_on_trigger_character = true; + }; + documentation = { + auto_show = true; + auto_show_delay_ms = 500; + }; + menu = { + auto_show = true; + }; + }; + keymap = { + preset = "default"; + }; + signature = { + enabled = true; + }; + sources = { + default = [ + "lsp" + "buffer" + "snippets" + "path" + ]; + providers = { + buffer = { + score_offset = -7; + }; + lsp = { + fallbacks = [ ]; + }; + }; + }; + }; + }; } diff --git a/config/modules/plugins/conform-nvim.nix b/config/modules/plugins/conform-nvim.nix index 50dce5a..84a838a 100644 --- a/config/modules/plugins/conform-nvim.nix +++ b/config/modules/plugins/conform-nvim.nix @@ -1,3 +1,191 @@ { - plugins.conform-nvim.enable = true; + lib, + pkgs, + ... +}: +{ + config = { + extraConfigLuaPre = + # lua + '' + local slow_format_filetypes = {} + + vim.api.nvim_create_user_command("FormatDisable", function(args) + if args.bang then + -- FormatDisable! will disable formatting just for this buffer + vim.b.disable_autoformat = true + else + vim.g.disable_autoformat = true + end + end, { + desc = "Disable autoformat-on-save", + bang = true, + }) + vim.api.nvim_create_user_command("FormatEnable", function() + vim.b.disable_autoformat = false + vim.g.disable_autoformat = false + end, { + desc = "Re-enable autoformat-on-save", + }) + vim.api.nvim_create_user_command("FormatToggle", function(args) + local Snacks = require("Snacks"); + if args.bang then + -- Toggle formatting for current buffer + vim.b.disable_autoformat = not vim.b.disable_autoformat + Snacks.notify.notify("[Buffer] Autoformat enabled: " .. tostring(not vim.b.disable_autoformat)) + else + -- Toggle formatting globally + vim.g.disable_autoformat = not vim.g.disable_autoformat + Snacks.notify.notify("[Global] Autoformat enabled: " .. tostring(not vim.g.disable_autoformat)) + end + end, { + desc = "Toggle autoformat-on-save", + bang = true, + }) + ''; + + plugins.conform-nvim = { + enable = true; + settings = { + format_on_save = '' + function(bufnr) + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then + return + end + + if slow_format_filetypes[vim.bo[bufnr].filetype] then + return + end + + 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 = 200, lsp_fallback = true }, on_format + end + ''; + + format_after_save = '' + function(bufnr) + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then + return + end + + if not slow_format_filetypes[vim.bo[bufnr].filetype] then + return + end + + return { lsp_fallback = true } + end + ''; + notify_on_error = true; + formatters_by_ft = { + html = { + __unkeyed-1 = "prettierd"; + __unkeyed-2 = "prettier"; + stop_after_first = true; + }; + css = { + __unkeyed-1 = "prettierd"; + __unkeyed-2 = "prettier"; + stop_after_first = true; + }; + javascript = { + __unkeyed-1 = "prettierd"; + __unkeyed-2 = "prettier"; + stop_after_first = true; + }; + javascriptreact = { + __unkeyed-1 = "prettierd"; + __unkeyed-2 = "prettier"; + stop_after_first = true; + }; + typescript = { + __unkeyed-1 = "prettierd"; + __unkeyed-2 = "prettier"; + stop_after_first = true; + }; + typescriptreact = { + __unkeyed-1 = "prettierd"; + __unkeyed-2 = "prettier"; + stop_after_first = true; + }; + python = [ "ruff" ]; + lua = [ "stylua" ]; + nix = [ "nixfmt-rfc-style" ]; + markdown = { + __unkeyed-1 = "prettierd"; + __unkeyed-2 = "prettier"; + stop_after_first = true; + }; + yaml = { + __unkeyed-1 = "prettierd"; + __unkeyed-2 = "prettier"; + stop_after_first = true; + }; + terraform = [ "terraform_fmt" ]; + bash = [ + "shellcheck" + "shellharden" + "shfmt" + ]; + json = [ "jq" ]; + "_" = [ "trim_whitespace" ]; + }; + + formatters = { + ruff = { + command = "${lib.getExe pkgs.ruff}"; + }; + nixfmt-rfc-style = { + command = "${lib.getExe pkgs.nixfmt-rfc-style}"; + }; + alejandra = { + command = "${lib.getExe pkgs.alejandra}"; + }; + jq = { + command = "${lib.getExe pkgs.jq}"; + }; + prettierd = { + command = "${lib.getExe pkgs.prettierd}"; + }; + stylua = { + command = "${lib.getExe pkgs.stylua}"; + }; + shellcheck = { + command = "${lib.getExe pkgs.shellcheck}"; + }; + shfmt = { + command = "${lib.getExe pkgs.shfmt}"; + }; + shellharden = { + command = "${lib.getExe pkgs.shellharden}"; + }; + yamlfmt = { + command = "${lib.getExe pkgs.yamlfmt}"; + }; + }; + }; + }; + keymaps = [ + { + mode = "n"; + key = "uf"; + action = "FormatToggle"; + options = { + desc = "Toggle Format (Global)"; + }; + } + { + mode = "n"; + key = "uF"; + action = "FormatToggle!"; + options = { + desc = "Toggle Format (Buffer)"; + }; + } + ]; + }; } diff --git a/config/modules/plugins/snacks.nix b/config/modules/plugins/snacks.nix index 55cc59b..bf37bc5 100644 --- a/config/modules/plugins/snacks.nix +++ b/config/modules/plugins/snacks.nix @@ -10,6 +10,7 @@ words.enabled = true; lazygit.enabled = true; picker.enabled = true; + indent.enabled = true; }; };