diff --git a/dotfiles/nvim.zip b/dotfiles/nvim.zip deleted file mode 100644 index 4f208e2..0000000 Binary files a/dotfiles/nvim.zip and /dev/null differ diff --git a/dotfiles/nvim/init.lua b/dotfiles/nvim/init.lua index b00cd05..16f2ec4 120000 --- a/dotfiles/nvim/init.lua +++ b/dotfiles/nvim/init.lua @@ -1 +1 @@ -/nix/store/hhz4243ymgf24x646pxh30jm38iss4rd-home-manager-files/.config/nvim/init.lua \ No newline at end of file +/nix/store/9zm2q9k1vrgi6j8f3p14xz9xkh0ch2xy-home-manager-files/.config/nvim/init.lua \ No newline at end of file diff --git a/dotfiles/nvim/lua/conf/autocmd.lua b/dotfiles/nvim/lua/conf/autocmd.lua index ed54f3d..8003c48 120000 --- a/dotfiles/nvim/lua/conf/autocmd.lua +++ b/dotfiles/nvim/lua/conf/autocmd.lua @@ -1 +1 @@ -/nix/store/hhz4243ymgf24x646pxh30jm38iss4rd-home-manager-files/.config/nvim/lua/conf/autocmd.lua \ No newline at end of file +/nix/store/9zm2q9k1vrgi6j8f3p14xz9xkh0ch2xy-home-manager-files/.config/nvim/lua/conf/autocmd.lua \ No newline at end of file diff --git a/dotfiles/nvim/lua/conf/lsp-config.lua b/dotfiles/nvim/lua/conf/lsp-config.lua index 61609ef..d35276c 120000 --- a/dotfiles/nvim/lua/conf/lsp-config.lua +++ b/dotfiles/nvim/lua/conf/lsp-config.lua @@ -1 +1 @@ -/nix/store/hhz4243ymgf24x646pxh30jm38iss4rd-home-manager-files/.config/nvim/lua/conf/lsp-config.lua \ No newline at end of file +/nix/store/9zm2q9k1vrgi6j8f3p14xz9xkh0ch2xy-home-manager-files/.config/nvim/lua/conf/lsp-config.lua \ No newline at end of file diff --git a/dotfiles/nvim/lua/conf/remap.lua b/dotfiles/nvim/lua/conf/remap.lua index 3cd678f..5fc6447 120000 --- a/dotfiles/nvim/lua/conf/remap.lua +++ b/dotfiles/nvim/lua/conf/remap.lua @@ -1 +1 @@ -/nix/store/hhz4243ymgf24x646pxh30jm38iss4rd-home-manager-files/.config/nvim/lua/conf/remap.lua \ No newline at end of file +/nix/store/9zm2q9k1vrgi6j8f3p14xz9xkh0ch2xy-home-manager-files/.config/nvim/lua/conf/remap.lua \ No newline at end of file diff --git a/dotfiles/nvim/lua/conf/settings.lua b/dotfiles/nvim/lua/conf/settings.lua index 68b471e..8dec0ef 120000 --- a/dotfiles/nvim/lua/conf/settings.lua +++ b/dotfiles/nvim/lua/conf/settings.lua @@ -1 +1 @@ -/nix/store/hhz4243ymgf24x646pxh30jm38iss4rd-home-manager-files/.config/nvim/lua/conf/settings.lua \ No newline at end of file +/nix/store/9zm2q9k1vrgi6j8f3p14xz9xkh0ch2xy-home-manager-files/.config/nvim/lua/conf/settings.lua \ No newline at end of file diff --git a/dotfiles/nvim/luasnippets/matlab.lua b/dotfiles/nvim/luasnippets/matlab.lua index 10513fa..32bf2f4 120000 --- a/dotfiles/nvim/luasnippets/matlab.lua +++ b/dotfiles/nvim/luasnippets/matlab.lua @@ -1 +1 @@ -/nix/store/hhz4243ymgf24x646pxh30jm38iss4rd-home-manager-files/.config/nvim/luasnippets/matlab.lua \ No newline at end of file +/nix/store/9zm2q9k1vrgi6j8f3p14xz9xkh0ch2xy-home-manager-files/.config/nvim/luasnippets/matlab.lua \ No newline at end of file diff --git a/dotfiles/nvim/luasnippets/tex.lua b/dotfiles/nvim/luasnippets/tex.lua index d73b19b..5555086 120000 --- a/dotfiles/nvim/luasnippets/tex.lua +++ b/dotfiles/nvim/luasnippets/tex.lua @@ -1 +1 @@ -/nix/store/hhz4243ymgf24x646pxh30jm38iss4rd-home-manager-files/.config/nvim/luasnippets/tex.lua \ No newline at end of file +/nix/store/9zm2q9k1vrgi6j8f3p14xz9xkh0ch2xy-home-manager-files/.config/nvim/luasnippets/tex.lua \ No newline at end of file diff --git a/dotfiles/nvim/queries/nix/injections.scm b/dotfiles/nvim/queries/nix/injections.scm index 5d4e3c3..7cd9e0d 120000 --- a/dotfiles/nvim/queries/nix/injections.scm +++ b/dotfiles/nvim/queries/nix/injections.scm @@ -1 +1 @@ -/nix/store/hhz4243ymgf24x646pxh30jm38iss4rd-home-manager-files/.config/nvim/queries/nix/injections.scm \ No newline at end of file +/nix/store/9zm2q9k1vrgi6j8f3p14xz9xkh0ch2xy-home-manager-files/.config/nvim/queries/nix/injections.scm \ No newline at end of file diff --git a/home/afoucaultc/packages/neovim/config/extrapackages.nix b/home/afoucaultc/packages/neovim/config/extrapackages.nix index 3af2fd1..4b55b81 100644 --- a/home/afoucaultc/packages/neovim/config/extrapackages.nix +++ b/home/afoucaultc/packages/neovim/config/extrapackages.nix @@ -11,7 +11,7 @@ pyright # python v2 # formatters - nixfmt-rfc-style + nixfmt stylua ruff diff --git a/home/afoucaultc/packages/neovim/config/plugins.nix b/home/afoucaultc/packages/neovim/config/plugins.nix index de9ea06..be8af41 100644 --- a/home/afoucaultc/packages/neovim/config/plugins.nix +++ b/home/afoucaultc/packages/neovim/config/plugins.nix @@ -8,10 +8,14 @@ ../plugins/lualine.nix ../plugins/luasnip.nix ../plugins/mini.nix + ../plugins/neogit.nix + ../plugins/noice.nix ../plugins/oil.nix + ../plugins/snacks.nix ../plugins/telescope.nix ../plugins/treesitter.nix ../plugins/vimtex.nix + ../plugins/web-devicons.nix ../plugins/which-key.nix ]; } diff --git a/home/afoucaultc/packages/neovim/lua/autocmd.lua b/home/afoucaultc/packages/neovim/lua/autocmd.lua index 6a6d6e1..52235c9 100644 --- a/home/afoucaultc/packages/neovim/lua/autocmd.lua +++ b/home/afoucaultc/packages/neovim/lua/autocmd.lua @@ -1,48 +1,51 @@ -- (.config/nvim/lua/neoconf/autocmd.lua) -vim.api.nvim_create_autocmd("BufWritePre", { - callback = function() - vim.lsp.buf.format({ async = false }) - end, -}) - local function run_curr_python_file() - -- Get file name in the current buffer - local file_name = vim.api.nvim_buf_get_name(0) + -- Get file name in the current buffer + local file_name = vim.api.nvim_buf_get_name(0) - -- Get terminal codes for running python file - -- ("i" to enter insert before typing rest of the command) - local py_cmd = vim.api.nvim_replace_termcodes('ipython "' .. file_name .. '"', true, false, true) + -- Get terminal codes for running python file + -- ("i" to enter insert before typing rest of the command) + local py_cmd = vim.api.nvim_replace_termcodes('ipython "' .. file_name .. '"', true, false, true) - -- Determine terminal window split and launch terminal - local percent_of_win = 0.4 - local curr_win_height = vim.api.nvim_win_get_height(0) -- Current window height - local term_height = math.floor(curr_win_height * percent_of_win) -- Terminal height - vim.cmd(":below " .. term_height .. "split | term") -- Launch terminal (horizontal split) + -- Determine terminal window split and launch terminal + local percent_of_win = 0.4 + local curr_win_height = vim.api.nvim_win_get_height(0) -- Current window height + local term_height = math.floor(curr_win_height * percent_of_win) -- Terminal height + vim.cmd(":below " .. term_height .. "split | term") -- Launch terminal (horizontal split) - -- Press keys to run python command on current file - vim.api.nvim_feedkeys(py_cmd, "t", false) + -- Press keys to run python command on current file + vim.api.nvim_feedkeys(py_cmd, "t", false) end vim.keymap.set({ "n" }, "", "", { - desc = "Run .py file via Neovim built-in terminal", - callback = run_curr_python_file, + desc = "Run .py file via Neovim built-in terminal", + callback = run_curr_python_file, }) vim.api.nvim_create_autocmd("FileType", { - pattern = { "markdown", "rmd" }, - callback = function() - -- Force syntaxe markdown - vim.bo.syntax = "markdown" - -- Conceal normal pour markdown - vim.wo.conceallevel = 2 - -- Désactive vimtex pour ces fichiers - vim.b.vimtex_syntax_enabled = 0 - end, + pattern = { "markdown", "rmd" }, + callback = function() + -- Force syntaxe markdown + vim.bo.syntax = "markdown" + -- Conceal normal pour markdown + vim.wo.conceallevel = 2 + -- Désactive vimtex pour ces fichiers + vim.b.vimtex_syntax_enabled = 0 + -- spellcheck + vim.wo.spell = true + end, }) vim.api.nvim_create_autocmd("FileType", { pattern = "*", callback = function() - pcall(vim.treesitter.start) + local ok = pcall(vim.treesitter.start) + if ok then + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end end, }) +-- active spell sur .tex +vim.api.nvim_create_autocmd("FileType", { pattern = "tex", callback = function() vim.wo.spell = true end }) + +vim.api.nvim_create_autocmd("TextYankPost", { callback = function() vim.highlight.on_yank() end }) diff --git a/home/afoucaultc/packages/neovim/lua/lsp-config.lua b/home/afoucaultc/packages/neovim/lua/lsp-config.lua index 9061272..fcade38 100644 --- a/home/afoucaultc/packages/neovim/lua/lsp-config.lua +++ b/home/afoucaultc/packages/neovim/lua/lsp-config.lua @@ -1,14 +1,48 @@ -- diagnostic vim.diagnostic.config({ - virtual_text = { - prefix = "●", -- Icône avant le message - source = "if_many", -- Affiche la source LSP si plusieurs - format = function(diag) - return string.format("%s: %s", diag.source, diag.message) - end, - }, - signs = true, - underline = true, - update_in_insert = false, -- Évite flicker en insert - severity_sort = true, + virtual_text = { + prefix = "●", + source = "if_many", + format = function(diag) + return string.format("%s: %s", diag.source, diag.message) + end, + }, + signs = true, + underline = true, + update_in_insert = false, + severity_sort = true, +}) + +vim.keymap.set("n", "[d", function() + vim.diagnostic.jump({ count = -1, float = true }) +end, { desc = "Previous diagnostic" }) +vim.keymap.set("n", "]d", function() + vim.diagnostic.jump({ count = 1, float = true }) +end, { desc = "Next diagnostic" }) + +vim.api.nvim_create_autocmd("LspAttach", { + desc = "Configure LSP keymaps on attach", + callback = function(event) + local map = function(keys, func, desc) + vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) + end + + map("gd", vim.lsp.buf.definition, "Goto Definition") + map("gD", vim.lsp.buf.declaration, "Goto Declaration") + map("gr", vim.lsp.buf.references, "Goto References") + map("gI", vim.lsp.buf.implementation, "Goto Implementation") + map("K", vim.lsp.buf.hover, "Hover Documentation") + map("rn", vim.lsp.buf.rename, "Rename") + map("ca", vim.lsp.buf.code_action, "Code Action") + map("ds", vim.lsp.buf.document_symbol, "Document Symbols") + + local client = vim.lsp.get_client_by_id(event.data.client_id) + if client and client:supports_method("textDocument/inlayHint") then + vim.lsp.inlay_hint.enable(true, { bufnr = event.buf }) + map("th", function() + local enabled = vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf }) + vim.lsp.inlay_hint.enable(not enabled, { bufnr = event.buf }) + end, "Toggle Inlay Hints") + end + end, }) diff --git a/home/afoucaultc/packages/neovim/lua/remap.lua b/home/afoucaultc/packages/neovim/lua/remap.lua index e588532..99e68fb 100644 --- a/home/afoucaultc/packages/neovim/lua/remap.lua +++ b/home/afoucaultc/packages/neovim/lua/remap.lua @@ -25,36 +25,35 @@ vim.keymap.set("n", "fb", builtin.buffers, { desc = "Telescope buffers" vim.keymap.set("n", "fh", builtin.help_tags, { desc = "Telescope help tags" }) -- oil vim.keymap.set("n", "n", "Oil", { desc = "Launch oil buffer" }) --- python -vim.keymap.set("n", "", ":w:!python3 %", { noremap = true, silent = false }) - +vim.keymap.set("n", "-", "Oil", { desc = "Open parent directory" }) -- spell checker from fr to en vim.keymap.set("n", "sf", function() - if vim.o.spelllang == "fr" then - vim.o.spelllang = "en" - else - vim.o.spelllang = "fr" - end - vim.o.spell = true - print("Spelllang: " .. vim.o.spelllang) + if vim.o.spelllang == "fr" then + vim.o.spelllang = "en" + else + vim.o.spelllang = "fr" + end + vim.o.spell = true + print("Spelllang: " .. vim.o.spelllang) end, { desc = "Toggle spelllang FR/EN" }) -- toggle correction vim.keymap.set("n", "sg", function() - vim.wo.spell = not vim.wo.spell - vim.notify("Spell: " .. (vim.wo.spell and "ON" or "OFF"), vim.log.levels.INFO) + vim.wo.spell = not vim.wo.spell + vim.notify("Spell: " .. (vim.wo.spell and "ON" or "OFF"), vim.log.levels.INFO) end, { desc = "Toggle spell check" }) vim.api.nvim_create_user_command("OctaveRun", function() - vim.cmd("write") - vim.cmd('!octave -qf "%:p"') + vim.cmd("write") + vim.cmd('!octave -qf "%:p"') end, {}) +vim.keymap.set("n", "ro", "OctaveRun", { desc = "Run current Octave/Matlab file" }) -- set vimtex main to current file local function vimtex_set_main() - vim.b.vimtex_main = vim.fn.expand("%:p") - vim.b.vimtex = nil - vim.fn["vimtex#init"]() - print("VimTeX main → " .. vim.b.vimtex_main) + vim.b.vimtex_main = vim.fn.expand("%:p") + vim.b.vimtex = nil + vim.fn["vimtex#init"]() + print("VimTeX main → " .. vim.b.vimtex_main) end vim.keymap.set("n", "lm", vimtex_set_main, { desc = "VimTeX: set main to current file" }) diff --git a/home/afoucaultc/packages/neovim/lua/settings.lua b/home/afoucaultc/packages/neovim/lua/settings.lua index e9578b0..ed65a35 100644 --- a/home/afoucaultc/packages/neovim/lua/settings.lua +++ b/home/afoucaultc/packages/neovim/lua/settings.lua @@ -9,13 +9,13 @@ vim.o.relativenumber = true vim.o.showmode = true -- sync clipboard vim.schedule(function() - vim.o.clipboard = "unnamedplus" + vim.o.clipboard = "unnamedplus" end) -- enable break indent vim.o.breakindent = true -- indent options vim.o.autoindent = true -vim.o.smartindent = true +-- vim.o.smartindent = true vim.o.expandtab = true -- save undo history vim.o.undofile = true @@ -39,8 +39,15 @@ vim.o.scrolloff = 10 -- confirm save/confirm vim.o.confirm = true -- spell checking -vim.opt.spell = true +-- vim.opt.spell = true vim.opt.spelllang = "fr" -- wrap vim.o.wrap = true vim.o.linebreak = true +-- indent +vim.o.shiftwidth = 4 +vim.o.tabstop = 4 +vim.o.softtabstop = 4 +-- timers +vim.o.updatetime = 250 +vim.o.timeoutlen = 300 diff --git a/home/afoucaultc/packages/neovim/neovim.nix b/home/afoucaultc/packages/neovim/neovim.nix index c0d1463..168c943 100644 --- a/home/afoucaultc/packages/neovim/neovim.nix +++ b/home/afoucaultc/packages/neovim/neovim.nix @@ -1,4 +1,4 @@ -{ inputs, ... }: +{ inputs, pkgs, ... }: let nixvim = import ( builtins.fetchGit { @@ -23,5 +23,6 @@ in defaultEditor = true; viAlias = true; vimAlias = true; + nixpkgs.source = pkgs.path; }; } diff --git a/home/afoucaultc/packages/neovim/plugins/conform-nvim.nix b/home/afoucaultc/packages/neovim/plugins/conform-nvim.nix index 072e011..ba955c2 100644 --- a/home/afoucaultc/packages/neovim/plugins/conform-nvim.nix +++ b/home/afoucaultc/packages/neovim/plugins/conform-nvim.nix @@ -8,6 +8,10 @@ nix = [ "nixfmt" ]; lua = [ "stylua" ]; python = [ "ruff_format" ]; + format_on_save = { + lsp_fallback = true; + timeout_ms = 500; + }; }; }; }; diff --git a/home/afoucaultc/packages/neovim/plugins/gitsigns.nix b/home/afoucaultc/packages/neovim/plugins/gitsigns.nix index 73b1641..8f714ee 100644 --- a/home/afoucaultc/packages/neovim/plugins/gitsigns.nix +++ b/home/afoucaultc/packages/neovim/plugins/gitsigns.nix @@ -1,10 +1,61 @@ { ... }: { - programs.nixvim = { - plugins = { - gitsigns = { - enable = true; + programs.nixvim.plugins.gitsigns.enable = true; + + programs.nixvim.keymaps = [ + { + mode = "n"; + key = "]c"; + action.__raw = '' + function() + if vim.wo.diff then return "]c" end + vim.schedule(function() require("gitsigns").nav_hunk("next") end) + return "" + end + ''; + options = { + desc = "Next git hunk"; + expr = true; }; - }; - }; + } + { + mode = "n"; + key = "[c"; + action.__raw = '' + function() + if vim.wo.diff then return "[c" end + vim.schedule(function() require("gitsigns").nav_hunk("prev") end) + return "" + end + ''; + options = { + desc = "Previous git hunk"; + expr = true; + }; + } + { + mode = "n"; + key = "hs"; + action.__raw = ''function() require("gitsigns").stage_hunk() end''; + options.desc = "Stage hunk"; + } + { + mode = "n"; + key = "hr"; + action.__raw = ''function() require("gitsigns").reset_hunk() end''; + options.desc = "Reset hunk"; + } + { + mode = "n"; + key = "hp"; + action.__raw = ''function() require("gitsigns").preview_hunk() end''; + options.desc = "Preview hunk"; + } + { + mode = "n"; + key = "hb"; + action.__raw = ''function() require("gitsigns").blame_line({ full = true }) end''; + options.desc = "Blame line"; + } + ]; } diff --git a/home/afoucaultc/packages/neovim/plugins/lsp.nix b/home/afoucaultc/packages/neovim/plugins/lsp.nix index 6dff22a..d18934c 100644 --- a/home/afoucaultc/packages/neovim/plugins/lsp.nix +++ b/home/afoucaultc/packages/neovim/plugins/lsp.nix @@ -6,7 +6,7 @@ enable = true; servers = { nil_ls.enable = true; - lua-ls = { + lua_ls = { enable = true; settings.Lua.diagnostics.globals = [ "vim" ]; }; diff --git a/home/afoucaultc/packages/neovim/plugins/neogit.nix b/home/afoucaultc/packages/neovim/plugins/neogit.nix new file mode 100644 index 0000000..ccc5c17 --- /dev/null +++ b/home/afoucaultc/packages/neovim/plugins/neogit.nix @@ -0,0 +1,16 @@ +{ ... }: +{ + programs.nixvim.plugins = { + neogit.enable = true; + diffview.enable = true; # compagnon habituel de neogit pour les diffs + }; + + programs.nixvim.keymaps = [ + { + mode = "n"; + key = "gg"; + action = "Neogit"; + options.desc = "Open Neogit"; + } + ]; +} diff --git a/home/afoucaultc/packages/neovim/plugins/noice.nix b/home/afoucaultc/packages/neovim/plugins/noice.nix new file mode 100644 index 0000000..5e26929 --- /dev/null +++ b/home/afoucaultc/packages/neovim/plugins/noice.nix @@ -0,0 +1,10 @@ +{ ... }: +{ + programs.nixvim.plugins.noice = { + enable = true; + settings.lsp = { + "vim.lsp.util.convert_input_to_markdown_lines" = true; + "vim.lsp.util.stylize_markdown" = true; + }; + }; +} diff --git a/home/afoucaultc/packages/neovim/plugins/snacks.nix b/home/afoucaultc/packages/neovim/plugins/snacks.nix new file mode 100644 index 0000000..cb71fa9 --- /dev/null +++ b/home/afoucaultc/packages/neovim/plugins/snacks.nix @@ -0,0 +1,11 @@ +{ ... }: +{ + programs.nixvim.plugins.snacks = { + enable = true; + settings = { + bigfile.enabled = true; # gère proprement les très gros fichiers + quickfile.enabled = true; # affichage plus rapide au démarrage + indent.enabled = true; # guides d'indentation visuels + }; + }; +} diff --git a/home/afoucaultc/packages/neovim/plugins/web-devicons.nix b/home/afoucaultc/packages/neovim/plugins/web-devicons.nix new file mode 100644 index 0000000..8b51a45 --- /dev/null +++ b/home/afoucaultc/packages/neovim/plugins/web-devicons.nix @@ -0,0 +1,8 @@ +{ ... }: +{ + programs.nixvim = { + plugins = { + web-devicons.enable = true; + }; + }; +} diff --git a/home/afoucaultc/packages/neovim/plugins/which-key.nix b/home/afoucaultc/packages/neovim/plugins/which-key.nix index 48c24d4..78d043c 100644 --- a/home/afoucaultc/packages/neovim/plugins/which-key.nix +++ b/home/afoucaultc/packages/neovim/plugins/which-key.nix @@ -1,10 +1,17 @@ { ... }: { - programs.nixvim = { - plugins = { - which-key = { - enable = true; - }; - }; - }; + programs.nixvim.plugins.which-key.enable = true; + + programs.nixvim.extraConfigLua = '' + require("which-key").add({ + { "f", group = "Find" }, + { "g", group = "Git" }, + { "h", group = "Git Hunk" }, + { "s", group = "Spell" }, + { "c", group = "Code" }, + { "r", group = "Run" }, + { "l", group = "LaTeX" }, + { "t", group = "Toggle" }, + }) + ''; } diff --git a/hosts/common/style/stylix.nix b/hosts/common/style/stylix.nix index 3dd4475..9cb80dc 100644 --- a/hosts/common/style/stylix.nix +++ b/hosts/common/style/stylix.nix @@ -4,6 +4,7 @@ stylix = { enable = true; targets.gtksourceview.enable = false; + targets.nixvim.enable = false; base16Scheme = "${pkgs.base16-schemes}/share/themes/tokyo-night-dark.yaml"; polarity = "dark"; cursor = {