From 5aad861057212d8835773d4e71f2b0dbbbc32b8c Mon Sep 17 00:00:00 2001 From: Hadi <112569860+anotherhadi@users.noreply.github.com> Date: Thu, 23 Jan 2025 17:36:26 +0100 Subject: [PATCH] update my nvim config Former-commit-id: cd54511aa0463839e0034ca1ccced8fc233f48a1 --- home/programs/nvim/autocmds.nix | 187 ++++++++++++++++++++++++ home/programs/nvim/default.nix | 14 +- home/programs/nvim/options.nix | 171 ++++++++++++++++++---- home/programs/nvim/plugins/cmp.nix | 1 - home/programs/nvim/plugins/dap.nix | 28 ---- home/programs/nvim/plugins/lualine.nix | 30 ++++ home/programs/nvim/plugins/markdown.nix | 35 ++--- home/programs/nvim/plugins/ui.nix | 56 +------ home/programs/nvim/plugins/utils.nix | 20 --- home/programs/nvim/plugins/zenmode.nix | 46 ------ 10 files changed, 385 insertions(+), 203 deletions(-) create mode 100644 home/programs/nvim/autocmds.nix delete mode 100644 home/programs/nvim/plugins/dap.nix create mode 100644 home/programs/nvim/plugins/lualine.nix delete mode 100644 home/programs/nvim/plugins/zenmode.nix diff --git a/home/programs/nvim/autocmds.nix b/home/programs/nvim/autocmds.nix new file mode 100644 index 0000000..2ed5178 --- /dev/null +++ b/home/programs/nvim/autocmds.nix @@ -0,0 +1,187 @@ +{ + programs.nixvim = { + autoGroups = { + auto_quit.clear = true; + autoview.clear = true; + bufferline.clear = true; + checktime.clear = true; + create_dir.clear = true; + editorconfig_filetype.clear = true; + file_user_events.clear = true; + highlighturl.clear = true; + highlightyank.clear = true; + large_buf_settings.clear = true; + q_close_windows.clear = true; + terminal_settings.clear = true; + unlist_quickfix.clear = true; + }; + + autoCmd = [ + # auto_quit + # https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/_astrocore_autocmds.lua#L18-L46 + { + desc = + "Quit neovim if more than one window is open and only sidebar windows are list"; + event = "BufEnter"; + group = "auto_quit"; + + callback.__raw = '' + function() + local wins = vim.api.nvim_tabpage_list_wins(0) + -- Both neo-tree and aerial will auto-quit if there is only a single window left + if #wins <= 1 then return end + local sidebar_fts = { aerial = true, ["neo-tree"] = true } + for _, winid in ipairs(wins) do + if vim.api.nvim_win_is_valid(winid) then + local bufnr = vim.api.nvim_win_get_buf(winid) + local filetype = vim.bo[bufnr].filetype + -- If any visible windows are not sidebars, early return + if not sidebar_fts[filetype] then + return + -- If the visible window is a sidebar + else + -- only count filetypes once, so remove a found sidebar from the detection + sidebar_fts[filetype] = nil + end + end + end + if #vim.api.nvim_list_tabpages() > 1 then + vim.cmd.tabclose() + else + vim.cmd.qall() + end + end + ''; + } + + # autoview + # https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/_astrocore_autocmds.lua#L49-L70 + { + desc = "Save view with mkview for real files"; + event = [ "BufWinLeave" "BufWritePost" "WinLeave" ]; + group = "autoview"; + + callback.__raw = '' + function(event) + if vim.b[event.buf].view_activated then vim.cmd.mkview { mods = { emsg_silent = true } } end + end + ''; + } + { + desc = + "Try to load file view if available and enable view saving for real files"; + event = "BufWinEnter"; + group = "autoview"; + + callback.__raw = '' + function(event) + if not vim.b[event.buf].view_activated then + local filetype = vim.bo[event.buf].filetype + local buftype = vim.bo[event.buf].buftype + local ignore_filetypes = { "gitcommit", "gitrebase", "svg", "hgcommit" } + if buftype == "" and filetype and filetype ~= "" and not vim.tbl_contains(ignore_filetypes, filetype) then + vim.b[event.buf].view_activated = true + vim.cmd.loadview { mods = { emsg_silent = true } } + end + end + end + ''; + } + + # checktime + # https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/_astrocore_autocmds.lua#L118-L122 + { + desc = "Check if buffers changed on editor focus"; + event = [ "FocusGained" "TermClose" "TermLeave" ]; + group = "checktime"; + command = "checktime"; + } + + # editorconfig_filetype + # https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/_astrocore_autocmds.lua#L135-L144 + { + desc = + "Configure editorconfig after filetype detection to override `ftplugin`s"; + event = "FileType"; + group = "editorconfig_filetype"; + + callback.__raw = '' + function(args) + if vim.F.if_nil(vim.b.editorconfig, vim.g.editorconfig, true) then + local editorconfig_avail, editorconfig = pcall(require, "editorconfig") + if editorconfig_avail then editorconfig.config(args.buf) end + end + end + ''; + } + + # highlightyank + # https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/_astrocore_autocmds.lua#L206-L211 + { + desc = "Highlight yanked text"; + event = "TextYankPost"; + group = "highlightyank"; + pattern = "*"; + + callback.__raw = '' + function() + vim.highlight.on_yank() + end + ''; + } + + # q_close_windows + # https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/_astrocore_autocmds.lua#L242-L255 + { + desc = "Make q close help, man, quickfix, dap floats"; + event = "BufWinEnter"; + group = "q_close_windows"; + + callback.__raw = '' + function(event) + if vim.tbl_contains({ "help", "nofile", "quickfix" }, vim.bo[event.buf].buftype) then + vim.keymap.set("n", "q", "close", { + desc = "Close window", + buffer = event.buf, + silent = true, + nowait = true, + }) + end + end + ''; + } + + # terminal_settings + # https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/_astrocore_autocmds.lua#L258-L266 + { + desc = "Disable line number/fold column/sign column for terminals"; + event = "TermOpen"; + group = "terminal_settings"; + + callback.__raw = '' + function() + vim.opt_local.number = false + vim.opt_local.relativenumber = false + vim.opt_local.foldcolumn = "0" + vim.opt_local.signcolumn = "no" + end + ''; + } + + # unlist_quickfix + # https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/_astrocore_autocmds.lua#L270-L275 + { + desc = "Unlist quickfix buffers"; + event = "FileType"; + group = "unlist_quickfix"; + pattern = "qf"; + + callback.__raw = '' + function() + vim.opt_local.buflisted = false + end + ''; + } + ]; + }; +} diff --git a/home/programs/nvim/default.nix b/home/programs/nvim/default.nix index 66f12ee..317019c 100644 --- a/home/programs/nvim/default.nix +++ b/home/programs/nvim/default.nix @@ -2,19 +2,19 @@ { inputs, ... }: { imports = [ inputs.nixvim.homeManagerModules.nixvim - ./plugins/cmp.nix - ./plugins/dashboard.nix ./plugins/lsp.nix - ./plugins/markdown.nix ./plugins/tree.nix - ./plugins/ui.nix - ./plugins/utils.nix - ./plugins/dap.nix ./plugins/telescope.nix - ./plugins/zenmode.nix + ./plugins/cmp.nix + ./plugins/ui.nix + ./plugins/lualine.nix + ./plugins/utils.nix + ./plugins/dashboard.nix + ./plugins/markdown.nix ./options.nix ./keymaps.nix + ./autocmds.nix ]; programs.nixvim.enable = true; diff --git a/home/programs/nvim/options.nix b/home/programs/nvim/options.nix index 8cb51c7..2f1b7ea 100644 --- a/home/programs/nvim/options.nix +++ b/home/programs/nvim/options.nix @@ -1,38 +1,151 @@ { - programs.nixvim.globals.mapleader = " "; - programs.nixvim.opts = { - updatetime = 50; # Faster completion + programs.nixvim = { + globals.mapleader = " "; + opts = { + autoindent = true; - number = true; - relativenumber = true; + smartindent = true; - autoindent = true; - clipboard = "unnamed,unnamedplus"; + incsearch = true; + hlsearch = true; + wildmode = "list:longest"; + scrolloff = 8; - expandtab = true; - tabstop = 2; - softtabstop = 2; - shiftwidth = 2; - smartindent = true; - breakindent = true; + swapfile = false; + conceallevel = 3; + clipboard = "unnamed,unnamedplus"; - ignorecase = true; - incsearch = true; - hlsearch = true; - smartcase = true; - wildmode = "list:longest"; - completeopt = [ "menuone" "noselect" "noinsert" ]; - signcolumn = "yes"; - cursorline = false; - scrolloff = 8; - mouse = "a"; - termguicolors = true; - showmode = false; + # Don't stop backspace at insert + backspace.__raw = '' + vim.list_extend(vim.opt.backspace:get(), { "nostop" }) + ''; - wrap = false; + # Keep visual indentation on wrapped lines + breakindent = true; - swapfile = false; - undofile = true; - conceallevel = 3; + # Hide command line unless needed + cmdheight = 0; + + # Insert mode completion options + completeopt = [ "menu" "menuone" "noselect" ]; + + # Raise a dialog asking if you wish to save the current file(s) + confirm = true; + + # Copy previous indentation on autoindenting + copyindent = true; + + # Highlight current line + cursorline = true; + + # Enable linematch diff algorithm + diffopt.__raw = '' + vim.list_extend(vim.opt.diffopt:get(), { "algorithm:histogram", "linematch:60" }) + ''; + + # Expand to spaces + expandtab = true; + + # Disable `~` on nonexistent lines + fillchars = { eob = " "; }; + + # Enable fold with all code unfolded + foldcolumn = "1"; + foldenable = true; + foldlevel = 99; + foldlevelstart = 99; + + # Ignore case in search patterns + ignorecase = true; + + # Show substitution preview in split window + inccommand = "split"; + + # Infer casing on word completion + infercase = true; + + # Global statusline + laststatus = 3; + + # Wrap lines at 'breakat' + linebreak = true; + + # Enable mouse support + mouse = "a"; + + # Show line numbers + number = true; + + # Preserve indentation as much as possible + preserveindent = true; + + # Height of the popup menu + pumheight = 10; + + # Display line numbers relative to current line + relativenumber = true; + + # Minimal number of lines to keep around the cursor + # This has the effect to move the view along with current line + #scrolloff = 999; + + # Number of spaces to use for indentation + shiftwidth = 2; + + # Disable search count wrap and startup messages + shortmess.__raw = '' + vim.tbl_deep_extend("force", vim.opt.shortmess:get(), { s = true, I = true }) + ''; + + # Disable showing modes in command line + showmode = false; + + # Always show tabline + showtabline = 2; + + # Show signs column + signcolumn = "yes"; + + # Override ignorecase if search pattern contains uppercase characters + smartcase = true; + + # Number of spaces input on + softtabstop = 2; + + # Open horizontal split below (:split) + splitbelow = true; + + # Open vertical split to the right (:vsplit) + splitright = true; + + # Number of spaces to represent a + tabstop = 2; + + # Enables 24-bit RGB color + termguicolors = true; + + # Shorter timeout duration + timeoutlen = 500; + + # Set window title to the filename + title = true; + + # Save undo history to undo file (in $XDG_STATE_HOME/nvim/undo) + undofile = true; + + viewoptions.__raw = '' + vim.tbl_filter(function(val) return val ~= "curdir" end, vim.opt.viewoptions:get()) + ''; + + # Enable virtual edit in visual block mode + # This has the effect of selecting empty cells beyond lines boundaries + virtualedit = "block"; + + # Disable line wrapping + wrap = false; + + # Disable making a backup before overwriting a file + writebackup = false; + }; }; } diff --git a/home/programs/nvim/plugins/cmp.nix b/home/programs/nvim/plugins/cmp.nix index e53726a..263b6bf 100644 --- a/home/programs/nvim/plugins/cmp.nix +++ b/home/programs/nvim/plugins/cmp.nix @@ -112,6 +112,5 @@ }; }; }; - }; } diff --git a/home/programs/nvim/plugins/dap.nix b/home/programs/nvim/plugins/dap.nix deleted file mode 100644 index 1de9291..0000000 --- a/home/programs/nvim/plugins/dap.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ pkgs, ... }: { - programs.nixvim.plugins.dap = { - enable = true; - adapters = { }; - signs = { - dapBreakpoint = { - text = "●"; - texthl = "DapBreakpoint"; - }; - dapBreakpointCondition = { - text = "●"; - texthl = "DapBreakpointCondition"; - }; - dapLogPoint = { - text = "◆"; - texthl = "DapLogPoint"; - }; - }; - extensions = { - dap-go = { - enable = true; - delve.path = "${pkgs.delve}/bin/dlv"; - }; - dap-ui = { enable = true; }; - dap-virtual-text = { enable = true; }; - }; - }; -} diff --git a/home/programs/nvim/plugins/lualine.nix b/home/programs/nvim/plugins/lualine.nix new file mode 100644 index 0000000..d1d602b --- /dev/null +++ b/home/programs/nvim/plugins/lualine.nix @@ -0,0 +1,30 @@ +{ + programs.nixvim.plugins.lualine = { + enable = true; + settings = { + options.disabled_filetypes.statusline = + [ "dashboard" "alpha" "neo-tree" ]; + + alwaysDivideMiddle = true; + globalstatus = true; + ignoreFocus = [ "neo-tree" ]; + extensions = [ "fzf" ]; + componentSeparators = { + left = "|"; + right = "|"; + }; + sectionSeparators = { + left = "█"; #  + right = "█"; #  + }; + sections = { + lualine_a = [ "mode" ]; + lualine_b = [ "branch" "diff" "diagnostics" ]; + lualine_c = [ "filename" ]; + lualine_x = [ "filetype" ]; + lualine_y = [ "progress" ]; + lualine_z = [ ''" " .. os.date("%R")'' ]; + }; + }; + }; +} diff --git a/home/programs/nvim/plugins/markdown.nix b/home/programs/nvim/plugins/markdown.nix index b50b2da..b1d8435 100644 --- a/home/programs/nvim/plugins/markdown.nix +++ b/home/programs/nvim/plugins/markdown.nix @@ -1,4 +1,3 @@ -# The render-markdown.nvim plugin is a plugin that renders markdown files in a neovim in a more readable way. { config, ... }: let accent = "#${config.lib.stylix.colors.base0D}"; @@ -11,7 +10,6 @@ in { plugins.mkdnflow = { enable = true; modules = { conceal = false; }; - toDo.symbols = [ " " "-" "x" "!" "/" ]; mappings = { MkdnCreateLink = false; @@ -29,14 +27,17 @@ in { modes = [ "v" ]; }; MkdnExtendList = false; + MkdnFoldSection = { key = "mf"; modes = "n"; }; + MkdnUnfoldSection = { key = "mF"; modes = "n"; }; + MkdnFollowLink = { key = "gd"; modes = "n"; @@ -128,30 +129,16 @@ in { RenderMarkdownH4.fg = accent-alt; RenderMarkdownH5.fg = accent-alt; RenderMarkdownH6.fg = accent-alt; - RenderMarkdownTodo.fg = muted; - RenderMarkdownWarning.fg = accent; - }; - plugins.headlines = { - enable = true; - settings = { - markdown = { - headline_highlights = [ - "RenderMarkdownH1" - "RenderMarkdownH2" - "RenderMarkdownH3" - "RenderMarkdownH4" - "RenderMarkdownH5" - "RenderMarkdownH6" - ]; - fat_headlines = false; - }; - }; + RenderMarkdownTodo.fg = "#f78c6c"; + RenderMarkdownWarning.fg = "#ff5370"; + RenderMarkdownDone.fg = muted; }; plugins.render-markdown = { enable = true; settings = { heading = { icons = [ "# " "󰲣 " "󰲥 " "󰲧 " "󰲩 " "󰲫 " ]; + sign = false; backgrounds = [ "RenderMarkdownBg" ]; foregrounds = [ "RenderMarkdownH1" @@ -164,22 +151,22 @@ in { }; checkbox = { unchecked = { highlight = "RenderMarkdownTodo"; }; - checked = { highlight = "RenderMarkdownTodo"; }; + checked = { highlight = "RenderMarkdownDone"; }; custom = { pending = { raw = "[-]"; - rendered = "󰥔 "; + rendered = " "; highlight = "RenderMarkdownTodo"; }; important = { raw = "[!]"; - rendered = " "; + rendered = "󰰱 "; highlight = "RenderMarkdownWarning"; }; cancel = { raw = "[/]"; rendered = "󱋬 "; - highlight = "RenderMarkdownTodo"; + highlight = "RenderMarkdownWarning"; }; }; }; diff --git a/home/programs/nvim/plugins/ui.nix b/home/programs/nvim/plugins/ui.nix index c0089c8..ffa72b5 100644 --- a/home/programs/nvim/plugins/ui.nix +++ b/home/programs/nvim/plugins/ui.nix @@ -1,54 +1,14 @@ { pkgs, ... }: { home.packages = with pkgs; [ ctags ]; - programs.nixvim = { - plugins = { - lualine = { - enable = true; - settings = { - options.disabled_filetypes.statusline = - [ "dashboard" "alpha" "neo-tree" ]; - - alwaysDivideMiddle = true; - globalstatus = true; - ignoreFocus = [ "neo-tree" ]; - extensions = [ "fzf" ]; - theme = "auto"; - componentSeparators = { - left = "|"; - right = "|"; - }; - sectionSeparators = { - left = "█"; #  - right = "█"; #  - }; - sections = { - lualine_a = [ "mode" ]; - lualine_b = [ "branch" "diff" "diagnostics" ]; - lualine_c = [ "filename" ]; - lualine_x = [ "filetype" ]; - lualine_y = [ "progress" ]; - lualine_z = [ ''" " .. os.date("%R")'' ]; - }; - }; - }; - web-devicons.enable = true; - noice.enable = true; - notify = { - enable = true; - level = "warn"; - }; - gitsigns = { - enable = true; - settings.current_line_blame = false; - }; - trouble.enable = true; - indent-blankline.enable = true; - colorizer.enable = true; - tagbar = { - enable = true; - tagsPackage = pkgs.universal-ctags; - }; + programs.nixvim.plugins = { + web-devicons.enable = true; + noice.enable = true; + gitsigns = { + enable = true; + settings.current_line_blame = false; }; + trouble.enable = true; + bufferline.enable = true; }; } diff --git a/home/programs/nvim/plugins/utils.nix b/home/programs/nvim/plugins/utils.nix index dfe23ce..f10112f 100644 --- a/home/programs/nvim/plugins/utils.nix +++ b/home/programs/nvim/plugins/utils.nix @@ -17,34 +17,14 @@ tmux-navigator.enable = true; comment.enable = true; nvim-autopairs.enable = true; - friendly-snippets.enable = true; todo-comments.enable = true; treesitter = { enable = true; nixGrammars = true; settings = { ensure_installed = "all"; - incremental_selection.enable = true; indent.enable = true; highlight.enable = true; - highlight.additional_vim_regex_highlighting = true; - }; - }; - harpoon = { - enable = true; - enableTelescope = true; - keymapsSilent = true; - keymaps = { - addFile = "ha"; - toggleQuickMenu = "hu"; - navNext = "hl"; - navPrev = "hh"; - navFile = { - "1" = "h1"; - "2" = "h2"; - "3" = "h3"; - "4" = "h4"; - }; }; }; }; diff --git a/home/programs/nvim/plugins/zenmode.nix b/home/programs/nvim/plugins/zenmode.nix deleted file mode 100644 index 3ec69ae..0000000 --- a/home/programs/nvim/plugins/zenmode.nix +++ /dev/null @@ -1,46 +0,0 @@ -{ - programs.nixvim.plugins = { - zen-mode = { - enable = true; - settings = { - on_close = '' - function() - require("gitsigns.actions").toggle_current_line_blame() - vim.cmd('IBLEnable') - vim.opt.signcolumn = "yes:2" - vim.wo.wrap = false - vim.wo.linebreak = false - require("gitsigns.actions").refresh() - end - ''; - on_open = '' - function() - require("gitsigns.actions").toggle_current_line_blame() - vim.cmd('IBLDisable') - vim.opt.relativenumber = false - vim.opt.signcolumn = "no" - vim.wo.wrap = true - vim.wo.linebreak = true - require("gitsigns.actions").refresh() - end - ''; - window = { - backdrop = 1; - height = 1; - options = { - signcolumn = "no"; - number = false; - relativenumber = false; - cursorline = false; - cursorcolumn = false; - foldcolumn = "0"; - list = false; - }; - width = 0.8; - - }; - }; - }; - - }; -}