commit 1e2ca5a6fc105222ba8f2ee81ecc1778e80ce6e8 Author: sharings Date: Sat Jul 26 12:43:01 2025 +0000 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2be92b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result diff --git a/config/RememberFoldAndView.nix b/config/RememberFoldAndView.nix new file mode 100644 index 0000000..132f457 --- /dev/null +++ b/config/RememberFoldAndView.nix @@ -0,0 +1,35 @@ +{ + autoGroups = { + remember_fold_and_view = { + clear = true; + }; + }; + # :help loadview + autoCmd = [ + { + # https://vi.stackexchange.com/questions/13864/bufwinleave-mkview-with-unnamed-file-error-32 + pattern = [ "?*" ]; + event = [ + "BufWinLeave" + "BufLeave" + "BufWritePost" + "BufHidden" + "QuitPre" + ]; + nested = true; + desc = "Save view"; + group = "remember_fold_and_view"; + command = "mkview"; + } + { + # https://vi.stackexchange.com/questions/13864/bufwinleave-mkview-with-unnamed-file-error-32 + pattern = [ "?*" ]; + event = [ + "BufWinEnter" + ]; + desc = "Load view"; + group = "remember_fold_and_view"; + command = "silent! loadview"; + } + ]; +} diff --git a/config/TextYankPost.nix b/config/TextYankPost.nix new file mode 100644 index 0000000..99d25b2 --- /dev/null +++ b/config/TextYankPost.nix @@ -0,0 +1,38 @@ +{ helpers, ... }: +let + inherit (helpers) mkRaw; +in +{ + # https://github.com/nvim-lua/kickstart.nvim/blob/2ba39c69736597b60f6033aa3f8526e7c28343d5/init.lua#L196-L205 + # Highlight when yakning (copying) text + # Try in with `yap` in normal mode + # See `:help vim.highlight.on_yank()` + # vim.api.nvim_create_autocmd('TextYankPost', { + # desc = 'Highlight when yanking (copying) text', + # group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), + # callback = function() + # vim.highlight.on_yank() + # end, + # }) + + # https://www.youtube.com/watch?v=m8C0Cq9Uv9o&t=7m50s + # TJ: setup groups to prevent "duplicate event listeners", prevent running + # code twice + autoGroups = { + kickstart-highlight-yank = { + clear = true; + }; + }; + autoCmd = [ + { + event = [ "TextYankPost" ]; + desc = "Highlight when yanking (copying) text"; + group = "kickstart-highlight-yank"; + callback = mkRaw '' + function() + vim.highlight.on_yank() + end + ''; + } + ]; +} diff --git a/config/colorscheme/gruvbox.nix b/config/colorscheme/gruvbox.nix new file mode 100644 index 0000000..d2d15b8 --- /dev/null +++ b/config/colorscheme/gruvbox.nix @@ -0,0 +1,6 @@ +{ + colorschemes.gruvbox = { + enable = true; + settings.transparent_mode = true; + }; +} diff --git a/config/colorscheme/onedark.nix b/config/colorscheme/onedark.nix new file mode 100644 index 0000000..c315a94 --- /dev/null +++ b/config/colorscheme/onedark.nix @@ -0,0 +1,66 @@ +{ + colorschemes.onedark = { + enable = true; + settings = { + transparent = true; + style = "darker"; + diagnostics = { + darker = true; # -- darker colors for diagnostic + undercurl = true; # -- use undercurl instead of underline for diagnostics + background = true; # -- use background color for virtual text + }; + }; + }; + # extraConfigLua = '' + # ---------------------------------- + # -- START custom setup for onedark + # ---------------------------------- + # -- https://github.com/navarasu/onedark.nvim + # require('onedark').setup { + # -- Main options -- + # style = 'darker', -- Default theme style. Choose between 'dark', 'darker', 'cool', 'deep', 'warm', 'warmer' and 'light' + # transparent = true, -- Show/hide background + # term_colors = true, -- Change terminal color as per the selected theme style + # ending_tildes = false, -- Show the end-of-buffer tildes. By default they are hidden + # cmp_itemkind_reverse = false, -- reverse item kind highlights in cmp menu + + # -- toggle theme style --- + # -- toggle_style_key = nil, -- keybind to toggle theme style. Leave it nil to disable it, or set it to a string, for example "ts" + # toggle_style_key = "ts", -- keybind to toggle theme style. Leave it nil to disable it, or set it to a string, for example "ts" + # -- toggle_style_list = {'dark', 'darker', 'cool', 'deep', 'warm', 'warmer', 'light'}, -- List of styles to toggle between + # toggle_style_list = {'dark', 'darker', 'cool', 'deep', 'warm', 'warmer'}, -- List of styles to toggle between + + # -- Change code style --- + # -- Options are italic, bold, underline, none + # -- You can configure multiple style with comma seperated, For e.g., keywords = 'italic,bold' + # code_style = { + # comments = 'italic', + # keywords = 'none', + # functions = 'none', + # strings = 'none', + # variables = 'none' + # }, + + # -- Lualine options -- + # -- lualine = { + # -- transparent = true, -- lualine center bar transparency + # -- }, + + # -- Custom Highlights -- + # colors = {}, -- Override default colors + # highlights = {}, -- Override highlight groups + + # -- Plugins Config -- + # diagnostics = { + # darker = true, -- darker colors for diagnostic + # undercurl = true, -- use undercurl instead of underline for diagnostics + # background = true, -- use background color for virtual text + # }, + # } + + # require('onedark').load() + # ---------------------------------- + # -- END custom setup for onedark + # ---------------------------------- + # ''; +} diff --git a/config/colorscheme/tokyonight.nix b/config/colorscheme/tokyonight.nix new file mode 100644 index 0000000..19b4d61 --- /dev/null +++ b/config/colorscheme/tokyonight.nix @@ -0,0 +1,12 @@ +{ + colorschemes.tokyonight = { + enable = true; + settings = { + transparent = true; + styles = { + sidebars = "transparent"; + floats = "transparent"; + }; + }; + }; +} diff --git a/config/colorscheme/transparency.nix b/config/colorscheme/transparency.nix new file mode 100644 index 0000000..b9552d1 --- /dev/null +++ b/config/colorscheme/transparency.nix @@ -0,0 +1,7 @@ +{ + # use this to sen transparency instead to keep nvim-scrollview bar transparent + extraConfigLua = '' + -- :highlight Normal guibg = none + vim.api.nvim_set_hl(0, "Normal", { bg = "none" }) + ''; +} diff --git a/config/custom-modules/linediff/default.nix b/config/custom-modules/linediff/default.nix new file mode 100644 index 0000000..5a0db1c --- /dev/null +++ b/config/custom-modules/linediff/default.nix @@ -0,0 +1,17 @@ +# Not yet merge into nixos-25.05 +{ lib, ... }: +lib.nixvim.plugins.mkVimPlugin { + name = "linediff"; + packPathName = "linediff.vim"; + package = "linediff-vim"; + + globalPrefix = "linediff_"; + + maintainers = [ lib.maintainers.GaetanLepage ]; + + settingsExample = { + modify_statusline = 0; + first_buffer_command = "topleft new"; + second_buffer_command = "vertical new"; + }; +} diff --git a/config/default.nix b/config/default.nix new file mode 100644 index 0000000..f2483b2 --- /dev/null +++ b/config/default.nix @@ -0,0 +1,88 @@ +{ + system, + lib, + variant, + ... +}: +{ + # Import all your configuration modules here + imports = + # custom plugins modules + [ + # do not use it in nixpkgs-unstable + # ./custom-modules/linediff/default.nix + ] + ++ [ + ./TextYankPost.nix + ./RememberFoldAndView.nix + ./json-foldable.nix + + # ./colorscheme/onedark.nix + # ./colorscheme/gruvbox.nix + ./colorscheme/tokyonight.nix + # ./colorscheme/transparency.nix # This is not required since scrollview bar transparency already fix in tokyonight.nix + + ./sets.nix + ./keymaps.nix + + ./plugins/fcitx-vim.nix + # ./plugins/bufferline.nix + ./plugins/comment.nix + ./plugins/fugitive.nix + ./plugins/indent-blankline.nix + ./plugins/leap.nix + # ./plugins/flash.nix + # ./plugins/sleuth.nix + ./plugins/gitsigns.nix + ./plugins/which-key.nix + ./plugins/telescope.nix + ./plugins/mini.nix + # ./plugins/neoscroll.nix # very slow sometime + ./plugins/oil.nix + + ./plugins/git-conflict.nix + + ./plugins/extra/vim-rhubarb.nix + ./plugins/extra/nvim-scrollview.nix + ./plugins/harpoon.nix + ./plugins/undotree.nix + ./plugins/lualine.nix + + ./plugins/lsp/lsp.nix + ./plugins/csvview-nvim.nix + ./plugins/nvim-jqx.nix + + ./plugins/linediff.nix + ] + # Below plugins excluded in "nvim-nix-on-droid" and "nvim-lite" + # Use "nvim --startuptime startuptime.log" to test which plugin slow down nvim startup + ++ + lib.optionals + ( + variant == "full" + || variant == "normal" + ) + [ + ./plugins/cmp.nix + ./plugins/luasnip/luasnip.nix + + # treesitter extremely slow in nix-on-droid + ./plugins/treesitter.nix + ] + # Below plugins excluded in "nvim-nix-on-droid", "nvim-normal" and "nvim-lite" + ++ + lib.optionals + ( + variant == "full" + ) + [ + # https://github.com/nvim-tree/nvim-tree.lua + # A File Explorer For Neovim Written In Lua + ./plugins/nvim-tree.nix + + ./plugins/neorg.nix + ./plugins/image.nix # enable only when "core.latex.renderer" in neorg is set + # ./plugins/noice.nix #breaks :Neorg export dialogue + ./plugins/notify.nix + ]; +} diff --git a/config/json-foldable.nix b/config/json-foldable.nix new file mode 100644 index 0000000..137b5f1 --- /dev/null +++ b/config/json-foldable.nix @@ -0,0 +1,27 @@ +{ + autoGroups = { + json-foldable = { + clear = true; + }; + }; + autoCmd = [ + { + pattern = [ "*.json" ]; + event = [ + "BufRead" + "BufNewFile" + ]; + desc = "Available to make json files foldable"; + group = "json-foldable"; + # https://vi.stackexchange.com/questions/10562/how-to-fold-text-in-a-json-file + callback.__raw = '' + function() + vim.o.foldmethod = "expr" + vim.o.foldexpr = "nvim_treesitter#foldexpr()" + -- vim.o.foldlevelstart not working for unknown reason + vim.o.foldlevel = 99 + end + ''; + } + ]; +} diff --git a/config/keymaps.nix b/config/keymaps.nix new file mode 100644 index 0000000..368c394 --- /dev/null +++ b/config/keymaps.nix @@ -0,0 +1,79 @@ +{ + keymaps = [ + { + # vim.keymap.set({ "n", "v" }, "\\y", '"+y', {noremap=true, silent=true}) + mode = [ + "n" + "v" + ]; + key = "\\y"; + action = "\"+y"; + options = { + silent = true; + remap = false; + }; + } + { + mode = [ + "n" + "v" + ]; + key = "bp"; + action = "bprev"; + options.desc = "Previous buffer"; + } + { + mode = [ + "n" + "v" + ]; + key = "bn"; + action = "bnext"; + options.desc = "Next buffer"; + } + { + mode = [ + "n" + "v" + ]; + key = "bd"; + action = "bdelete"; + options.desc = "Delete buffer"; + } + { + mode = [ + "n" + "v" + ]; + key = "bD"; + action = "bdelete!"; + options.desc = "Delete buffer !"; + } + + # https://www.youtube.com/watch?v=w7i4amO_zaE + # keep search result in the middle of the screen + { + mode = [ "n" ]; + key = "n"; + action = "nzzzv"; + } + # keep search result in the middle of the screen + { + mode = [ "n" ]; + key = "N"; + action = "Nzzzv"; + } + # preserve previously copyed text when pasting when highlighting text + # otherwise, previously copyed text will be lost and clipboard will be filled with highlighted text + { + mode = [ "x" ]; + key = "p"; + action = "\"_dP"; + } + ]; + extraConfigLua = '' + -- see ":help default-mapping" + -- vim.cmd[[unmap Y]] + vim.keymap.del( "n", "Y" ) + ''; +} diff --git a/config/plugins/bufferline.nix b/config/plugins/bufferline.nix new file mode 100644 index 0000000..d001838 --- /dev/null +++ b/config/plugins/bufferline.nix @@ -0,0 +1,7 @@ +{ + plugins = { + bufferline = { + enable = true; + }; + }; +} diff --git a/config/plugins/cmp.nix b/config/plugins/cmp.nix new file mode 100644 index 0000000..92c0567 --- /dev/null +++ b/config/plugins/cmp.nix @@ -0,0 +1,66 @@ +{ + config, + lib, + helpers, + ... +}: +let + inherit (helpers) mkRaw; +in +{ + # TJ + # https://www.youtube.com/watch?v=_DnmphIwnjo + plugins = { + cmp = { + enable = true; + autoEnableSources = true; + settings = { + sources = + lib.optionals config.plugins.lsp.enable [ + { name = "nvim_lsp"; } + ] + ++ lib.optionals config.plugins.luasnip.enable [ + { + name = "luasnip"; + option = { + show_autosnippets = true; + }; + } + ] + ++ [ + { name = "path"; } + { name = "spell"; } + { name = "latex_symbols"; } + { + name = "buffer"; + keyword_length = 5; + } + ]; + mapping = mkRaw '' + cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }), + }) + ''; + snippet.expand = '' + function(args) + require('luasnip').lsp_expand(args.body) + end + ''; + experimental = { + # ghost_text = true; + }; + view.entries = { + name = "custom"; + # selection_order = "top_down"; + }; + }; + }; + }; +} diff --git a/config/plugins/comment.nix b/config/plugins/comment.nix new file mode 100644 index 0000000..a0261b5 --- /dev/null +++ b/config/plugins/comment.nix @@ -0,0 +1,7 @@ +{ + plugins = { + comment = { + enable = true; + }; + }; +} diff --git a/config/plugins/csvview-nvim.nix b/config/plugins/csvview-nvim.nix new file mode 100644 index 0000000..e9ba9db --- /dev/null +++ b/config/plugins/csvview-nvim.nix @@ -0,0 +1,17 @@ +{ + pkgs, + ... +}: +{ + # in 20241208, csvview-nvim not available in nixos-24.11 yet + extraPlugins = with pkgs.vimPlugins; [ csvview-nvim ]; + extraConfigLua = '' + require('csvview').setup({ + -- Add your configuration here + vim.keymap.set( 'n', 'ct', function() require('csvview').toggle() end, { desc = 'CsvViewToggle' }), + view = { + display_mode = "border", + }, + }) + ''; +} diff --git a/config/plugins/extra/nvim-scrollview.nix b/config/plugins/extra/nvim-scrollview.nix new file mode 100644 index 0000000..29ef5ee --- /dev/null +++ b/config/plugins/extra/nvim-scrollview.nix @@ -0,0 +1,21 @@ +# {pkgs, ...}: { +# extraPlugins = with pkgs.vimPlugins; [nvim-scrollview]; +# +# # gitsigns support +# # https://github.com/dstein64/nvim-scrollview/blob/main/lua/scrollview/contrib/gitsigns.lua +# extraConfigLua = '' +# require('scrollview.contrib.gitsigns').setup({ }) +# ''; +# } +{ + plugins = { + scrollview = { + enable = true; + settings = { + winblend_gui = 35; + hide_on_intersect = true; + signs_hidden_for_insert = [ "all" ]; + }; + }; + }; +} diff --git a/config/plugins/extra/vim-rhubarb.nix b/config/plugins/extra/vim-rhubarb.nix new file mode 100644 index 0000000..9e18f5a --- /dev/null +++ b/config/plugins/extra/vim-rhubarb.nix @@ -0,0 +1,4 @@ +{ pkgs, ... }: +{ + extraPlugins = with pkgs.vimPlugins; [ vim-rhubarb ]; +} diff --git a/config/plugins/fcitx-vim.nix b/config/plugins/fcitx-vim.nix new file mode 100644 index 0000000..d322e14 --- /dev/null +++ b/config/plugins/fcitx-vim.nix @@ -0,0 +1,11 @@ +{ pkgs, ... }: +{ + # https://github.com/h-hg/fcitx.nvim + extraPlugins = with pkgs.vimPlugins; [ fcitx-vim ]; + + extraConfigLua = '' + -- let g:fcitx5_rime = 1 + vim.g.fcitx5_rime = 1; + vim.g.fcitx5_remote = "${pkgs.fcitx5}/bin/fcitx5-remote"; + ''; +} diff --git a/config/plugins/flash.nix b/config/plugins/flash.nix new file mode 100644 index 0000000..b9581a8 --- /dev/null +++ b/config/plugins/flash.nix @@ -0,0 +1,23 @@ +{ helpers, ... }: +let + inherit (helpers) mkRaw; +in +{ + plugins.flash = { + enable = true; + }; + keymaps = [ + { + mode = [ + "n" + "x" + "o" + ]; + key = "ss"; + action = mkRaw '' + function() require("flash").jump() end + ''; + options.desc = "Flash jump"; + } + ]; +} diff --git a/config/plugins/fugitive.nix b/config/plugins/fugitive.nix new file mode 100644 index 0000000..e312e46 --- /dev/null +++ b/config/plugins/fugitive.nix @@ -0,0 +1,21 @@ +{ + plugins = { + fugitive = { + enable = true; + }; + }; + keymaps = [ + { + mode = [ "n" ]; + key = "git"; + action.__raw = ''function() vim.cmd('Git') end ''; + options.desc = "[fujitive] Git"; + } + { + mode = [ "n" ]; + key = "G"; + action.__raw = ''function() vim.api.nvim_feedkeys(':Git ', 'n', true) end ''; + options.desc = "[fujitive] :Git"; + } + ]; +} diff --git a/config/plugins/git-conflict.nix b/config/plugins/git-conflict.nix new file mode 100644 index 0000000..fce848d --- /dev/null +++ b/config/plugins/git-conflict.nix @@ -0,0 +1,24 @@ +{ + plugins = { + git-conflict = { + enable = true; + settings = { + default_commands = true; + default_mappings = { + both = "Gb"; + next = "Gn"; + none = "G0"; + ours = "Go"; + prev = "Gp"; + theirs = "Gt"; + }; + disable_diagnostics = false; + highlights = { + current = "DiffText"; + incoming = "DiffAdd"; + }; + list_opener = "copen"; + }; + }; + }; +} diff --git a/config/plugins/gitsigns.nix b/config/plugins/gitsigns.nix new file mode 100644 index 0000000..128ad6c --- /dev/null +++ b/config/plugins/gitsigns.nix @@ -0,0 +1,58 @@ +{ + plugins = { + gitsigns = { + enable = true; + settings = { + # https://github.com/lewis6991/gitsigns.nvim + # https://nix-community.github.io/nixvim/plugins/gitsigns/settings/index.html + on_attach = '' + function(bufnr) + local gitsigns = require('gitsigns') + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then + vim.cmd.normal({']c', bang = true}) + else + gitsigns.nav_hunk('next') + end + end) + + map('n', '[c', function() + if vim.wo.diff then + vim.cmd.normal({'[c', bang = true}) + else + gitsigns.nav_hunk('prev') + end + end) + + -- Setup keymaps + local gitsigns = require('gitsigns') + map('n', 'hs', gitsigns.stage_hunk, { desc = "Stage hunk" } ) + map('n', 'hr', gitsigns.reset_hunk, { desc = "Reset hunk" } ) + map('v', 'hs', function() gitsigns.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end, { desc = "Stage hunk" } ) + map('v', 'hr', function() gitsigns.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end, { desc = "Reset hunk" } ) + map('n', 'hS', gitsigns.stage_buffer, { desc = "Stage buffer" } ) + map('n', 'hu', gitsigns.undo_stage_hunk, { desc = "Undo stage hunk" } ) + map('n', 'hR', gitsigns.reset_buffer, { desc = "Reset buffer" } ) + map('n', 'hp', gitsigns.preview_hunk, { desc = "Preview hunk" } ) + map('n', 'hP', gitsigns.preview_hunk_inline, { desc = "Preview hunk inline" } ) + -- map('n', 'hb', function() gitsigns.blame_line{full=true} end, { desc = "Blame line full" } ) + map('n', 'hb', function() gitsigns.blame_line{full=false} end, { desc = "Blame line" } ) + map('n', 'hB', function() gitsigns.blame() end, { desc = "Blame" } ) + map('n', 'tb', gitsigns.toggle_current_line_blame, { desc = "Toggle current line blame" } ) + map('n', 'hd', gitsigns.diffthis, { desc = "Diffthis" } ) + map('n', 'hD', function() gitsigns.diffthis('~') end, { desc = "Diffthis ~" } ) + map('n', 'td', gitsigns.toggle_deleted, { desc = "Toggle deleted" } ) + end + ''; + }; + }; + }; +} diff --git a/config/plugins/harpoon.nix b/config/plugins/harpoon.nix new file mode 100644 index 0000000..7b92980 --- /dev/null +++ b/config/plugins/harpoon.nix @@ -0,0 +1,108 @@ +{ + plugins = { + harpoon = { + enable = true; + settings = { + # save_on_toggle = true; + # sync_on_ui_close = false; + }; + + # DEPRECATED, keep the comments because not all moved to keymaps + # + # enableTelescope = true; + # keymaps = { + # /* + # DUPRECATED, moved to keymaps session + # navFile = { + # "1" = ""; + # "2" = ""; + # "3" = ""; + # # "4" = ""; # breaks neorg links ( also treat as Enter key in terminal) + # "4" = ""; + # # "5" = ""; # spare for luasnip + # }; + # */ + # + # /* + # # https://github.com/ThePrimeagen/harpoon/issues/487 + # # DUPRECATED, but seems not yet implemented very well in harpoon2 + # gotoTerminal = { + # "1" = "1"; + # "2" = "2"; + # "3" = "3"; + # "4" = "4"; + # "5" = "5"; + # }; + # */ + # + # # Moved to keymaps session to add descriptions + # # addFile = "hm"; + # # toggleQuickMenu = "ht"; + # # navNext = ""; + # # navPrev = ""; + # }; + }; + }; + keymaps = [ + { + mode = "n"; + key = ""; + action.__raw = "function() require'harpoon':list():select(1) end"; + } + { + mode = "n"; + key = ""; + action.__raw = "function() require'harpoon':list():select(2) end"; + } + { + mode = "n"; + key = ""; + action.__raw = "function() require'harpoon':list():select(3) end"; + } + { + mode = "n"; + key = ""; + action.__raw = "function() require'harpoon':list():select(4) end"; + } + { + mode = "n"; + key = "hm"; + options = { + silent = false; + desc = "Harpoon marks current file"; + }; + # action = mkRaw "require('harpoon.mark').add_file"; + action.__raw = "function() require'harpoon':list():add() end"; + } + { + mode = "n"; + key = "ht"; + options = { + silent = false; + desc = "Harpoon quick menu toggle"; + }; + # action = mkRaw "require('harpoon.ui').toggle_quick_menu"; + action.__raw = "function() require'harpoon.ui':toggle_quick_menu(harpoon:list()) end"; + } + { + mode = "n"; + key = ""; + options = { + silent = false; + desc = "Harpoon next file"; + }; + # action = mkRaw "require('harpoon.ui').nav_next"; + action.__raw = "function() require'harpoon':list():next() end"; + } + { + mode = "n"; + key = ""; + options = { + silent = false; + desc = "Harpoon previous file"; + }; + # action = mkRaw "require('harpoon.ui').nav_prev"; + action.__raw = "function() require'harpoon':list():prev() end"; + } + ]; +} diff --git a/config/plugins/image.nix b/config/plugins/image.nix new file mode 100644 index 0000000..fa73d96 --- /dev/null +++ b/config/plugins/image.nix @@ -0,0 +1,30 @@ +{ + pkgs, + config, + lib, + ... +}: +{ + plugins = { + # For "core.latex.renderer" to work + image = { + enable = lib.mkIf (builtins.hasAttr "core.latex.renderer" config.plugins.neorg.settings.load) true; + settings.integrations = { + backend = "ueberzug"; + neorg = { + enabled = true; + clearInInsertMode = true; + filetypes = [ "norg" ]; + }; + markdown = { + enabled = true; + clearInInsertMode = true; + filetypes = [ + "markdown" + "vimwiki" + ]; + }; + }; + }; + }; +} diff --git a/config/plugins/indent-blankline.nix b/config/plugins/indent-blankline.nix new file mode 100644 index 0000000..c78e260 --- /dev/null +++ b/config/plugins/indent-blankline.nix @@ -0,0 +1,36 @@ +{ + plugins = { + indent-blankline = { + enable = true; + settings = { + indent = { + char = "│"; # "│" or "▎" + tab_char = "┊"; + }; + scope = { + enabled = true; + show_start = true; + }; + exclude = { + buftypes = [ + "terminal" + "nofile" + ]; + filetypes = [ + "help" + "alpha" + "dashboard" + "neo-tree" + "Trouble" + "trouble" + "lazy" + "mason" + "notify" + "toggleterm" + "lazyterm" + ]; + }; + }; + }; + }; +} diff --git a/config/plugins/leap.nix b/config/plugins/leap.nix new file mode 100644 index 0000000..7c6d16e --- /dev/null +++ b/config/plugins/leap.nix @@ -0,0 +1,77 @@ +{ helpers, ... }: +let + inherit (helpers) mkRaw; +in +{ + plugins.leap = { + enable = true; + addDefaultMappings = false; + }; + keymaps = [ + { + mode = [ "n" ]; + key = "ss"; + action = mkRaw "function () require('leap').leap {} end"; + options.desc = "leap"; + } + { + mode = [ + "x" + "o" + ]; + key = "ss"; + action = mkRaw "function () require('leap').leap { inclusive_op = true } end"; + options.desc = "leap"; + } + { + mode = [ + "n" + "x" + "o" + ]; + key = "sS"; + action = "(leap-backward-to)"; + options.desc = "leap-backward-to"; + } + { + mode = [ + "n" + "x" + "o" + ]; + key = "sx"; + action = "(leap-forward-till)"; + options.desc = "leap-forward-till"; + } + { + mode = [ + "n" + "x" + "o" + ]; + key = "sX"; + action = "(leap-backward-till)"; + options.desc = "leap-backward-till"; + } + { + mode = [ + "n" + "x" + "o" + ]; + key = "sgs"; + action = "(leap-from-window)"; + options.desc = "leap-from-window"; + } + { + mode = [ + "n" + "x" + "o" + ]; + key = "sgs"; + action = "(leap-cross-window)"; + options.desc = "leap-cross-window"; + } + ]; +} diff --git a/config/plugins/linediff.nix b/config/plugins/linediff.nix new file mode 100644 index 0000000..14a344b --- /dev/null +++ b/config/plugins/linediff.nix @@ -0,0 +1,19 @@ +{ + plugins.linediff.enable = true; +} + +# { lib, ... }: +# lib.nixvim.plugins.mkVimPlugin { +# name = "linediff"; +# packPathName = "linediff.vim"; +# package = "linediff-vim"; +# +# globalPrefix = "linediff_"; +# +# maintainers = [ lib.maintainers.GaetanLepage ]; +# +# settingsExample = { +# modify_statusline = 0; +# first_buffer_command = "topleft new"; +# second_buffer_command = "vertical new"; +# }; diff --git a/config/plugins/lsp/conform-nvim.nix b/config/plugins/lsp/conform-nvim.nix new file mode 100644 index 0000000..0daa7a3 --- /dev/null +++ b/config/plugins/lsp/conform-nvim.nix @@ -0,0 +1,152 @@ +{ + lib, + config, + helpers, + pkgs, + ... +}: +let + inherit (helpers) mkRaw; +in +{ + plugins = { + # https://github.com/stevearc/conform.nvim/ + # Preserves extmarks and folds + # Fixes bad-behaving LSP formatters + # Enables range formatting for all formatters + # And more + conform-nvim = { + enable = lib.mkIf config.plugins.lsp.enable true; + settings = { + formatters_by_ft = { + perl = [ "perltidy" ]; + # nix = ["nixfmt" "alejandra"]; + nix = [ "nixfmt" ]; + sh = [ + "shellcheck" + "shellharden" + "shfmt" + ]; + bash = [ + "shellcheck" + "shellharden" + "shfmt" + ]; + cpp = [ "clang_format" ]; + javascript = { + __unkeyed-1 = "prettierd"; + __unkeyed-2 = "prettier"; + timeout_ms = 2000; + stop_after_first = true; + }; + lua = [ "stylua" ]; + # -- Conform will run multiple formatters sequentially + python = [ + "isort" + "black" + ]; + # -- You can customize some of the format options for the filetype (:help conform.format) + rust = { + _unkeyed-1 = "rustfmt"; + lsp_format = "fallback"; + }; + tex = [ "latexindent" ]; + # Use the "_" filetype to run formatters on filetypes that don't + # have other formatters configured. + "_" = [ + "squeeze_blanks" + "trim_whitespace" + "trim_newlines" + ]; + }; + # format_on_save = + # # Lua + # '' + # 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 = + # # Lua + # '' + # 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 + # ''; + log_level = "warn"; + notify_on_error = true; + notify_no_formatters = true; + formatters = { + perltidy = { + command = lib.getExe pkgs.perlPackages.PerlTidy; + prepend_args = [ "-i=2" ]; # default 4 spaces + }; + shfmt = { + command = lib.getExe pkgs.shfmt; + }; + shellcheck = { + command = lib.getExe pkgs.shellcheck; + }; + shellharden = { + command = lib.getExe pkgs.shellharden; + }; + squeeze_blanks = { + command = lib.getExe' pkgs.coreutils "cat"; + }; + latexindent = { + command = lib.getExe' pkgs.texlivePackages.latexindent "latexindent"; + # latexindent always produce indent.log in the current directory. It cannot be disabled in indentconfig.yaml + # This flag redirect it to /dev/null + prepend_args = [ + "-g" + "/dev/null" + ]; + }; + # alejandra = { + # command = lib.getExe pkgs.alejandra; + # prepend_args = ["--quiet"]; + # }; + nixfmt = { + command = lib.getExe pkgs.nixfmt-rfc-style; + }; + stylua = { + command = lib.getExe pkgs.stylua; + }; + }; + }; + }; + }; + keymaps = [ + { + mode = [ "n" ]; + key = "lf"; + action = mkRaw '' + function() + require("conform").format() + end''; + options.desc = "Format with conform-nvim"; + } + ]; +} diff --git a/config/plugins/lsp/lsp.nix b/config/plugins/lsp/lsp.nix new file mode 100644 index 0000000..e46fe97 --- /dev/null +++ b/config/plugins/lsp/lsp.nix @@ -0,0 +1,133 @@ +{ + lib, + ... +}: +{ + imports = [ + ./lspkind.nix + ./conform-nvim.nix # fix lsp formatter issues + + ./servers/clangd.nix + ./servers/eslint.nix + ./servers/pyright.nix + ./servers/ruff.nix + ./servers/lua_ls.nix + ./servers/bashls.nix + # ./servers/nil_ls.nix # replaced by nixd + ./servers/nixd.nix + ./servers/rust_analyzer.nix + ./servers/ts_ls.nix + ./servers/texlab/texlab.nix + ]; + plugins = { + # # https://github.com/lukas-reineke/lsp-format.nvim/ + # # auto format on save + # lsp-format = { + # enable = false; # Enable it if you want lsp-format integration for none-ls + # }; + # # formatter and diagnose + # none-ls = { + # enable = true; + # # don't enable use lsp-format plugin + # enableLspFormat = false; + # sources = { + # formatting = { + # alejandra.enable = true; + # stylua.enable = true; + # }; + # }; + # }; + lsp = { + enable = true; + capabilities = "offsetEncoding = 'utf-16'"; + keymaps = { + silent = true; + lspBuf = { + # use require("conform").format() instead + # "lf" = { + # action = "format"; + # desc = "Lsp format"; + # }; + gd = { + action = "definition"; + desc = "Goto Definition"; + }; + gr = { + action = "references"; + desc = "Goto References"; + }; + gD = { + action = "declaration"; + desc = "Goto Declaration"; + }; + gI = { + action = "implementation"; + desc = "Goto Implementation"; + }; + gT = { + action = "type_definition"; + desc = "Type Definition"; + }; + K = { + action = "hover"; + desc = "Hover"; + }; + "cw" = { + action = "workspace_symbol"; + desc = "Workspace Symbol"; + }; + "cr" = { + action = "rename"; + desc = "Rename"; + }; + "ca" = { + action = "code_action"; + desc = "Code Action"; + }; + # "" = { + "" = { + action = "signature_help"; + desc = "Signature Help"; + }; + }; + diagnostic = { + "cd" = { + action = "open_float"; + desc = "Line Diagnostics"; + }; + "[d" = { + action = "goto_next"; + desc = "Next Diagnostic"; + }; + "]d" = { + action = "goto_prev"; + desc = "Previous Diagnostic"; + }; + }; + }; + }; + }; + extraConfigLua = '' + local _border = "rounded" + + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with( + vim.lsp.handlers.hover, { + border = _border + } + ) + + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with( + vim.lsp.handlers.signature_help, { + border = _border + } + ) + + vim.diagnostic.config{ + float={border=_border} + }; + + require('lspconfig.ui.windows').default_options = { + border = _border + } + ''; +} diff --git a/config/plugins/lsp/lspkind.nix b/config/plugins/lsp/lspkind.nix new file mode 100644 index 0000000..cf91d25 --- /dev/null +++ b/config/plugins/lsp/lspkind.nix @@ -0,0 +1,19 @@ +{ + lib, + config, + helpers, + ... +}: +let + inherit (helpers) mkRaw; +in +{ + # TJ + # https://www.youtube.com/watch?v=_DnmphIwnjo + plugins = { + # Make cmp have icons and colors + lspkind = { + enable = lib.mkIf config.plugins.cmp.enable true; + }; + }; +} diff --git a/config/plugins/lsp/servers/bashls.nix b/config/plugins/lsp/servers/bashls.nix new file mode 100644 index 0000000..2374d04 --- /dev/null +++ b/config/plugins/lsp/servers/bashls.nix @@ -0,0 +1,24 @@ +{ + plugins.lsp.servers = { + bashls = { + enable = true; + filetypes = [ + "sh" + "bash" + ]; + # extraOptions = { + # settings = { + # Lua = { + # completion = { + # callSnippet = "Replace"; + # }; + # telemetry = { + # enabled = false; + # }; + # hint = {enable = true;}; + # }; + # }; + # }; + }; + }; +} diff --git a/config/plugins/lsp/servers/clangd.nix b/config/plugins/lsp/servers/clangd.nix new file mode 100644 index 0000000..eab118f --- /dev/null +++ b/config/plugins/lsp/servers/clangd.nix @@ -0,0 +1,7 @@ +{ + plugins = { + lsp.servers = { + clangd.enable = true; + }; + }; +} diff --git a/config/plugins/lsp/servers/eslint.nix b/config/plugins/lsp/servers/eslint.nix new file mode 100644 index 0000000..3830580 --- /dev/null +++ b/config/plugins/lsp/servers/eslint.nix @@ -0,0 +1,7 @@ +{ + plugins = { + lsp.servers = { + eslint.enable = true; + }; + }; +} diff --git a/config/plugins/lsp/servers/lua_ls.nix b/config/plugins/lsp/servers/lua_ls.nix new file mode 100644 index 0000000..49041fd --- /dev/null +++ b/config/plugins/lsp/servers/lua_ls.nix @@ -0,0 +1,22 @@ +{ + plugins.lsp.servers = { + lua_ls = { + enable = true; + extraOptions = { + settings = { + Lua = { + completion = { + callSnippet = "Replace"; + }; + telemetry = { + enabled = false; + }; + hint = { + enable = true; + }; + }; + }; + }; + }; + }; +} diff --git a/config/plugins/lsp/servers/nil_ls.nix b/config/plugins/lsp/servers/nil_ls.nix new file mode 100644 index 0000000..2876011 --- /dev/null +++ b/config/plugins/lsp/servers/nil_ls.nix @@ -0,0 +1,12 @@ +{ + plugins.lsp.servers = { + nil_ls = { + enable = true; + # Fix error message: + # lsp.message LSP Message (nil_ls) Some flake inputs are not available, please run `nix flake archive` to fetch them. + # Your LSP client doesn't support confirmation. You can enable autoArchive in lsp configuration. + # https://github.com/oxalica/nil/issues/131#issuecomment-2241281279 + settings.nix.flake.autoArchive = false; + }; + }; +} diff --git a/config/plugins/lsp/servers/nixd.nix b/config/plugins/lsp/servers/nixd.nix new file mode 100644 index 0000000..5a7040d --- /dev/null +++ b/config/plugins/lsp/servers/nixd.nix @@ -0,0 +1,21 @@ +{ + variant, + lib, + self, + system, + ... +}: +{ + plugins.lsp.servers = { + nixd = { + enable = true; + settings = lib.mkMerge [ + { + diagnostic.suppress = [ ]; + # This will not be used, formatters use conform-nvim.nix instead in keymaps + # formatting.command = ["alejandra"]; + } + ]; + }; + }; +} diff --git a/config/plugins/lsp/servers/pyright.nix b/config/plugins/lsp/servers/pyright.nix new file mode 100644 index 0000000..5567fd4 --- /dev/null +++ b/config/plugins/lsp/servers/pyright.nix @@ -0,0 +1,7 @@ +{ + plugins = { + lsp.servers = { + pyright.enable = true; + }; + }; +} diff --git a/config/plugins/lsp/servers/ruff.nix b/config/plugins/lsp/servers/ruff.nix new file mode 100644 index 0000000..386a832 --- /dev/null +++ b/config/plugins/lsp/servers/ruff.nix @@ -0,0 +1,7 @@ +{ + plugins = { + lsp.servers = { + ruff.enable = true; + }; + }; +} diff --git a/config/plugins/lsp/servers/rust_analyzer.nix b/config/plugins/lsp/servers/rust_analyzer.nix new file mode 100644 index 0000000..f671b78 --- /dev/null +++ b/config/plugins/lsp/servers/rust_analyzer.nix @@ -0,0 +1,24 @@ +{ + plugins.lsp.servers = { + rust_analyzer = { + enable = true; + installCargo = true; + installRustc = true; + settings = { + checkOnSave = true; + check = { + command = "clippy"; + }; + # inlayHints = { + # enable = true; + # showParameterNames = true; + # parameterHintsPrefix = "<- "; + # otherHintsPrefix = "=> "; + # }; + procMacro = { + enable = true; + }; + }; + }; + }; +} diff --git a/config/plugins/lsp/servers/texlab/indentconfig.yaml b/config/plugins/lsp/servers/texlab/indentconfig.yaml new file mode 100644 index 0000000..fef4824 --- /dev/null +++ b/config/plugins/lsp/servers/texlab/indentconfig.yaml @@ -0,0 +1 @@ +# defaultIndent: " " diff --git a/config/plugins/lsp/servers/texlab/texlab.nix b/config/plugins/lsp/servers/texlab/texlab.nix new file mode 100644 index 0000000..c87be62 --- /dev/null +++ b/config/plugins/lsp/servers/texlab/texlab.nix @@ -0,0 +1,117 @@ +{ + lib, + helpers, + ... +}: +let + inherit (helpers) mkRaw; + use_tectonic = false; +in +{ + plugins.lsp.servers = { + texlab = { + enable = true; + filetypes = [ + "tex" + "plaintex" + "bib" + ]; + settings = { + texlab = { + # -------------------------------- + # -- START texlab main config + # -- if used with texmagic, disable this + # -------------------------------- + # https://github.com/latex-lsp/texlab/wiki/Configuration#deprecated-texlabauxdirectory + # auxDirectory = "tex_aux_output"; # deprecated + rootDirectory = false; + build = lib.mkMerge [ + (lib.mkIf (!use_tectonic) { + executable = "latexmk"; + args = [ + "-xelatex" + "-verbose" + # -- "-outdir=%f_output" + # -- "-auxdir=%f_aux" + "-auxdir=tex_aux_output" + "-file-line-error" + # https://github.com/latex-lsp/texlab/wiki/Previewing + # use for forward serach and inverse search + "-synctex=1" + + "-interaction=nonstopmode" + # "-pvc" # preview continuously update instead if -pv (open a new instance) + "%f" + ]; + }) + (lib.mkIf use_tectonic { + executable = "tectonic"; + # https://github.com/latex-lsp/texlab/wiki/Tectonic + # V2 + args = [ + "-X" + "compile" + "%f" + "--synctex" + "--keep-logs" + "--keep-intermediates" + ]; + }) + { + auxDirectory = "tex_aux_output"; + logDirectory = "tex_aux_output"; + pdfDirectory = "."; + # -- forwardSearchAfter = true, + isContinuous = true; + # -- "onSave = true" failed to work properly with large files like moderncv + # -- it would not build properly until you delete all the intermediate files + onSave = true; + # -------------------------------- + # -- END texlab main config + # -- if used with texmagic, disable this + # -------------------------------- + # https://github.com/latex-lsp/texlab/wiki/Previewing#zathura + } + ]; + forwardSearch = { + executable = "zathura"; + args = [ + "--synctex-forward" + "%l:1:%f" + "%p" + ]; + }; + # Inverse Search for zathura set in ~/.config/zathura/zathurarc + # set synctex true + # set synctex-editor-command "texlab inverse-search -i %{input} -l %{line}" + chktex = { + onOpenAndSave = true; + onEdit = true; + }; + # https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/configs/texlab.lua#L179-L183 + # https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/configs/texlab.lua#L179-L183 + latexindent = { + local = ./indentconfig.yaml; + }; + }; + }; + }; + }; + autoCmd = [ + { + pattern = [ "tex" ]; + event = [ "FileType" ]; + callback = mkRaw '' + function() + -- vim.keymap.set( 'n', 'TH', "TexlabBuild", { desc = 'TexlabBuild' }) + -- vim.keymap.set( 'n', 'TD', "TexlabCleanAuxiliary", { desc = 'TexlabCleanAuxiliary' }) + -- vim.keymap.set( 'n', 'TN', "TexlabForward", { desc = 'TexlabForward' }) + vim.keymap.set( 'n', 'TH', function() vim.cmd.TexlabBuild() end, { desc = 'TexlabBuild' }) + vim.keymap.set( 'n', 'TD', function() vim.cmd.TexlabCancelBuild(); vim.cmd.TexlabCleanAuxiliary() end, { desc = 'TexlabCancelBuild+CleanAuxiliary' }) + vim.keymap.set( 'n', 'Td', function() vim.cmd.TexlabCleanArtifacts() end, { desc = 'TexlabCleanArtifacts' }) + vim.keymap.set( 'n', 'TN', function() vim.cmd.TexlabForward() end, { desc = 'TexlabForward' }) + end + ''; + } + ]; +} diff --git a/config/plugins/lsp/servers/ts_ls.nix b/config/plugins/lsp/servers/ts_ls.nix new file mode 100644 index 0000000..de7c9f3 --- /dev/null +++ b/config/plugins/lsp/servers/ts_ls.nix @@ -0,0 +1,39 @@ +{ + plugins.lsp.servers = { + ts_ls = { + enable = false; + filetypes = [ + "javascript" + "javascriptreact" + "typescript" + "typescriptreact" + ]; + extraOptions = { + settings = { + javascript = { + inlayHints = { + includeInlayEnumMemberValueHints = true; + includeInlayFunctionLikeReturnTypeHints = true; + includeInlayFunctionParameterTypeHints = true; + includeInlayParameterNameHints = "all"; + includeInlayParameterNameHintsWhenArgumentMatchesName = true; + includeInlayPropertyDeclarationTypeHints = true; + includeInlayVariableTypeHints = true; + }; + }; + typescript = { + inlayHints = { + includeInlayEnumMemberValueHints = true; + includeInlayFunctionLikeReturnTypeHints = true; + includeInlayFunctionParameterTypeHints = true; + includeInlayParameterNameHints = "all"; + includeInlayParameterNameHintsWhenArgumentMatchesName = true; + includeInlayPropertyDeclarationTypeHints = true; + includeInlayVariableTypeHints = true; + }; + }; + }; + }; + }; + }; +} diff --git a/config/plugins/lualine.nix b/config/plugins/lualine.nix new file mode 100644 index 0000000..45948ac --- /dev/null +++ b/config/plugins/lualine.nix @@ -0,0 +1,27 @@ +{ + config, + lib, + ... +}: +{ + plugins = { + lualine = { + enable = true; + # Show @recording messages + # https://github.com/folke/noice.nvim/wiki/Configuration-Recipes#show-recording-messages + luaConfig.pre = lib.mkIf config.plugins.noice.enable '' + require("lualine").setup({ + sections = { + lualine_x = { + { + require("noice").api.statusline.mode.get, + cond = require("noice").api.statusline.mode.has, + color = { fg = "#ff9e64" } + } + }, + }, + }) + ''; + }; + }; +} diff --git a/config/plugins/luasnip/helpers/luasnip-helper-funcs.lua b/config/plugins/luasnip/helpers/luasnip-helper-funcs.lua new file mode 100644 index 0000000..4f9d2e6 --- /dev/null +++ b/config/plugins/luasnip/helpers/luasnip-helper-funcs.lua @@ -0,0 +1,68 @@ +local M = {} + +-- stop lsp error messages +-- https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#loaders +local ls = require("luasnip") +local s = ls.snippet +local sn = ls.snippet_node +local isn = ls.indent_snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node +local r = ls.restore_node +local events = require("luasnip.util.events") +local ai = require("luasnip.nodes.absolute_indexer") +local extras = require("luasnip.extras") +local l = extras.lambda +local rep = extras.rep +local p = extras.partial +local m = extras.match +local n = extras.nonempty +local dl = extras.dynamic_lambda +local fmt = require("luasnip.extras.fmt").fmt +local fmta = require("luasnip.extras.fmt").fmta +local conds = require("luasnip.extras.expand_conditions") +local postfix = require("luasnip.extras.postfix").postfix +local types = require("luasnip.util.types") +local parse = require("luasnip.util.parser").parse_snippet +local ms = ls.multi_snippet +local k = require("luasnip.nodes.key_indexer").new_key +-- Example: expanding a snippet on a new line only. +-- In a snippet file, first require the line_begin condition... +local line_begin = conds.line_begin + +-- This is the `get_visual` function I've been talking about. +-- ---------------------------------------------------------------------------- +-- Summary: When `LS_SELECT_RAW` is populated with a visual selection, the function +-- returns an insert node whose initial text is set to the visual selection. +-- When `LS_SELECT_RAW` is empty, the function simply returns an empty insert node. +M.get_visual = function(_, parent, _, user_args) + if #parent.snippet.env.LS_SELECT_RAW > 0 then + return sn(nil, i(1, parent.snippet.env.LS_SELECT_RAW)) + else -- If LS_SELECT_RAW is empty, return a blank insert node + return sn(nil, i(1, user_args)) + end +end + +-- https://github.com/L3MON4D3/LuaSnip/discussions/1195 +M.make_single_curly_bracket_snippets = function(type, trig, command, user_args) + -- return s({trig=keyword,desc=desc}, {t"local function " .. keyword .. "(", i(1), t")"}) + return s({ + trig = trig, + desc = "Expand " .. trig .. " into \\" .. command .. "{}", + snippetType = type, + }, fmt("\\" .. command .. "{<>}", { d(1, M.get_visual, { user_args = { user_args } }) }, { delimiters = "<>" })) +end + +M.make_scope_snippets = function(type, trig, command, user_args) + -- return s({trig=keyword,desc=desc}, {t"local function " .. keyword .. "(", i(1), t")"}) + return s({ + trig = trig, + desc = "Expand " .. trig .. " into {\\" .. command .. " ... }", + snippetType = type, + }, fmt("{\\" .. command .. " <>}", { d(1, M.get_visual, { user_args = { user_args } }) }, { delimiters = "<>" })) +end + +return M diff --git a/config/plugins/luasnip/luasnip.nix b/config/plugins/luasnip/luasnip.nix new file mode 100644 index 0000000..6b79ef2 --- /dev/null +++ b/config/plugins/luasnip/luasnip.nix @@ -0,0 +1,102 @@ +{ helpers, ... }: +let + inherit (helpers) mkRaw; +in +{ + plugins.luasnip = { + enable = true; + filetypeExtend = { + lua = [ + "c" + "cpp" + ]; + }; + settings = { + # https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#config-options + enable_autosnippets = true; + # https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#variables + cut_selection_keys = ""; + update_events = "TextChanged,TextChangedI"; + }; + # https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#lua + fromLua = [ + { paths = ./snippets; } # snippts attached to nixvim repo + { paths = "~/snippets"; } # snippts in home dir + ]; + }; + extraFiles = { + "lua/luasnip-helper-funcs.lua".source = ./helpers/luasnip-helper-funcs.lua; + }; + # https://github.com/L3MON4D3/LuaSnip/wiki/Nice-Configs#hint-node-type-with-virtual-text + extraConfigLua = '' + local types = require("luasnip.util.types") + require'luasnip'.config.setup({ + ext_opts = { + [types.choiceNode] = { + active = { + -- virt_text = {{"●", "GruvboxOrange"}} + -- see ":h group-name" (syntax highlighting) + virt_text = {{ '««« Choice Node', 'Constant', }} + } + }, + [types.insertNode] = { + active = { + -- virt_text = {{"●", "GruvboxBlue"}} + -- see ":h group-name" (syntax highlighting) + virt_text = {{ '««« Insert Node', 'Comment', }} + } + } + }, + }) + ''; + keymaps = [ + { + mode = [ + "i" + "s" + ]; + key = ""; + action = mkRaw '' + function() + local ls = require('luasnip') + if ls.expand_or_jumpable() then + ls.expand_or_jump() + end + end + ''; + options.silent = true; + } + { + mode = [ + "i" + "s" + ]; + key = ""; + action = mkRaw '' + function() + local ls = require('luasnip') + if ls.jumpable(-1) then + ls.jump(-1) + end + end + ''; + options.silent = true; + } + { + mode = [ + "i" + "s" + ]; + key = ""; + action = mkRaw '' + function() + local ls = require('luasnip') + if ls.choice_active() then + ls.change_choice(1) + end + end + ''; + options.silent = true; + } + ]; +} diff --git a/config/plugins/luasnip/snippets/nix/attrs.lua b/config/plugins/luasnip/snippets/nix/attrs.lua new file mode 100644 index 0000000..a1e1a98 --- /dev/null +++ b/config/plugins/luasnip/snippets/nix/attrs.lua @@ -0,0 +1,62 @@ +-- stop lsp error messages +-- https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#loaders +local ls = require("luasnip") +local s = ls.snippet +local sn = ls.snippet_node +local isn = ls.indent_snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node +local r = ls.restore_node +local events = require("luasnip.util.events") +local ai = require("luasnip.nodes.absolute_indexer") +local extras = require("luasnip.extras") +local l = extras.lambda +local rep = extras.rep +local p = extras.partial +local m = extras.match +local n = extras.nonempty +local dl = extras.dynamic_lambda +local fmt = require("luasnip.extras.fmt").fmt +local fmta = require("luasnip.extras.fmt").fmta +local conds = require("luasnip.extras.expand_conditions") +local postfix = require("luasnip.extras.postfix").postfix +local types = require("luasnip.util.types") +local parse = require("luasnip.util.parser").parse_snippet +local ms = ls.multi_snippet +local k = require("luasnip.nodes.key_indexer").new_key + +-- tutorials: +-- https://ejmastnak.com/tutorials/vim-latex/luasnip/#anatomy +-- https://evesdropper.dev/files/luasnip/ +return + +-- https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#lua +-- the files may return two lists of snippets, the snippets in the first are +-- all added as regular snippets, while the snippets in the second will be +-- added as autosnippets (both are the defaults, if a snippet defines a +-- different snippetType, that will have preference) + +-- First list of snippets (snippetType = "snippet") start +{ + s( + {trig = "attrs", dscr = "nix new attrs"}, + fmta( + [[ + <> = { + <> = <> + }; + ]] + , { i(1),i(2),i(3) }) + ), +}, +-- First list of snippets (snippetType = "snippet") end + +-- Second list of snippets (snippetType = "autosnippet") start +{ +} +-- Second list of snippets (snippetType = "autosnippet") end + + diff --git a/config/plugins/luasnip/snippets/tex/EndlessList.lua b/config/plugins/luasnip/snippets/tex/EndlessList.lua new file mode 100644 index 0000000..ab29ad2 --- /dev/null +++ b/config/plugins/luasnip/snippets/tex/EndlessList.lua @@ -0,0 +1,20 @@ +-- https://github.com/L3MON4D3/LuaSnip/wiki/Cool-Snippets#endless-list +local rec_ls +rec_ls = function() + return sn(nil, { + c(1, { + -- important!! Having the sn(...) as the first choice will cause infinite recursion. + t({""}), + -- The same dynamicNode as in the snippet (also note: self reference). + sn(nil, {t({"", "\t\\item "}), i(1), d(2, rec_ls, {})}), + }), + }); +end + +return { +s(";endlessitem", { + t({"\\begin{itemize}", + "\t\\item "}), i(1), d(2, rec_ls, {}), + t({"", "\\end{itemize}"}), i(0) +}) +} diff --git a/config/plugins/luasnip/snippets/tex/Tabular.lua b/config/plugins/luasnip/snippets/tex/Tabular.lua new file mode 100644 index 0000000..398fddf --- /dev/null +++ b/config/plugins/luasnip/snippets/tex/Tabular.lua @@ -0,0 +1,40 @@ +-- https://github.com/L3MON4D3/LuaSnip/wiki/Cool-Snippets#tabular + +table_node= function(args) + local tabs = {} + local count + table = args[1][1]:gsub("%s",""):gsub("|","") + count = table:len() + for j=1, count do + local iNode + iNode = i(j) + tabs[2*j-1] = iNode + if j~=count then + tabs[2*j] = t" & " + end + end + return sn(nil, tabs) +end + +rec_table = function () + return sn(nil, { + c(1, { + t({""}), + sn(nil, {t{"\\\\",""} ,d(1,table_node, {ai[1]}), d(2, rec_table, {ai[1]})}) + }), + }); +end + + +return { + + s(";table", { + t"\\begin{tabular}{", + i(1,"0"), + t{"}",""}, + d(2, table_node, {1}, {}), + d(3, rec_table, {1}), + t{"","\\end{tabular}"} + }), + +} diff --git a/config/plugins/luasnip/snippets/tex/dcenvelope.lua b/config/plugins/luasnip/snippets/tex/dcenvelope.lua new file mode 100644 index 0000000..cad3056 --- /dev/null +++ b/config/plugins/luasnip/snippets/tex/dcenvelope.lua @@ -0,0 +1,102 @@ +local line_begin = require("luasnip.extras.expand_conditions").line_begin + +return { + s( + { trig = ";dcenvelope", dscr = "A LaTeX equation environment" }, + fmta( + [[ + % https://en.wikibooks.org/wiki/LaTeX/Letters#Envelopes + + % https://tex.stackexchange.com/questions/268693/how-do-you-print-c4-envelopes + \documentclass{letter} + \usepackage{geometry} + \geometry{paperheight=9.25in,paperwidth=4.13in} + \usepackage{graphics} + \usepackage{envlab} + \usepackage[AutoFallBack=true]{xeCJK} + \setCJKmainfont<> + + % from envlab + \SetEnvelope{9.25in}{4.13in} + % from envlab + \setlength{\ToAddressTopMargin}{0in} %Arbitrarily decided by me + % from envlab + \setlength{\ToAddressLeftMargin}{1in} %Arbitrarily decided by me + + % from envlab + \makelabels + + \begin{document} + \startlabels + % from envlab + \mlabel + {% This "%" is required to make alignment right + % + % Sender Address + % + % append \\ at the end of the line before inserting newline + % + % e.g. Title\\ + % Address line1\\ + % Address line2\\ + % Address line3 + <> + } + {% This "%" is required to make alignment right + % + % Reciever Address + % + % append \\ at the end of the line before inserting newline + % + % e.g. Title\\ + % Address line1\\ + % Address line2\\ + % Address line3 + <> + % if print with lpr use command "lpr -o media=EnvYou4" + } + \end{document} + + ]], + { + c(1, { + t({ + "{Source Han Serif TC}", + "\\newCJKfontfamily\\secondaryfont{Source Han Sans TC}", + "\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}", + }), + t({ + "{Source Han Sans TC}", + "\\newCJKfontfamily\\secondaryfont{Source Han Serif TC}", + "\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}", + }), + t({ + "[Path=\\string~/.local/share/fonts/", + ",UprightFeatures = {FontIndex=13}", + ",BoldFeatures = {FontIndex=28}", + "]{SourceHanSerif.ttc}", + "\\newCJKfontfamily[Path=\\string~/.local/share/fonts/", + " ,UprightFeatures = {FontIndex=28}", + " ,BoldFeatures = {FontIndex=38}", + "]\\secondaryfont{Source Han Sans TC}", + "\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}", + }), + t({ + "[Path=\\string~/.local/share/fonts/", + ",UprightFeatures = {FontIndex=28}", + ",BoldFeatures = {FontIndex=38}", + "]{SourceHanSans.ttc}", + "\\newCJKfontfamily[Path=\\string~/.local/share/fonts/", + ",UprightFeatures = {FontIndex=13}", + ",BoldFeatures = {FontIndex=28}", + "]\\secondaryfont{Source Han Serif TC}", + "\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}", + }), + }), + i(3, "% Sender Address"), + i(2, "% Reciever Address"), + } + ), + { condition = line_begin } -- set condition in the `opts` table + ), +} diff --git a/config/plugins/luasnip/snippets/tex/dcinit.lua b/config/plugins/luasnip/snippets/tex/dcinit.lua new file mode 100644 index 0000000..c851f26 --- /dev/null +++ b/config/plugins/luasnip/snippets/tex/dcinit.lua @@ -0,0 +1,74 @@ +local helpers = require("luasnip-helper-funcs") +local get_visual = helpers.get_visual + +return { + s( + { trig = ";dcinit", snippetType = "snippet" }, + fmta( + [[ + \documentclass[<>]{<>} + \usepackage[<>]{geometry} + \usepackage[AutoFallBack=true]{xeCJK} + \setCJKmainfont<> + \begin{document} + <><> + \end{document} + ]], + { + c(1, { + t(""), + t("a4paper"), + t("letter"), + t("20pt"), + }), + c(2, { + t("article"), + t("extarticle"), + t("report"), + t("moderncv"), + }), + c(3, { + t(""), + t("margin=3cm"), + t("top=3cm,bottom=3cm,left=3cm,right=3cm"), + }), + c(4, { + t({ + "{Source Han Serif TC}", + "\\newCJKfontfamily\\secondaryfont{Source Han Sans TC}", + "\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}", + }), + t({ + "{Source Han Sans TC}", + "\\newCJKfontfamily\\secondaryfont{Source Han Serif TC}", + "\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}", + }), + t({ + "[Path=\\string~/.local/share/fonts/", + ",UprightFeatures = {FontIndex=13}", + ",BoldFeatures = {FontIndex=28}", + "]{SourceHanSerif.ttc}", + "\\newCJKfontfamily[Path=\\string~/.local/share/fonts/", + " ,UprightFeatures = {FontIndex=28}", + " ,BoldFeatures = {FontIndex=38}", + "]\\secondaryfont{Source Han Sans TC}", + "\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}", + }), + t({ + "[Path=\\string~/.local/share/fonts/", + ",UprightFeatures = {FontIndex=28}", + ",BoldFeatures = {FontIndex=38}", + "]{SourceHanSans.ttc}", + "\\newCJKfontfamily[Path=\\string~/.local/share/fonts/", + ",UprightFeatures = {FontIndex=13}", + ",BoldFeatures = {FontIndex=28}", + "]\\secondaryfont{Source Han Serif TC}", + "\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}", + }), + }), + d(5, get_visual, {}, { user_args = { "Content here" } }), + i(0), + } + ) + ), +} diff --git a/config/plugins/luasnip/snippets/tex/dcwatermark.lua b/config/plugins/luasnip/snippets/tex/dcwatermark.lua new file mode 100644 index 0000000..8f10c12 --- /dev/null +++ b/config/plugins/luasnip/snippets/tex/dcwatermark.lua @@ -0,0 +1,30 @@ +local line_begin = require("luasnip.extras.expand_conditions").line_begin + +return { + s( + { trig = ";dcwatermark", dscr = "Top-right corner watermark" }, + fmta( + [[ + \documentclass[a4paper]{article} + \usepackage[top=.2in,right=.2in]{geometry} + \usepackage{xcolor} + \renewcommand{\familydefault}{\sfdefault} + \begin{document} + % switch off page number + % https://tex.stackexchange.com/questions/7355/how-to-suppress-page-number + \pagenumbering{gobble} + + % https://superuser.com/questions/280659/how-can-i-apply-a-watermark-on-every-page-of-a-pdf-file + % pdftk original.pdf stamp watermark.pdf output final.pdf + + \hfill {\Large \textcolor{red}{``<>''}} + \end{document} + + ]], + { + i(1, "Insert watermark"), + } + ), + { condition = line_begin } -- set condition in the `opts` table + ), +} diff --git a/config/plugins/luasnip/snippets/tex/general.lua b/config/plugins/luasnip/snippets/tex/general.lua new file mode 100644 index 0000000..09b37b7 --- /dev/null +++ b/config/plugins/luasnip/snippets/tex/general.lua @@ -0,0 +1,72 @@ +local line_begin = require("luasnip.extras.expand_conditions").line_begin +local helpers = require("luasnip-helper-funcs") +local get_visual = helpers.get_visual +local mkscbs = helpers.make_single_curly_bracket_snippets +local mkss = helpers.make_scope_snippets +-- mkscbs ("snippetType", "trig", "command", "desc") + +return +-- https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#lua +-- First list of snippets (snippetType = "snippet") start +{ + mkscbs("snippet", ";tt", "texttt", "teletypefont"), + mkscbs("snippet", ";ti", "textit", "italic shape"), + mkscbs("snippet", ";bf", "textbf", "bold"), + mkscbs("snippet", ";em", "emph", "emphasis"), + mkscbs("snippet", ";em", "emph", "emphasis"), + mkscbs("snippet", ";sf", "sfont", "secondary font"), + s( + { trig = ";url", dscr = "The hyperref package's href{}{} command (for url links)" }, + fmta("\\href{<>}{<>}", { + d(1, get_visual, { 1 }, { user_args = { "url" } }), + i(2, "display name"), + }) + ), + s( + -- https://en.wikibooks.org/wiki/LaTeX/Paragraph_Formatting#Verbatim_text + { trig = ";vb", dscr = "Expands 'vb' into '\\verb++' (verbatim phrase, + as delimiters (can be changed))" }, + fmta("\\verb<><><>", { i(1, "+"), d(2, get_visual, {}, { user_args = { "verbatim phrase" } }), rep(1) }) + ), + s( + { trig = ";begin", dscr = "A LaTeX equation environment" }, + fmta( + [[ + \begin{<>} + <><> + \end{<>} + ]], + -- The insert node is placed in the <> angle brackets + { i(1), d(2, get_visual, {}, { user_args = { "Content here" } }), i(0), rep(1) } + ), + { condition = line_begin } -- set condition in the `opts` table + ), + s( + { trig = ";ff", dscr = "Expands 'ff' into '\\frac{}{}'" }, + fmt("\\fanc{<>}{<>}", { i(1), i(2) }, { delimiters = "<>" }) + ), + -- Example use of insert node placeholder text + s({ trig = ";s", desc = "square bracket" }, fmta("\\<>[<>]", { i(1, "command"), d(2, get_visual) })), + s({ trig = ";c", desc = "curly bracket" }, fmta("\\<>{<>}", { i(1, "command"), d(2, get_visual) })), + s({ trig = ";cc", desc = "curly bracket + curly bracket" }, fmta("\\<>{<>}{<>}", { i(1, "command"), i(3), i(2) })), + s({ trig = ";sc", desc = "square bracket + curly bracket" }, fmta("\\<>[<>]{<>}", { i(1, "command"), i(3), i(2) })), + -- s( + -- { trig = ";tt", dscr = "Expands 'tt' into '\\texttt{}' (teletypefont family)" }, + -- fmta("\\texttt{<>}", { d(1, get_visual, {}, { user_args = { "teletypefont" } }) }) + -- ), + -- s( + -- { trig = ";ti", dscr = "Expands 'ti' into '\\textit{}' (italic shape)" }, + -- fmta("\\textit{<>}", { d(1, get_visual, {}, { user_args = { "italic shape" } }) }) + -- ), + -- s( + -- { trig = ";bf", dscr = "Expands 'bf' into '\\textbf{}' (bold)" }, + -- fmta("\\textbf{<>}", { d(1, get_visual, {}, { user_args = { "bold" } }) }) + -- ), + -- s( + -- { trig = ";em", dscr = "Expands 'em' into '\\emph{}' (emphasis)" }, + -- fmta("\\emph{<>}", { d(1, get_visual, {}, { user_args = { "emphasis" } }) }) + -- ), +}, +-- First list of snippets (snippetType = "snippet") end +-- Second list of snippets (snippetType = "autosnippet") start +{} +-- Second list of snippets (snippetType = "autosnippet") end diff --git a/config/plugins/luasnip/snippets/tex/preamble.lua b/config/plugins/luasnip/snippets/tex/preamble.lua new file mode 100644 index 0000000..4dc4bae --- /dev/null +++ b/config/plugins/luasnip/snippets/tex/preamble.lua @@ -0,0 +1,75 @@ +return { + s( + ";updarkmode", + t({ + "\\usepackage{xcolor}", + "\\pagecolor[rgb]{0.1,0.1,0.1}", + "\\color[rgb]{1,1,1}", + }) + ), + s(";upurlpackage", t("\\usepackage{hyperref}")), + + -- % https://old.reddit.com/r/LaTeX/comments/m8frij/aligning_text_across_lines/ + -- % allign dates in working experience + -- for \brlap or \stackunder or \bllap + s(";upstack", t("\\usepackage{stackengine}")), + -- % for \CurrentLineWidth + s(";uptabto", t("\\usepackage{tabto}")), + + -- % https://tex.stackexchange.com/questions/5036/how-to-prevent-latex-from-hyphenating-the-entire-document + -- % disable hyphenation at the edge + s(";upnohyphen", t("\\usepackage[none]{hyphenat}")), + + s(";upinpututf8", t("\\usepackage[utf8]{inputenc}")), + + s(";up", fmta("\\usepackage[<>]{<>}", { i(2), i(1) })), + + -- Help using xeCJK + -- https://tex.stackexchange.com/questions/510853/using-one-xecjk-font-family-on-english-and-chinese-at-the-same-time + -- https://tex.stackexchange.com/questions/264265/defining-subfamilies-for-a-font/264275#264275 + s( + ";upxecjk", + fmta( + [[ + \usepackage[AutoFallBack=true]{xeCJK} + \setCJKmainfont<> + ]], + { + c(1, { + t({ + "{Source Han Serif TC}", + "\\newCJKfontfamily\\secondaryfont{Source Han Sans TC}", + "\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}", + }), + t({ + "{Source Han Sans TC}", + "\\newCJKfontfamily\\secondaryfont{Source Han Serif TC}", + "\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}", + }), + t({ + "[Path=\\string~/.local/share/fonts/", + ",UprightFeatures = {FontIndex=13}", + ",BoldFeatures = {FontIndex=28}", + "]{SourceHanSerif.ttc}", + "\\newCJKfontfamily[Path=\\string~/.local/share/fonts/", + " ,UprightFeatures = {FontIndex=28}", + " ,BoldFeatures = {FontIndex=38}", + "]\\secondaryfont{Source Han Sans TC}", + "\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}", + }), + t({ + "[Path=\\string~/.local/share/fonts/", + ",UprightFeatures = {FontIndex=28}", + ",BoldFeatures = {FontIndex=38}", + "]{SourceHanSans.ttc}", + "\\newCJKfontfamily[Path=\\string~/.local/share/fonts/", + ",UprightFeatures = {FontIndex=13}", + ",BoldFeatures = {FontIndex=28}", + "]\\secondaryfont{Source Han Serif TC}", + "\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}", + }), + }), + } + ) + ), +} diff --git a/config/plugins/mini.nix b/config/plugins/mini.nix new file mode 100644 index 0000000..e77685f --- /dev/null +++ b/config/plugins/mini.nix @@ -0,0 +1,75 @@ +{ helpers, ... }: +let + inherit (helpers) mkRaw; +in +{ + # evaluation warning: Nixvim: `plugins.web-devicons` was enabled automatically because the following plugins are enabled. + # This behaviour is deprecated. Please explicitly define `plugins.web-devicons.enable` or alternatively + # enable `plugins.mini.enable` with `plugins.mini.modules.icons` and `plugins.mini.mockDevIcons`. + # plugins.telescope + # plugins.nvim-tree + # plugins.bufferline + plugins = { + mini = { + enable = true; + # https://nix-community.github.io/nixvim/plugins/mini/index.html + modules.icons = { + ai = { + n_lines = 50; + search_method = "cover_or_next"; + }; + comment = { + mappings = { + comment = "/"; + comment_line = "/"; + comment_visual = "/"; + textobject = "/"; + }; + }; + diff = { + view = { + style = "sign"; + }; + }; + starter = { + content_hooks = { + "__unkeyed-1.adding_bullet" = mkRaw "require('mini.starter').gen_hook.adding_bullet()"; + "__unkeyed-2.indexing" = + mkRaw "require('mini.starter').gen_hook.indexing('all', { 'Builtin actions' })"; + "__unkeyed-3.padding" = mkRaw "require('mini.starter').gen_hook.aligning('center', 'center')"; + }; + evaluate_single = true; + header = '' + ███╗ ██╗██╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ + ████╗ ██║██║╚██╗██╔╝██║ ██║██║████╗ ████║ + ██╔██╗ ██║██║ ╚███╔╝ ██║ ██║██║██╔████╔██║ + ██║╚██╗██║██║ ██╔██╗ ╚██╗ ██╔╝██║██║╚██╔╝██║ + ██║ ╚████║██║██╔╝ ██╗ ╚████╔╝ ██║██║ ╚═╝ ██║ + ''; + items = { + "__unkeyed-1.buildtin_actions" = mkRaw "require('mini.starter').sections.builtin_actions()"; + "__unkeyed-2.recent_files_current_directory" = + mkRaw "require('mini.starter').sections.recent_files(10, false)"; + "__unkeyed-3.recent_files" = mkRaw "require('mini.starter').sections.recent_files(10, true)"; + "__unkeyed-4.sessions" = mkRaw "require('mini.starter').sections.sessions(5, true)"; + }; + }; + surround = { + mappings = { + add = "gsa"; + delete = "gsd"; + find = "gsf"; + find_left = "gsF"; + highlight = "gsh"; + replace = "gsr"; + update_n_lines = "gsn"; + }; + }; + }; + # https://nix-community.github.io/nixvim/plugins/mini/index.html + # Whether to tell mini.icons to emulate nvim-web-devicons for plugins that don’t natively support it. + # When enabled, you don’t need to set plugins.web-devicons.enable. This will replace the need for it. + mockDevIcons = true; + }; + }; +} diff --git a/config/plugins/neorg.nix b/config/plugins/neorg.nix new file mode 100644 index 0000000..6e3854b --- /dev/null +++ b/config/plugins/neorg.nix @@ -0,0 +1,151 @@ +{ + pkgs, + pkgs-stable, + helpers, + ... +}: +let + inherit (helpers) mkRaw; +in +{ + # https://github.com/nvim-neorg/neorg + # NOW neorg require lua-utils.nvim, nvim-nio, pathlib.vim + # https://github.com/nix-community/nixvim/issues/1395#issuecomment-2267262919 + # Workaround + # extraPlugins = [ + # (pkgs.vimUtils.buildVimPlugin {inherit (pkgs.luaPackages.lua-utils-nvim) pname version src;}) + # + # (pkgs.vimUtils.buildVimPlugin {inherit (pkgs.luaPackages.pathlib-nvim) pname version src;}) + # + # (pkgs.vimUtils.buildVimPlugin {inherit (pkgs.luaPackages.nvim-nio) pname version src;}) + # ]; + + plugins = { + # https://haseebmajid.dev/posts/2024-04-21-til-how-to-fix-neorg-metadata-treesitter-issues-with-nixvim/ + # no need to use neorg-overlay inputs when also add these treesitter + treesitter = { + grammarPackages = with pkgs.tree-sitter-grammars; [ + tree-sitter-norg + tree-sitter-norg-meta + ]; + }; + neorg = { + enable = true; + # package = pkgs-stable.vimPlugins.neorg; + # package = pkgs.vimPlugins.neorg; + # lazyLoading = true; + settings.load = { + "core.defaults" = helpers.emptyTable; # -- Loads default behaviour + "core.summary" = helpers.emptyTable; + "core.export" = helpers.emptyTable; + "core.export.markdown" = helpers.emptyTable; + "core.concealer" = { + config = { + folds = true; + }; + }; # -- Adds pretty icons to your documents + "core.dirman" = { + config = { + workspaces = { + n = "~/neorg/notes"; + e = "~/neorg/english"; + l = "~/neorg/letter"; + g = "~/neorg/grammar"; + p = "~/neorg/perl"; + m = "~/neorg/misc"; + c = "~/neorg/nc"; + # nvim = "~/.config/nvim/NeorgNvimNotes"; + }; + default_workspace = "c"; + }; + }; + "core.keybinds" = { + config = { + default_keybinds = true; + # # Raw lua + # # https://github.com/nix-community/nixvim#raw-lua + # hook = mkRaw '' + # function(keybinds) + # keybinds.unmap("norg", "i", "") + # keybinds.remap_event("norg", "i", "", "core.itero.next-iteration", "") + # end + # ''; + }; + }; + # "core.latex.renderer" = helpers.emptyTable; + "core.qol.toc" = { + config = { + close_after_use = true; + }; + }; + }; + }; + }; + autoCmd = [ + { + pattern = [ "norg" ]; + event = [ "FileType" ]; + callback = mkRaw '' + function() + vim.opt.formatoptions:remove('r') + vim.opt.formatoptions:remove('o') + -- use this insteand: ['core.concealer'] = { config = { folds = false }, }, + vim.opt.foldlevelstart = 99 + + -- https://github.com/nvim-neorg/neorg/discussions/1066 + vim.opt.conceallevel = 2 + vim.keymap.set( 'n', 'nT', function() + if vim.opt.conceallevel:get() == 2 then + vim.opt.conceallevel = 0 + elseif vim.opt.conceallevel:get() == 0 then + vim.opt.conceallevel = 2 + end + vim.cmd('Neorg toggle-concealer') + end, { desc = '[neorg] toggle-concealer and conceallevel' }) + + + vim.keymap.set( 'n', 'ng', function() vim.cmd.Neorg('generate-workspace-summary') end, { desc = '[neorg] generate-workspace-summary' }) + vim.keymap.set( 'n', 'nt', function() vim.cmd.Neorg('toc') end, { desc = '[neorg] Table of Content' }) + vim.keymap.set( 'n', 'nm', function() vim.cmd.Neorg('inject-metadata') end, { desc = '[neorg] Inject metadata' }) + vim.keymap.set( 'n', 'nj', function() vim.api.nvim_feedkeys(':Neorg journal ', 'n', true) end, { desc = '[neorg] Neorg journal ' }) + + vim.keymap.set( 'n', 'tn', "(neorg.qol.todo-items.todo.task-cycle)", { desc = "[neorg] Cycle Task" }) + + vim.keymap.set('i', "", "(neorg.itero.next-iteration)", {} ) + end + ''; + } + ]; + keymaps = [ + { + mode = [ "n" ]; + key = "nw"; + action = mkRaw ''function() vim.api.nvim_feedkeys(':Neorg workspace ', 'n', true) end ''; + options.desc = "[neorg] Neorg workspace "; + } + { + mode = [ "n" ]; + key = "nc"; + action = mkRaw ''function() vim.cmd('Neorg workspace c') end ''; + options.desc = "[neorg] Neorg workspace c"; + } + { + mode = [ "n" ]; + key = "ni"; + action = mkRaw ''function() vim.cmd('Neorg index') end ''; + options.desc = "[neorg] Neorg index"; + } + { + mode = [ "n" ]; + key = "nr"; + action = mkRaw ''function() vim.cmd('Neorg return') end ''; + options.desc = "[neorg] Neorg return"; + } + { + mode = [ "n" ]; + key = "ne"; + action = mkRaw ''function() vim.cmd('Neorg workspace e') end ''; + options.desc = "[neorg] Neorg workspace e (neorg-english)"; + } + ]; +} diff --git a/config/plugins/neoscroll.nix b/config/plugins/neoscroll.nix new file mode 100644 index 0000000..ed4da3d --- /dev/null +++ b/config/plugins/neoscroll.nix @@ -0,0 +1,30 @@ +{ helpers, ... }: +{ + plugins = { + neoscroll = { + enable = true; + settings = { + easing_function = "sine"; + }; + }; + }; + # https://github.com/karb94/neoscroll.nvim + extraConfigLua = '' + neoscroll = require('neoscroll') + local keymap = { + [""] = function() neoscroll.ctrl_u({ duration = 80 }) end; + [""] = function() neoscroll.ctrl_d({ duration = 80 }) end; + [""] = function() neoscroll.ctrl_b({ duration = 80 }) end; + [""] = function() neoscroll.ctrl_f({ duration = 80 }) end; + [""] = function() neoscroll.scroll(-0.1, { move_cursor=false; duration = 40 }) end; + [""] = function() neoscroll.scroll(0.1, { move_cursor=false; duration = 40 }) end; + ["zt"] = function() neoscroll.zt({ half_win_duration = 80 }) end; + ["zz"] = function() neoscroll.zz({ half_win_duration = 80 }) end; + ["zb"] = function() neoscroll.zb({ half_win_duration = 80 }) end; + } + local modes = { 'n', 'v', 'x' } + for key, func in pairs(keymap) do + vim.keymap.set(modes, key, func) + end + ''; +} diff --git a/config/plugins/noice.nix b/config/plugins/noice.nix new file mode 100644 index 0000000..da3daa3 --- /dev/null +++ b/config/plugins/noice.nix @@ -0,0 +1,61 @@ +{ + plugins = { + noice = { + enable = true; + + # This does not work when "luaConfig.pre" is used + # + # settings = { + # # https://github.com/folke/noice.nvim/wiki/Configuration-Recipes#classic-cmdline + # # Classic Cmdline + # cmdline.view = "cmdline"; + # presets = { + # bottom_search = true; + # command_palette = true; + # }; + # # auto fallback to mini when nvim-notify not use + # # this force use min in :messages + # # messages.view = "mini"; + # }; + + # https://github.com/folke/noice.nvim/blob/main/lua/noice/config/views.lua + # set mini (:messages) timeout to 5000 + # https://github.com/folke/noice.nvim/issues/226#issuecomment-1324011122 + # set mini win_options.winblend = 0 (for transparency) + luaConfig.pre = '' + require("noice").setup({ + -- https://github.com/folke/noice.nvim/wiki/Configuration-Recipes#classic-cmdline + -- Classic Cmdline + cmdline = { + view = "cmdline", + }, + messages = { + view = "mini", -- default fallback + }, + presets = { + bottom_search = true, + command_palette = true, + }, + views = { + mini = { + timeout = 10000, + win_options = { + winblend = 0 + }, + }, + }, + }) + ''; + }; + }; + keymaps = [ + { + mode = "n"; + key = "cm"; + action = "NoiceDismiss"; + options = { + desc = "Dismiss noice messages"; + }; + } + ]; +} diff --git a/config/plugins/notify.nix b/config/plugins/notify.nix new file mode 100644 index 0000000..9560305 --- /dev/null +++ b/config/plugins/notify.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + ... +}: +{ + plugins = { + # notify.nvim + notify = { + enable = lib.mkIf config.plugins.noice.enable true; + settings = { + # https://github.com/rcarriga/nvim-notify/issues/183#issuecomment-1464892813 + on_open = '' + function(win) + vim.api.nvim_win_set_config(win, { focusable = false }) + end + ''; + background_colour = "#000000"; + top_down = false; + render = "minimal"; + }; + }; + }; +} diff --git a/config/plugins/nvim-jqx.nix b/config/plugins/nvim-jqx.nix new file mode 100644 index 0000000..9f9b173 --- /dev/null +++ b/config/plugins/nvim-jqx.nix @@ -0,0 +1,4 @@ +{ pkgs, ... }: +{ + extraPlugins = with pkgs.vimPlugins; [ nvim-jqx ]; +} diff --git a/config/plugins/nvim-tree.nix b/config/plugins/nvim-tree.nix new file mode 100644 index 0000000..24e0084 --- /dev/null +++ b/config/plugins/nvim-tree.nix @@ -0,0 +1,9 @@ +{ + plugins = { + # https://github.com/nvim-tree/nvim-tree.lua + # A File Explorer For Neovim Written In Lua + nvim-tree = { + enable = true; + }; + }; +} diff --git a/config/plugins/oil.nix b/config/plugins/oil.nix new file mode 100644 index 0000000..7007da5 --- /dev/null +++ b/config/plugins/oil.nix @@ -0,0 +1,22 @@ +{ + plugins = { + oil = { + enable = true; + settings = { + view_options = { + show_hidden = true; + }; + }; + }; + }; + keymaps = [ + { + mode = "n"; + key = "--"; + action = "Oil"; + options = { + desc = "Open parent directory"; + }; + } + ]; +} diff --git a/config/plugins/sleuth.nix b/config/plugins/sleuth.nix new file mode 100644 index 0000000..0404dc8 --- /dev/null +++ b/config/plugins/sleuth.nix @@ -0,0 +1,7 @@ +{ + plugins = { + sleuth = { + enable = true; + }; + }; +} diff --git a/config/plugins/telescope.nix b/config/plugins/telescope.nix new file mode 100644 index 0000000..603a167 --- /dev/null +++ b/config/plugins/telescope.nix @@ -0,0 +1,226 @@ +{ helpers, ... }: +let + inherit (helpers) mkRaw; +in +{ + plugins.telescope = { + enable = true; + + extensions = { + fzf-native = { + enable = true; + }; + ui-select = { + settings = { + specific_opts = { + codeactions = true; + }; + }; + }; + undo = { + enable = true; + }; + }; + # If you'd prefer Telescope not to enter a normal-like mode when hitting escape (and instead exiting), you can map to do so via: + settings = { + defaults = { + sorting_strategy = "ascending"; + mappings = { + i = { + "" = mkRaw '' + function(...) + return require("telescope.actions").close(...) + end''; + }; + }; + }; + }; + keymaps = { + "" = { + action = "find_files"; + options.desc = "[F]ind [F]iles"; + }; + "fg" = { + action = "live_grep"; + options.desc = "[F]ind files by [G]rep"; + }; + "cm" = { + action = "command_history"; + options.desc = "[C]ommand [H]istory"; + }; + "s." = { + action = "oldfiles"; + options.desc = "[S]earch Recent Files (\".\" for repeat)"; + }; + "fb" = { + action = "buffers"; + options.desc = "[F]ind [B]uffers"; + }; + "gf" = { + action = "git_files"; + options.desc = "Search [G]it [F]iles"; + }; + "gc" = { + action = "git_commits"; + options.desc = "[G]it [C]ommits"; + }; + "gs" = { + action = "git_status"; + options.desc = "[G]it [S]tatus"; + }; + "sa" = { + action = "autocommands"; + options.desc = "[S]earch [A]uto Commands"; + }; + "sb" = { + action = "current_buffer_fuzzy_find"; + options.desc = "[S]earch current [B]uffer (fuzzy find)"; + }; + "sB" = { + action = "bulitin"; + options.desc = "[S]earch [B]uiltins"; + }; + "sc" = { + action = "command_history"; + options.desc = "[C]ommand [H]istory"; + }; + "sC" = { + action = "commands"; + options.desc = "[S]earch [C]ommands"; + }; + "sD" = { + action = "diagnostics"; + options.desc = "[S]earch [D]iagnostics"; + }; + "sh" = { + action = "help_tags"; + options.desc = "[S]earch [H]elp pages"; + }; + "sH" = { + action = "highlights"; + options.desc = "[S]earch [H]ighlight Groups"; + }; + "sk" = { + action = "keymaps"; + options.desc = "[S]earch [K]eymaps"; + }; + "sM" = { + action = "man_pages"; + options.desc = "[S]eanch [M]an pages"; + }; + "sm" = { + action = "marks"; + options.desc = "[S]eanch (jump) to [M]ark"; + }; + "so" = { + action = "vim_options"; + options.desc = "[S]earch vim [O]ptions"; + }; + "sR" = { + action = "resume"; + options.desc = "[S]earch [R]esume"; + }; + "C" = { + action = "colorscheme"; + options.desc = "[C]olorscheme preview"; + }; + }; + }; + keymaps = [ + { + mode = [ "n" ]; + key = "ffn"; + action = mkRaw '' + function () require("telescope.builtin").find_files + { cwd = "~/forgejo/nixos-configs/" } + end + ''; + options.desc = "Find files in nixos-configs"; + } + { + mode = [ "n" ]; + key = "ffm"; + action = mkRaw '' + function () require("telescope.builtin").find_files + { cwd = "~/forgejo/my_nixvim/" } + end + ''; + options.desc = "Find files in my_nixvim"; + } + ]; + + # use -j1 for ripgrep + # https://github.com/nvim-telescope/telescope.nvim/issues/647#issuecomment-1536456802 + # keymaps = [ + # { + # mode = [ "n" ]; + # key = ""; + # action = mkRaw ''function () require("telescope.builtin").find_files({ additional_args = { "-j1" }}) end''; + # options.desc = "Find project files"; + # } + # { + # mode = [ "n" ]; + # key = "fg"; + # action = mkRaw ''function () require("telescope.builtin").live_grep({ additional_args = { "-j1" }}) end''; + # options.desc = "Grep (root dir)"; + # } + # { + # mode = [ "n" ]; + # key = "ff"; + # action = mkRaw ''function () require("telescope.builtin").find_files({ additional_args = { "-j1" }}) end''; + # options.desc = "Find project files"; + # } + # ]; + extraConfigLua = '' + local telescope = require('telescope') + telescope.setup{ + pickers = { + colorscheme = { + enable_preview = true + }, + -- To prevent crash on slow machines + -- Replace (ripgrep --files) with gnu find for "find_files" + find_files = { + -- enable hidden file/folder search, but exclude hidden folder in find_command + hidden = true, + find_command = { + "find", + ".", + "(", + "-path", + "*/.*", + "-type", + "d", + ")", + "-prune", + "-o", + "-type", + "f", + "-printf", + "%P\n" + }, + }, + }, + -- To prevent crash on slow machines + -- Replace ripgrep with gnu grep for "live_grep" and "grep_string" + -- https://github.com/nvim-telescope/telescope.nvim/issues/2083#issuecomment-1215476157 + defaults = { + vimgrep_arguments = { + "grep", + "--extended-regexp", + "--color=never", + "--with-filename", + "--line-number", + "-b", -- grep doesn't support a `--column` option :( + "--ignore-case", + "--recursive", + "--no-messages", + "--exclude-dir=*cache*", + "--exclude-dir=*.git", + "--exclude=.*", + "--binary-files=without-match", -- skip binary files + } + } + } + ''; +} diff --git a/config/plugins/treesitter.nix b/config/plugins/treesitter.nix new file mode 100644 index 0000000..3cb1e0c --- /dev/null +++ b/config/plugins/treesitter.nix @@ -0,0 +1,16 @@ +{ + config, + lib, + ... +}: +{ + plugins = { + treesitter = { + enable = true; + nixvimInjections = true; + # For neorg formatting (italic/bold/etc) to work properly + # https://github.com/nvim-neorg/neorg/wiki/Dependencies#nvim-treesitter-plugin + settings.highlight.enable = lib.mkIf config.plugins.neorg.enable true; + }; + }; +} diff --git a/config/plugins/undotree.nix b/config/plugins/undotree.nix new file mode 100644 index 0000000..d15a834 --- /dev/null +++ b/config/plugins/undotree.nix @@ -0,0 +1,40 @@ +{ helpers, ... }: +let + inherit (helpers) mkRaw; +in +{ + plugins = { + undotree = { + enable = true; + settings = { + CursorLine = true; + DiffAutoOpen = true; + DiffCommand = "diff"; + DiffpanelHeight = 10; + HelpLine = true; + HighlightChangedText = true; + HighlightChangedWithSign = true; + HighlightSyntaxAdd = "DiffAdd"; + HighlightSyntaxChange = "DiffChange"; + HighlightSyntaxDel = "DiffDelete"; + RelativeTimestamp = true; + SetFocusWhenToggle = true; + ShortIndicators = false; + SplitWidth = 40; + TreeNodeShape = "*"; + TreeReturnShape = "\\"; + TreeSplitShape = "/"; + TreeVertShape = "|"; + WindowLayout = 4; + }; + }; + }; + keymaps = [ + { + mode = "n"; + key = "u"; + action = mkRaw "vim.cmd.UndotreeToggle"; + options.desc = "UndoTreeToggle"; + } + ]; +} diff --git a/config/plugins/which-key.nix b/config/plugins/which-key.nix new file mode 100644 index 0000000..80d0adb --- /dev/null +++ b/config/plugins/which-key.nix @@ -0,0 +1,7 @@ +{ + plugins = { + which-key = { + enable = true; + }; + }; +} diff --git a/config/sets.nix b/config/sets.nix new file mode 100644 index 0000000..79e37dc --- /dev/null +++ b/config/sets.nix @@ -0,0 +1,83 @@ +{ + config = { + globals = { + mapleader = " "; + maplocalleader = " "; + + # set *.tex to tex filetype instead of plaintex + # :help tex_flavor + tex_flavor = "latex"; + }; + opts = { + relativenumber = true; + splitbelow = true; + redrawtime = 15000; + + # new split to the right + splitright = true; + + # show hidden characters + list = true; + + # don't break words on the edge + linebreak = true; + wrap = true; + # length of an actual \t character: + # https://stackoverflow.com/questions/191201/indenting-comments-to-match-code-in-vim + smartindent = false; + # length to use when shifting text (eg. <<, >> and == commands) + + tabstop = 2; + shiftwidth = 0; + + # set it to true for indenting with space after prssing o/O in normal mode + expandtab = true; + autoindent = true; + # Set highlight on search + hlsearch = false; + + # Make line numbers default + number = true; + + # Enable mouse mode + mouse = "a"; + + # Sync clipboard between OS and Neovim. + # Remove this option if you want your OS clipboard to remain independent. + # See `:help 'clipboard'` + # vim.o.clipboard = 'unnamedplus' -- REMOVED BY ME + + # Enable break indent + breakindent = true; + + # Save undo history + # vim.o.undofile = true -- REMOVED BY ME + + # Case insensitive searching UNLESS /C or capital in search + ignorecase = true; + smartcase = true; + + # Keep signcolumn on by default + signcolumn = "yes"; + + # Decrease update time + updatetime = 250; + timeout = true; + # timeoutlen = 1000; # time of valid keypress like for leader key in millisecond + timeoutlen = 300; # lower to 300 in favor of which-key plugins + + # Set completeopt to have a better completion experience + completeopt = "menuone,noselect"; + + # NOTE: You should make sure your terminal supports this + termguicolors = true; + + # Configures the cursor style for each mode. + # from :help guicursor + guicursor = "n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor,sm:block-blinkwait175-blinkoff150-blinkon175"; + + # Minimal number of screen lines to keep above and below the cursor. + scrolloff = 0; + }; + }; +} diff --git a/flake-modules/formatter.nix b/flake-modules/formatter.nix new file mode 100644 index 0000000..b74025c --- /dev/null +++ b/flake-modules/formatter.nix @@ -0,0 +1,10 @@ +{ + perSystem = + { + pkgs, + ... + }: + { + formatter = pkgs.nixfmt-tree; + }; +} diff --git a/flake-modules/nixvim.nix b/flake-modules/nixvim.nix new file mode 100644 index 0000000..5ebe58d --- /dev/null +++ b/flake-modules/nixvim.nix @@ -0,0 +1,96 @@ +{ inputs, ... }: +{ + imports = [ inputs.devshell.flakeModule ]; + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + let + nixvim' = inputs'.nixvim.legacyPackages; + lib = inputs.nixpkgs.lib; + # https://nix-community.github.io/nixvim/modules/standalone.html + nixvimModule = variant: { + inherit pkgs; + module = import ../config { + inherit lib; + inherit system; + inherit variant; + }; + # You can use `extraSpecialArgs` to pass additional arguments to your module files + extraSpecialArgs = { + inherit (inputs) self; + inherit variant; + inherit system; # used in nixd and csvview-nvim + inherit inputs; # used in csvview-nvim, before the package merged into nixos-24.11 + }; + }; + makeNixvimFunction = variant: nixvim'.makeNixvimWithModule (nixvimModule variant); + in + { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ + # remove this and use nixos-25.05 to accelerate evaluation time + # # https://haseebmajid.dev/posts/2024-04-21-til-how-to-fix-neorg-metadata-treesitter-issues-with-nixvim/ + # no need to use neorg-overlay after adding treesitter in ./config/plugins/neorg.nix + # + # inputs.neorg-overlay.overlays.default + (final: prev: { + nvim-full = makeNixvimFunction "full"; + nvim-lite = makeNixvimFunction "lite"; + nvim-normal = makeNixvimFunction "normal"; + }) + ]; + }; + + packages = { + # Lets you run `nix run .` to start nixvim + default = self'.packages.nvim-full; + + # nvim-full = pkgs.symlinkJoin { + # name = "nvim-full"; + # paths = [ + # (pkgs.writeShellScriptBin "nvim-full" '' + # exec ${pkgs.nvim-full}/bin/nvim "$@" + # '') + # (pkgs.writeShellScriptBin "nixvim-print-init-full" '' + # exec ${pkgs.nvim-full}/bin/nixvim-print-init "$@" + # '') + # ]; + # }; + # nvim-normal = pkgs.symlinkJoin { + # name = "nvim-normal"; + # paths = [ + # (pkgs.writeShellScriptBin "nvim-normal" '' + # exec ${pkgs.nvim-normal}/bin/nvim "$@" + # '') + # (pkgs.writeShellScriptBin "nixvim-print-init-normal" '' + # exec ${pkgs.nvim-normal}/bin/nixvim-print-init "$@" + # '') + # ]; + # }; + # nvim-lite = pkgs.symlinkJoin { + # name = "nvim-lite"; + # paths = [ + # (pkgs.writeShellScriptBin "nvim-lite" '' + # exec ${pkgs.nvim-lite}/bin/nvim "$@" + # '') + # (pkgs.writeShellScriptBin "nixvim-print-init-lite" '' + # exec ${pkgs.nvim-lite}/bin/nixvim-print-init "$@" + # '') + # ]; + # }; + nvim-full = pkgs.nvim-full; + nvim-normal = pkgs.nvim-normal; + nvim-lite = pkgs.nvim-lite; + }; + devshells.default = { + packages = [ self'.packages.nvim-full ]; + }; + }; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c01c719 --- /dev/null +++ b/flake.lock @@ -0,0 +1,242 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1741473158, + "narHash": "sha256-kWNaq6wQUbUMlPgw8Y+9/9wP0F8SHkjy24/mN3UAppg=", + "owner": "numtide", + "repo": "devshell", + "rev": "7c9e793ebe66bcba8292989a68c0419b737a22a0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1751413152, + "narHash": "sha256-Tyw1RjYEsp5scoigs1384gIg6e0GoBVjms4aXFfRssQ=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "77826244401ea9de6e3bac47c2db46005e1f30b5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "ixx": { + "inputs": { + "flake-utils": [ + "nixvim", + "nuschtosSearch", + "flake-utils" + ], + "nixpkgs": [ + "nixvim", + "nuschtosSearch", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1748294338, + "narHash": "sha256-FVO01jdmUNArzBS7NmaktLdGA5qA3lUMJ4B7a05Iynw=", + "owner": "NuschtOS", + "repo": "ixx", + "rev": "cc5f390f7caf265461d4aab37e98d2292ebbdb85", + "type": "github" + }, + "original": { + "owner": "NuschtOS", + "ref": "v0.0.8", + "repo": "ixx", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1752480373, + "narHash": "sha256-JHQbm+OcGp32wAsXTE/FLYGNpb+4GLi5oTvCxwSoBOA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "62e0f05ede1da0d54515d4ea8ce9c733f12d9f08", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1751159883, + "narHash": "sha256-urW/Ylk9FIfvXfliA1ywh75yszAbiTEVgpPeinFyVZo=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "14a40a1d7fb9afa4739275ac642ed7301a9ba1ab", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixvim": { + "inputs": { + "flake-parts": [ + "flake-parts" + ], + "nixpkgs": [ + "nixpkgs" + ], + "nuschtosSearch": "nuschtosSearch", + "systems": "systems_3" + }, + "locked": { + "lastModified": 1752546848, + "narHash": "sha256-WzHqmJ1wEZoUGAedomwcVLCuNsiB9bZzZXk7K9ZDBwk=", + "owner": "nix-community", + "repo": "nixvim", + "rev": "1fb1bf8a73ccf207dbe967cdb7f2f4e0122c8bd5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "main", + "repo": "nixvim", + "type": "github" + } + }, + "nuschtosSearch": { + "inputs": { + "flake-utils": "flake-utils_2", + "ixx": "ixx", + "nixpkgs": [ + "nixvim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1749730855, + "narHash": "sha256-L3x2nSlFkXkM6tQPLJP3oCBMIsRifhIDPMQQdHO5xWo=", + "owner": "NuschtOS", + "repo": "search", + "rev": "8dfe5879dd009ff4742b668d9c699bc4b9761742", + "type": "github" + }, + "original": { + "owner": "NuschtOS", + "repo": "search", + "type": "github" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-parts": "flake-parts", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "nixvim": "nixvim" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8c8ee57 --- /dev/null +++ b/flake.nix @@ -0,0 +1,58 @@ +{ + # https://github.com/redyf/Neve/blob/main/flake.nix + description = "nixvim-for-share"; + + inputs = { + # https://github.com/nix-community/nixvim/issues/1859 + # use nixos-24.05 branch to get rid of "error: attribute 'cmp-ai' missing" + # nixvim.url = "github:nix-community/nixvim/main"; + + nixvim = { + # url = "github:nix-community/nixvim/nixos-25.05"; + url = "github:nix-community/nixvim/main"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-parts.follows = "flake-parts"; + }; + flake-utils.url = "github:numtide/flake-utils"; + flake-parts.url = "github:hercules-ci/flake-parts"; + # nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; + # nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + # nixpkgs.follows = "nixvim/nixpkgs"; + + # https://github.com/nvim-neorg/nixpkgs-neorg-overlay + # https://github.com/nix-community/nixvim/issues/1395 + # remove this and use nixos-25.05 to accelerate evaluation time + # + # https://haseebmajid.dev/posts/2024-04-21-til-how-to-fix-neorg-metadata-treesitter-issues-with-nixvim/ + # no need to use neorg-overlay after adding treesitter in ./config/plugins/neorg.nix + # neorg-overlay = { + # url = "github:nvim-neorg/nixpkgs-neorg-overlay"; + # inputs.nixpkgs.follows = "nixpkgs"; + # inputs.flake-utils.follows = "flake-utils"; + # }; + devshell = { + url = "github:numtide/devshell"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + inputs@{ + self, + flake-parts, + ... + }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + imports = [ + ./flake-modules/formatter.nix + ./flake-modules/nixvim.nix + ]; + }; +}