From c3ee469ed568578632c1127dc391774edd2c637b Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Thu, 10 Oct 2024 00:48:10 -0700 Subject: [PATCH] add formatters and cool stuff --- .stylua.toml | 1 + flake.nix | 7 + lua/keymaps.lua | 42 ++- lua/plugins/blink-cmp.lua | 452 ++++++++++++++-------------- lua/plugins/conform.lua | 34 +++ lua/plugins/harpoon.lua | 80 ++--- lua/plugins/lualine.lua | 111 ++++--- lua/plugins/lz-spec.lua | 601 +++++++++++++++++++------------------- lua/plugins/oil.lua | 70 ++--- lua/plugins/telescope.lua | 65 +++-- 10 files changed, 766 insertions(+), 697 deletions(-) create mode 100644 lua/plugins/conform.lua diff --git a/.stylua.toml b/.stylua.toml index 394e884..0435f67 100644 --- a/.stylua.toml +++ b/.stylua.toml @@ -1 +1,2 @@ indent_type = "Spaces" +indent_width = 2 diff --git a/flake.nix b/flake.nix index e774812..0ee1d7c 100644 --- a/flake.nix +++ b/flake.nix @@ -151,6 +151,12 @@ lua-language-server nixd nixfmt-rfc-style + nodePackages_latest.prettier + taplo + typstyle + rustfmt + black + stylua ]; }; @@ -226,6 +232,7 @@ diffview-nvim barbecue-nvim undotree + conform-nvim ]; }; diff --git a/lua/keymaps.lua b/lua/keymaps.lua index 5f3ded1..4f1cec1 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -9,10 +9,10 @@ vim.keymap.set("t", "", "") vim.keymap.set("n", "", "zz") vim.keymap.set("n", "", "zz") -vim.keymap.set("n", "mr", function () +vim.keymap.set("n", "mr", function() vim.cmd.CellularAutomaton("make_it_rain") end) -vim.keymap.set("n", "bruh", function () +vim.keymap.set("n", "bruh", function() vim.cmd.CellularAutomaton("game_of_life") end) @@ -21,21 +21,39 @@ vim.keymap.set("n", "n", "nzzzv") vim.keymap.set("n", "N", "Nzzzv") -- The greatest remap of all time -- the primeagen -vim.keymap.set({"n", "v"}, "d",'"_d', { desc = "same as `d` but send to black hole register"}) -vim.keymap.set({"n", "v"}, "D",'"_D', { desc = "same as `D` but send to black hole register"}) +vim.keymap.set({ "n", "v" }, "d", '"_d', { desc = "same as `d` but send to black hole register" }) +vim.keymap.set({ "n", "v" }, "D", '"_D', { desc = "same as `D` but send to black hole register" }) -- The real greatest remap(s) of all time -- me -vim.keymap.set({"n", "v"}, "y",'"+y', { desc = "yank to clipboard"}) -vim.keymap.set({"n", "v"}, "Y",'"+Y', { desc = "yank rest of line to clipboard"}) -vim.keymap.set({"n", "v"}, "p",'"+p', { desc = "put after cursor from clipboard"}) -vim.keymap.set({"n", "v"}, "P",'"+P', { desc = "put before cursor from clipboard"}) +vim.keymap.set({ "n", "v" }, "y", '"+y', { desc = "yank to clipboard" }) +vim.keymap.set({ "n", "v" }, "Y", '"+Y', { desc = "yank rest of line to clipboard" }) +vim.keymap.set({ "n", "v" }, "p", '"+p', { desc = "put after cursor from clipboard" }) +vim.keymap.set({ "n", "v" }, "P", '"+P', { desc = "put before cursor from clipboard" }) -vim.keymap.set("n", "gg", function () +vim.keymap.set("n", "gg", function() vim.cmd.Neogit() end, { desc = "Open neogit" }) -vim.keymap.set("n", "gc", function () +vim.keymap.set("n", "gc", function() vim.cmd.Neogit("kind=floating commit") end, { desc = "Open neogit commit menu" }) -vim.keymap.set("n", "u", function () +vim.keymap.set("n", "u", function() vim.cmd.UndotreeToggle() -end, {desc = "Toggle undotree"}) +end, { desc = "Toggle undotree" }) + +vim.keymap.set({ "n", "v" }, "cf", function() + require("conform").format({ async = true }) +end) +vim.keymap.set({ "n", "v" }, "ctf", function() + if vim.g.disable_autoformat then + vim.g.disable_autoformat = false + else + vim.g.disable_autoformat = true + end +end, { desc = "Disable autoformat on save globally" }) +vim.keymap.set({ "n", "v" }, "cbf", function() + if vim.b[0].disable_autoformat then + vim.b[0].disable_autoformat = false + else + vim.b[0].disable_autoformat = true + end +end, { desc = "Disable autoformat on save buffer" }) diff --git a/lua/plugins/blink-cmp.lua b/lua/plugins/blink-cmp.lua index 9b5cc57..1bb919e 100644 --- a/lua/plugins/blink-cmp.lua +++ b/lua/plugins/blink-cmp.lua @@ -1,242 +1,242 @@ return { - "blink-cmp", - event = "BufEnter", - after = function() - require("blink-cmp").setup({ - -- for keymap, all values may be string | string[] - -- use an empty table to disable a keymap - keymap = { - show = "", - hide = "", - accept = "", - select_prev = { "", "" }, - select_next = { "", "" }, + "blink-cmp", + event = "BufEnter", + after = function() + require("blink-cmp").setup({ + -- for keymap, all values may be string | string[] + -- use an empty table to disable a keymap + keymap = { + show = "", + hide = "", + accept = "", + select_prev = { "", "" }, + select_next = { "", "" }, - show_documentation = {}, - hide_documentation = {}, - scroll_documentation_up = "", - scroll_documentation_down = "", + show_documentation = {}, + hide_documentation = {}, + scroll_documentation_up = "", + scroll_documentation_down = "", - snippet_forward = "", - snippet_backward = "", + snippet_forward = "", + snippet_backward = "", + }, + + accept = { + create_undo_point = true, + auto_brackets = { + enabled = false, + default_brackets = { "(", ")" }, + override_brackets_for_filetypes = {}, + -- Overrides the default blocked filetypes + force_allow_filetypes = {}, + blocked_filetypes = {}, + -- Synchronously use the kind of the item to determine if brackets should be added + kind_resolution = { + enabled = true, + blocked_filetypes = { "typescript", "typescriptreact", "javascript", "javascriptreact", "vue" }, + }, + -- Asynchronously use semantic token to determine if brackets should be added + semantic_token_resolution = { + enabled = true, + blocked_filetypes = {}, + }, + }, + }, + + trigger = { + completion = { + -- regex used to get the text when fuzzy matching + -- changing this may break some sources, so please report if you run into issues + -- todo: shouldnt this also affect the accept command? should this also be per language? + keyword_regex = "[%w_\\-]", + -- LSPs can indicate when to show the completion window via trigger characters + -- however, some LSPs (*cough* tsserver *cough*) return characters that would essentially + -- always show the window. We block these by default + blocked_trigger_characters = { " ", "\n", "\t" }, + -- when true, will show the completion window when the cursor comes after a trigger character when entering insert mode + show_on_insert_on_trigger_character = true, + }, + + signature_help = { + enabled = false, + blocked_trigger_characters = {}, + blocked_retrigger_characters = {}, + -- when true, will show the signature help window when the cursor comes after a trigger character when entering insert mode + show_on_insert_on_trigger_character = true, + }, + }, + + fuzzy = { + -- frencency tracks the most recently/frequently used items and boosts the score of the item + use_frecency = true, + -- proximity bonus boosts the score of items with a value in the buffer + use_proximity = true, + max_items = 200, + -- controls which sorts to use and in which order, these three are currently the only allowed options + sorts = { "label", "kind", "score" }, + + prebuiltBinaries = { + -- Whether or not to automatically download a prebuilt binary from github. If this is set to `false` + -- you will need to manually build the fuzzy binary dependencies by running `cargo build --release` + download = false, + -- When downloading a prebuilt binary force the downloader to resolve this version. If this is uset + -- then the downloader will attempt to infer the version from the checked out git tag (if any). + -- + -- Beware that if the FFI ABI changes while tracking main then this may result in blink breaking. + forceVersion = nil, + }, + }, + + sources = { + -- similar to nvim-cmp's sources, but we point directly to the source's lua module + -- multiple groups can be provided, where it'll fallback to the next group if the previous + -- returns no completion items + -- WARN: This API will have breaking changes during the beta + providers = { + { + { "blink.cmp.sources.lsp" }, + { "blink.cmp.sources.path" }, + { "blink.cmp.sources.snippets", score_offset = -3 }, + }, + { { "blink.cmp.sources.buffer" } }, + }, + -- FOR REF: full example + providers = { + { + -- all of these properties work on every source + { + "blink.cmp.sources.lsp", + keyword_length = 0, + score_offset = 0, + trigger_characters = { "f", "o", "o" }, + opts = {}, }, - - accept = { - create_undo_point = true, - auto_brackets = { - enabled = false, - default_brackets = { "(", ")" }, - override_brackets_for_filetypes = {}, - -- Overrides the default blocked filetypes - force_allow_filetypes = {}, - blocked_filetypes = {}, - -- Synchronously use the kind of the item to determine if brackets should be added - kind_resolution = { - enabled = true, - blocked_filetypes = { "typescript", "typescriptreact", "javascript", "javascriptreact", "vue" }, - }, - -- Asynchronously use semantic token to determine if brackets should be added - semantic_token_resolution = { - enabled = true, - blocked_filetypes = {}, - }, - }, + -- the follow two sources have additional options + { + "blink.cmp.sources.path", + opts = { + trailing_slash = false, + label_trailing_slash = true, + get_cwd = function(context) + return vim.fn.expand(("#%d:p:h"):format(context.bufnr)) + end, + show_hidden_files_by_default = true, + }, }, - - trigger = { - completion = { - -- regex used to get the text when fuzzy matching - -- changing this may break some sources, so please report if you run into issues - -- todo: shouldnt this also affect the accept command? should this also be per language? - keyword_regex = "[%w_\\-]", - -- LSPs can indicate when to show the completion window via trigger characters - -- however, some LSPs (*cough* tsserver *cough*) return characters that would essentially - -- always show the window. We block these by default - blocked_trigger_characters = { " ", "\n", "\t" }, - -- when true, will show the completion window when the cursor comes after a trigger character when entering insert mode - show_on_insert_on_trigger_character = true, - }, - - signature_help = { - enabled = false, - blocked_trigger_characters = {}, - blocked_retrigger_characters = {}, - -- when true, will show the signature help window when the cursor comes after a trigger character when entering insert mode - show_on_insert_on_trigger_character = true, - }, + { + "blink.cmp.sources.snippets", + score_offset = -3, + -- similar to https://github.com/garymjr/nvim-snippets + opts = { + friendly_snippets = true, + search_paths = { vim.fn.stdpath("config") .. "/snippets" }, + global_snippets = { "all" }, + extended_filetypes = {}, + ignored_filetypes = {}, + }, }, + }, + { { "blink.cmp.sources.buffer" } }, + }, + }, - fuzzy = { - -- frencency tracks the most recently/frequently used items and boosts the score of the item - use_frecency = true, - -- proximity bonus boosts the score of items with a value in the buffer - use_proximity = true, - max_items = 200, - -- controls which sorts to use and in which order, these three are currently the only allowed options - sorts = { "label", "kind", "score" }, + windows = { + autocomplete = { + min_width = 30, + max_width = 60, + max_height = 10, + border = "none", + winhighlight = "Normal:BlinkCmpMenu,FloatBorder:BlinkCmpMenuBorder,CursorLine:BlinkCmpMenuSelection,Search:None", + -- keep the cursor X lines away from the top/bottom of the window + scrolloff = 2, + -- which directions to show the window, + -- falling back to the next direction when there's not enough space + direction_priority = { "s", "n" }, + -- whether to preselect the first item in the completion list + preselect = true, + -- Controls how the completion items are rendered on the popup window + -- 'simple' will render the item's kind icon the left alongside the label + -- 'reversed' will render the label on the left and the kind icon + name on the right + -- 'function(blink.cmp.CompletionRenderContext): blink.cmp.Component[]' for custom rendering + draw = "simple", + -- Controls the cycling behavior when reaching the beginning or end of the completion list. + cycle = { + -- When `true`, calling `select_next` at the *bottom* of the completion list will select the *first* completion item. + from_bottom = true, + -- When `true`, calling `select_prev` at the *top* of the completion list will select the *last* completion item. + from_top = true, + }, + }, + documentation = { + min_width = 10, + max_width = 60, + max_height = 20, + border = "padded", + winhighlight = "Normal:BlinkCmpDoc,FloatBorder:BlinkCmpDocBorder,CursorLine:BlinkCmpDocCursorLine,Search:None", + -- which directions to show the documentation window, + -- for each of the possible autocomplete window directions, + -- falling back to the next direction when there's not enough space + direction_priority = { + autocomplete_north = { "e", "w", "n", "s" }, + autocomplete_south = { "e", "w", "s", "n" }, + }, + auto_show = true, + auto_show_delay_ms = 500, + update_delay_ms = 100, + }, + signature_help = { + min_width = 1, + max_width = 100, + max_height = 10, + border = "padded", + winhighlight = "Normal:BlinkCmpSignatureHelp,FloatBorder:BlinkCmpSignatureHelpBorder", + }, + }, - prebuiltBinaries = { - -- Whether or not to automatically download a prebuilt binary from github. If this is set to `false` - -- you will need to manually build the fuzzy binary dependencies by running `cargo build --release` - download = true, - -- When downloading a prebuilt binary force the downloader to resolve this version. If this is uset - -- then the downloader will attempt to infer the version from the checked out git tag (if any). - -- - -- Beware that if the FFI ABI changes while tracking main then this may result in blink breaking. - forceVersion = nil, - }, - }, + highlight = { + ns = vim.api.nvim_create_namespace("blink_cmp"), + -- sets the fallback highlight groups to nvim-cmp's highlight groups + -- useful for when your theme doesn't support blink.cmp + -- will be removed in a future release, assuming themes add support + use_nvim_cmp_as_default = false, + }, - sources = { - -- similar to nvim-cmp's sources, but we point directly to the source's lua module - -- multiple groups can be provided, where it'll fallback to the next group if the previous - -- returns no completion items - -- WARN: This API will have breaking changes during the beta - providers = { - { - { "blink.cmp.sources.lsp" }, - { "blink.cmp.sources.path" }, - { "blink.cmp.sources.snippets", score_offset = -3 }, - }, - { { "blink.cmp.sources.buffer" } }, - }, - -- FOR REF: full example - providers = { - { - -- all of these properties work on every source - { - "blink.cmp.sources.lsp", - keyword_length = 0, - score_offset = 0, - trigger_characters = { "f", "o", "o" }, - opts = {}, - }, - -- the follow two sources have additional options - { - "blink.cmp.sources.path", - opts = { - trailing_slash = false, - label_trailing_slash = true, - get_cwd = function(context) - return vim.fn.expand(("#%d:p:h"):format(context.bufnr)) - end, - show_hidden_files_by_default = true, - }, - }, - { - "blink.cmp.sources.snippets", - score_offset = -3, - -- similar to https://github.com/garymjr/nvim-snippets - opts = { - friendly_snippets = true, - search_paths = { vim.fn.stdpath("config") .. "/snippets" }, - global_snippets = { "all" }, - extended_filetypes = {}, - ignored_filetypes = {}, - }, - }, - }, - { { "blink.cmp.sources.buffer" } }, - }, - }, + -- set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- adjusts spacing to ensure icons are aligned + nerd_font_variant = "normal", - windows = { - autocomplete = { - min_width = 30, - max_width = 60, - max_height = 10, - border = "none", - winhighlight = "Normal:BlinkCmpMenu,FloatBorder:BlinkCmpMenuBorder,CursorLine:BlinkCmpMenuSelection,Search:None", - -- keep the cursor X lines away from the top/bottom of the window - scrolloff = 2, - -- which directions to show the window, - -- falling back to the next direction when there's not enough space - direction_priority = { "s", "n" }, - -- whether to preselect the first item in the completion list - preselect = true, - -- Controls how the completion items are rendered on the popup window - -- 'simple' will render the item's kind icon the left alongside the label - -- 'reversed' will render the label on the left and the kind icon + name on the right - -- 'function(blink.cmp.CompletionRenderContext): blink.cmp.Component[]' for custom rendering - draw = "simple", - -- Controls the cycling behavior when reaching the beginning or end of the completion list. - cycle = { - -- When `true`, calling `select_next` at the *bottom* of the completion list will select the *first* completion item. - from_bottom = true, - -- When `true`, calling `select_prev` at the *top* of the completion list will select the *last* completion item. - from_top = true, - }, - }, - documentation = { - min_width = 10, - max_width = 60, - max_height = 20, - border = "padded", - winhighlight = "Normal:BlinkCmpDoc,FloatBorder:BlinkCmpDocBorder,CursorLine:BlinkCmpDocCursorLine,Search:None", - -- which directions to show the documentation window, - -- for each of the possible autocomplete window directions, - -- falling back to the next direction when there's not enough space - direction_priority = { - autocomplete_north = { "e", "w", "n", "s" }, - autocomplete_south = { "e", "w", "s", "n" }, - }, - auto_show = true, - auto_show_delay_ms = 500, - update_delay_ms = 100, - }, - signature_help = { - min_width = 1, - max_width = 100, - max_height = 10, - border = "padded", - winhighlight = "Normal:BlinkCmpSignatureHelp,FloatBorder:BlinkCmpSignatureHelpBorder", - }, - }, + kind_icons = { + Text = "󰉿", + Method = "󰊕", + Function = "󰊕", + Constructor = "󰒓", - highlight = { - ns = vim.api.nvim_create_namespace("blink_cmp"), - -- sets the fallback highlight groups to nvim-cmp's highlight groups - -- useful for when your theme doesn't support blink.cmp - -- will be removed in a future release, assuming themes add support - use_nvim_cmp_as_default = false, - }, + Field = "󰜢", + Variable = "󰆦", + Property = "󰖷", - -- set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font' - -- adjusts spacing to ensure icons are aligned - nerd_font_variant = "normal", + Class = "󱡠", + Interface = "󱡠", + Struct = "󱡠", + Module = "󰅩", - kind_icons = { - Text = "󰉿", - Method = "󰊕", - Function = "󰊕", - Constructor = "󰒓", + Unit = "󰪚", + Value = "󰦨", + Enum = "󰦨", + EnumMember = "󰦨", - Field = "󰜢", - Variable = "󰆦", - Property = "󰖷", + Keyword = "󰻾", + Constant = "󰏿", - Class = "󱡠", - Interface = "󱡠", - Struct = "󱡠", - Module = "󰅩", - - Unit = "󰪚", - Value = "󰦨", - Enum = "󰦨", - EnumMember = "󰦨", - - Keyword = "󰻾", - Constant = "󰏿", - - Snippet = "󱄽", - Color = "󰏘", - File = "󰈔", - Reference = "󰬲", - Folder = "󰉋", - Event = "󱐋", - Operator = "󰪚", - TypeParameter = "󰬛", - }, - }) - end, + Snippet = "󱄽", + Color = "󰏘", + File = "󰈔", + Reference = "󰬲", + Folder = "󰉋", + Event = "󱐋", + Operator = "󰪚", + TypeParameter = "󰬛", + }, + }) + end, } diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua new file mode 100644 index 0000000..a93f66d --- /dev/null +++ b/lua/plugins/conform.lua @@ -0,0 +1,34 @@ +return { + "conform.nvim", + event = "BufWritePre", + cmd = "ConformInfo", + after = function() + require("conform").setup({ + format_on_save = function(bufnr) + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then + return + end + + return { timeout_ms = 500, lsp_fallback = true } + end, + default_format_opts = { + lsp_format = "fallback", + }, + formatters_by_ft = { + lua = { "stylua" }, + python = { "black" }, + rust = { "rustfmt" }, + javascript = { "prettierd", "prettier", stop_after_first = true }, + typescript = { "prettierd", "prettier", stop_after_first = true }, + nix = { "nixfmt" }, + haskell = { "fourmolu", "ormolu", stop_after_first = true }, + json = { "prettierd", "prettier", stop_after_first = true }, + toml = { "taplo", stop_after_first = true }, + yaml = { "prettierd", "prettier", stop_after_first = true }, + typst = { "typstyle" }, + }, + }) + + vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" + end, +} diff --git a/lua/plugins/harpoon.lua b/lua/plugins/harpoon.lua index 1d06535..b2efbd3 100644 --- a/lua/plugins/harpoon.lua +++ b/lua/plugins/harpoon.lua @@ -1,45 +1,45 @@ return { - "harpoon2", - after = function() - local harpoon = require("harpoon") + "harpoon2", + after = function() + local harpoon = require("harpoon") - vim.keymap.set("n", "a", function() - harpoon:list():add() - end) - vim.keymap.set("n", "", function() - harpoon:list():select(1) - end) - vim.keymap.set("n", "", function() - harpoon:list():select(2) - end) - vim.keymap.set("n", "", function() - harpoon:list():select(3) - end) - vim.keymap.set("n", "", function() - harpoon:list():select(4) - end) + vim.keymap.set("n", "a", function() + harpoon:list():add() + end) + vim.keymap.set("n", "", function() + harpoon:list():select(1) + end) + vim.keymap.set("n", "", function() + harpoon:list():select(2) + end) + vim.keymap.set("n", "", function() + harpoon:list():select(3) + end) + vim.keymap.set("n", "", function() + harpoon:list():select(4) + end) - local conf = require("telescope.config").values - local function toggle_telescope(harpoon_files) - local file_paths = {} - for _, item in ipairs(harpoon_files.items) do - table.insert(file_paths, item.value) - end + local conf = require("telescope.config").values + local function toggle_telescope(harpoon_files) + local file_paths = {} + for _, item in ipairs(harpoon_files.items) do + table.insert(file_paths, item.value) + end - require("telescope.pickers") - .new({}, { - prompt_title = "Harpoon", - finder = require("telescope.finders").new_table({ - results = file_paths, - }), - previewer = conf.file_previewer({}), - sorter = conf.generic_sorter({}), - }) - :find() - end + require("telescope.pickers") + .new({}, { + prompt_title = "Harpoon", + finder = require("telescope.finders").new_table({ + results = file_paths, + }), + previewer = conf.file_previewer({}), + sorter = conf.generic_sorter({}), + }) + :find() + end - vim.keymap.set("n", "", function() - toggle_telescope(harpoon:list()) - end, { desc = "Open harpoon window" }) - end, - } + vim.keymap.set("n", "", function() + toggle_telescope(harpoon:list()) + end, { desc = "Open harpoon window" }) + end, +} diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua index ffee655..80ad1b0 100644 --- a/lua/plugins/lualine.lua +++ b/lua/plugins/lualine.lua @@ -1,58 +1,57 @@ return { - "lualine.nvim", - event = "BufEnter", - after = function() - require("lualine").setup({ - options = { - icons_enabled = true, - theme = "auto", - component_separators = { left = "", right = "" }, - section_separators = { left = "", right = "" }, - disabled_filetypes = { - statusline = { "ministarter" }, - winbar = {}, - }, - ignore_focus = {}, - always_divide_middle = true, - globalstatus = true, - refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, - }, - }, - sections = { - lualine_a = { "branch" }, - lualine_b = { - function() - return require("lsp-progress").progress() - end, - }, - lualine_c = { "progress", "filetype" }, - lualine_x = { "encoding", "fileformat" }, - lualine_y = { "diff", "diagnostics" }, - lualine_z = { "location" }, - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = { "filename" }, - lualine_x = { "location" }, - lualine_y = {}, - lualine_z = {}, - }, - tabline = {}, - winbar = {}, - inactive_winbar = {}, - extensions = {}, - }) --- listen lsp-progress event and refresh lualine -vim.api.nvim_create_augroup("lualine_augroup", { clear = true }) -vim.api.nvim_create_autocmd("User", { - group = "lualine_augroup", - pattern = "LspProgressStatusUpdated", - callback = require("lualine").refresh, -}) - end, - + "lualine.nvim", + event = "BufEnter", + after = function() + require("lualine").setup({ + options = { + icons_enabled = true, + theme = "auto", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + disabled_filetypes = { + statusline = { "ministarter" }, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = true, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + }, + }, + sections = { + lualine_a = { "branch" }, + lualine_b = { + function() + return require("lsp-progress").progress() + end, + }, + lualine_c = { "progress", "filetype" }, + lualine_x = { "encoding", "fileformat" }, + lualine_y = { "diff", "diagnostics" }, + lualine_z = { "location" }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {}, + }) + -- listen lsp-progress event and refresh lualine + vim.api.nvim_create_augroup("lualine_augroup", { clear = true }) + vim.api.nvim_create_autocmd("User", { + group = "lualine_augroup", + pattern = "LspProgressStatusUpdated", + callback = require("lualine").refresh, + }) + end, } diff --git a/lua/plugins/lz-spec.lua b/lua/plugins/lz-spec.lua index b6a3860..7f193a3 100644 --- a/lua/plugins/lz-spec.lua +++ b/lua/plugins/lz-spec.lua @@ -1,192 +1,190 @@ return { - require("plugins.blink-cmp"), - require("plugins.telescope"), - require("plugins.oil"), - require("plugins.harpoon"), - require("plugins.lualine"), - { "lsp-progress", - after = function() - require("lsp-progress").setup({ - client_format = function(client_name, spinner, series_messages) - if #series_messages == 0 then - return nil - end - return { - name = client_name, - body = spinner .. " " .. table.concat(series_messages, ", "), - } - end, - format = function(client_messages) - --- @param name string - --- @param msg string? - --- @return string - local function stringify(name, msg) - return msg and string.format("%s %s", name, msg) or name - end + require("plugins.blink-cmp"), + require("plugins.telescope"), + require("plugins.oil"), + require("plugins.harpoon"), + require("plugins.lualine"), + require("plugins.conform"), + { + "lsp-progress", + after = function() + require("lsp-progress").setup({ + client_format = function(client_name, spinner, series_messages) + if #series_messages == 0 then + return nil + end + return { + name = client_name, + body = spinner .. " " .. table.concat(series_messages, ", "), + } + end, + format = function(client_messages) + --- @param name string + --- @param msg string? + --- @return string + local function stringify(name, msg) + return msg and string.format("%s %s", name, msg) or name + end - local sign = "󰆧" -- nf-fa-gear \uf013 - local lsp_clients = vim.lsp.get_clients() - local messages_map = {} - for _, climsg in ipairs(client_messages) do - messages_map[climsg.name] = climsg.body - end + local sign = "󰆧" -- nf-fa-gear \uf013 + local lsp_clients = vim.lsp.get_clients() + local messages_map = {} + for _, climsg in ipairs(client_messages) do + messages_map[climsg.name] = climsg.body + end - if #lsp_clients > 0 then - table.sort(lsp_clients, function(a, b) - return a.name < b.name - end) - local builder = {} - for _, cli in ipairs(lsp_clients) do - if - type(cli) == "table" - and type(cli.name) == "string" - and string.len(cli.name) > 0 - then - if messages_map[cli.name] then - table.insert(builder, stringify(cli.name, messages_map[cli.name])) - else - table.insert(builder, stringify(cli.name)) + if #lsp_clients > 0 then + table.sort(lsp_clients, function(a, b) + return a.name < b.name + end) + local builder = {} + for _, cli in ipairs(lsp_clients) do + if type(cli) == "table" and type(cli.name) == "string" and string.len(cli.name) > 0 then + if messages_map[cli.name] then + table.insert(builder, stringify(cli.name, messages_map[cli.name])) + else + table.insert(builder, stringify(cli.name)) + end end end + if #builder > 0 then + return sign .. " " .. table.concat(builder, ", ") + end end - if #builder > 0 then - return sign .. " " .. table.concat(builder, ", ") - end - end - return "" - end, - }) - end - }, - { "telescope-ui-select.nvim", priority = 70 }, - { - "nvim-autopairs", - event = "BufEnter", - after = function() - require("nvim-autopairs").setup() + return "" end, - }, - { - "nvim-lspconfig", - event = "BufEnter", - after = function() - require("lsp") - end, - }, - { - "sleuth", - event = "BufEnter", - }, - { - "which-key.nvim", - after = function() - require("which-key").setup({ - delay = 1000, - }) - end, - }, - { "nvim-web-devicons" }, - { "rose-pine" }, - { "render-markdown.nvim" }, - { "markdown-preview.nvim" }, - { - "trouble.nvim", - event = "LspAttach", - after = function() - require("trouble").setup() - vim.keymap.set("n", "xx", function() - vim.cmd("Trouble diagnostics toggle") - end, { desc = "Diagnostics" }) - vim.keymap.set("n", "xX", function() - vim.cmd("Trouble diagnostics toggle filter.buf=0") - end, { desc = "Buffer diagnostics" }) - vim.keymap.set("n", "cs", function() - vim.cmd("Trouble symbols toggle") - end, { desc = "Symbols" }) - vim.keymap.set("n", "cl", function() - vim.cmd("Trouble lsp toggle win.position=right") - end, { desc = "LSP definitions / references /..." }) - vim.keymap.set("n", "ql", function() - vim.cmd("Trouble qflist toggle") - end, { desc = "Quickfix list (trouble)" }) - end, - }, - { - "typst-preview", - after = function() - require("typst-preview").setup({ - dependencies_bin = { - ["typst-preview"] = nixCats("bin.tinymist"), - ["websocat"] = nixCats("bin.websocat"), - }, - }) - end, - }, - { - "toggleterm.nvim", - after = function() - require("toggleterm").setup({ - shade_terminals = false, - }) + }) + end, + }, + { "telescope-ui-select.nvim", priority = 70 }, + { + "nvim-autopairs", + event = "BufEnter", + after = function() + require("nvim-autopairs").setup() + end, + }, + { + "nvim-lspconfig", + event = "BufEnter", + after = function() + require("lsp") + end, + }, + { + "sleuth", + event = "BufEnter", + }, + { + "which-key.nvim", + after = function() + require("which-key").setup({ + delay = 1000, + }) + end, + }, + { "nvim-web-devicons" }, + { "rose-pine" }, + { "render-markdown.nvim" }, + { "markdown-preview.nvim" }, + { + "trouble.nvim", + event = "LspAttach", + after = function() + require("trouble").setup() + vim.keymap.set("n", "xx", function() + vim.cmd("Trouble diagnostics toggle") + end, { desc = "Diagnostics" }) + vim.keymap.set("n", "xX", function() + vim.cmd("Trouble diagnostics toggle filter.buf=0") + end, { desc = "Buffer diagnostics" }) + vim.keymap.set("n", "cs", function() + vim.cmd("Trouble symbols toggle") + end, { desc = "Symbols" }) + vim.keymap.set("n", "cl", function() + vim.cmd("Trouble lsp toggle win.position=right") + end, { desc = "LSP definitions / references /..." }) + vim.keymap.set("n", "ql", function() + vim.cmd("Trouble qflist toggle") + end, { desc = "Quickfix list (trouble)" }) + end, + }, + { + "typst-preview", + after = function() + require("typst-preview").setup({ + dependencies_bin = { + ["typst-preview"] = nixCats("bin.tinymist"), + ["websocat"] = nixCats("bin.websocat"), + }, + }) + end, + }, + { + "toggleterm.nvim", + after = function() + require("toggleterm").setup({ + shade_terminals = false, + }) - vim.keymap.set({ "n", "t", "v" }, "", function() - vim.cmd("ToggleTerm direction=float") - end) - vim.keymap.set("n", "tv", function() - vim.cmd("ToggleTerm direction=vertical") - end) - vim.keymap.set("n", "tt", function() - vim.cmd("ToggleTerm direction=horizontal") - end) - vim.keymap.set("n", "ts", function() - vim.cmd("TermSelect") - end) - end, - }, - { - "mini.ai", - event = "BufEnter", - after = function() - require("mini.ai").setup() - end - }, - { - "mini.surround", - event = "BufEnter", - after = function() - require("mini.surround").setup() - end - }, - { - "mini.starter", - after = function () - require("mini.starter").setup() - end - }, - { - "mini.notify", - event = "BufEnter", - after = function () - require("mini.notify").setup({ - lsp_progress = { enable = false } - }) - end - }, - { - "mini.trailspace", - event = "BufEnter", - after = function () - require("mini.trailspace").setup() - end - }, - { - "cellular-automaton.nvim", - cmd = "CellularAutomaton", - }, - { - "indent-blankline.nvim", - after = function () - require("ibl").setup({ + vim.keymap.set({ "n", "t", "v" }, "", function() + vim.cmd("ToggleTerm direction=float") + end) + vim.keymap.set("n", "tv", function() + vim.cmd("ToggleTerm direction=vertical") + end) + vim.keymap.set("n", "tt", function() + vim.cmd("ToggleTerm direction=horizontal") + end) + vim.keymap.set("n", "ts", function() + vim.cmd("TermSelect") + end) + end, + }, + { + "mini.ai", + event = "BufEnter", + after = function() + require("mini.ai").setup() + end, + }, + { + "mini.surround", + event = "BufEnter", + after = function() + require("mini.surround").setup() + end, + }, + { + "mini.starter", + after = function() + require("mini.starter").setup() + end, + }, + { + "mini.notify", + event = "BufEnter", + after = function() + require("mini.notify").setup({ + lsp_progress = { enable = false }, + }) + end, + }, + { + "mini.trailspace", + event = "BufEnter", + after = function() + require("mini.trailspace").setup() + end, + }, + { + "cellular-automaton.nvim", + cmd = "CellularAutomaton", + }, + { + "indent-blankline.nvim", + after = function() + require("ibl").setup({ indent = { char = "│", tab_char = "│", @@ -201,127 +199,134 @@ return { "toggleterm", }, }, - } - ) - end - }, - { - "mini.bufremove", - event = "BufEnter", - after = function () - require("mini.bufremove").setup() + }) + end, + }, + { + "mini.bufremove", + event = "BufEnter", + after = function() + require("mini.bufremove").setup() - vim.keymap.set({"n", "v"}, "bd", function () - MiniBufremove.delete() - end) - end - }, - { - "mini.hipatterns", - event = "BufEnter", - after = function () - require("mini.hipatterns").setup() - end - }, - { - "gitsigns.nvim", - event = "BufEnter", - after = function () - require('gitsigns').setup{ - on_attach = function(bufnr) - local gitsigns = require('gitsigns') + vim.keymap.set({ "n", "v" }, "bd", function() + MiniBufremove.delete() + end) + end, + }, + { + "mini.hipatterns", + event = "BufEnter", + after = function() + require("mini.hipatterns").setup() + end, + }, + { + "gitsigns.nvim", + event = "BufEnter", + after = function() + require("gitsigns").setup({ + 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 + 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) + -- 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) + map("n", "[c", function() + if vim.wo.diff then + vim.cmd.normal({ "[c", bang = true }) + else + gitsigns.nav_hunk("prev") + end + end) - -- Actions - map('n', 'gs', gitsigns.stage_hunk) - map('n', 'gr', gitsigns.reset_hunk) - map('v', 'gs', function() gitsigns.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end) - map('v', 'gr', function() gitsigns.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end) - map('n', 'gS', gitsigns.stage_buffer) - map('n', 'gu', gitsigns.undo_stage_hunk) - map('n', 'gR', gitsigns.reset_buffer) - map('n', 'gp', gitsigns.preview_hunk) - map('n', 'gb', function() gitsigns.blame_line{full=true} end) - map('n', 'gb', gitsigns.toggle_current_line_blame) - map('n', 'gd', gitsigns.diffthis) - map('n', 'gD', function() gitsigns.diffthis('~') end) - map('n', 'gtd', gitsigns.toggle_deleted) + -- Actions + map("n", "gs", gitsigns.stage_hunk) + map("n", "gr", gitsigns.reset_hunk) + map("v", "gs", function() + gitsigns.stage_hunk({ vim.fn.line("."), vim.fn.line("v") }) + end) + map("v", "gr", function() + gitsigns.reset_hunk({ vim.fn.line("."), vim.fn.line("v") }) + end) + map("n", "gS", gitsigns.stage_buffer) + map("n", "gu", gitsigns.undo_stage_hunk) + map("n", "gR", gitsigns.reset_buffer) + map("n", "gp", gitsigns.preview_hunk) + map("n", "gb", function() + gitsigns.blame_line({ full = true }) + end) + map("n", "gb", gitsigns.toggle_current_line_blame) + map("n", "gd", gitsigns.diffthis) + map("n", "gD", function() + gitsigns.diffthis("~") + end) + map("n", "gtd", gitsigns.toggle_deleted) - -- Text object - map({'o', 'x'}, 'ih', ':Gitsigns select_hunk') - end + -- Text object + map({ "o", "x" }, "ih", ":Gitsigns select_hunk") + end, + }) + end, + }, + { + "neogit", + cmd = "Neogit", + after = function() + require("neogit").setup({ + graph_style = "unicode", + integrations = { + telescope = true, + diffview = true, + }, + }) + end, + }, + { + "diffiew.nvim", + cmd = { "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles", "DiffviewRefresh" }, + }, + { + "barbecue.nvim", + event = "BufEnter", + after = function() + require("barbecue").setup() + -- triggers CursorHold event faster + vim.opt.updatetime = 200 + + require("barbecue").setup({ + create_autocmd = false, -- prevent barbecue from updating itself automatically + }) + + vim.api.nvim_create_autocmd({ + "WinResized", + "BufWinEnter", + "CursorHold", + "InsertLeave", + + -- include this if you have set `show_modified` to `true` + "BufModifiedSet", + }, { + group = vim.api.nvim_create_augroup("barbecue.updater", {}), + callback = function() + require("barbecue.ui").update() + end, + }) + end, + }, + { + "undotree", + cmd = "UndotreeToggle", + }, } - end - }, - { - "neogit", - cmd = "Neogit", - after = function () - require("neogit").setup({ - graph_style = "unicode", - integrations = { - telescope = true, - diffview = true - } - }) - end - }, - { - "diffiew.nvim", - cmd = {"DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles", "DiffviewRefresh"}, - }, - { - "barbecue.nvim", - event = "BufEnter", - after = function() - require("barbecue").setup() - -- triggers CursorHold event faster - vim.opt.updatetime = 200 - - require("barbecue").setup({ - create_autocmd = false, -- prevent barbecue from updating itself automatically - }) - - vim.api.nvim_create_autocmd({ - "WinResized", - "BufWinEnter", - "CursorHold", - "InsertLeave", - - -- include this if you have set `show_modified` to `true` - "BufModifiedSet", - }, { - group = vim.api.nvim_create_augroup("barbecue.updater", {}), - callback = function() - require("barbecue.ui").update() - end, - }) - end - }, - { - "undotree", - cmd = "UndotreeToggle" - } - } diff --git a/lua/plugins/oil.lua b/lua/plugins/oil.lua index 8e3fde4..d85d03f 100644 --- a/lua/plugins/oil.lua +++ b/lua/plugins/oil.lua @@ -1,39 +1,39 @@ return { - "oil.nvim", - after = function() - require("oil").setup({ - columns = { - "size", - "icon", - }, - use_default_keymaps = false, - keymaps = { - ["J"] = "actions.parent", - ["Q"] = "actions.close", - [""] = "actions.select_split", - [""] = "actions.refresh", - [""] = "actions.preview", - [""] = "actions.select_vsplit", - [""] = "actions.select_tab", - [""] = "actions.select", - ["K"] = "actions.select", - ["_"] = "actions.open_cwd", - ["`"] = "actions.cd", - ["g."] = "actions.toggle_hidden", - ["g?"] = "actions.show_help", - ["g\\"] = "actions.toggle_trash", - ["gs"] = "actions.change_sort", - ["gx"] = "actions.open_external", - ["~"] = "actions.tcd", - }, - }) + "oil.nvim", + after = function() + require("oil").setup({ + columns = { + "size", + "icon", + }, + use_default_keymaps = false, + keymaps = { + ["J"] = "actions.parent", + ["Q"] = "actions.close", + [""] = "actions.select_split", + [""] = "actions.refresh", + [""] = "actions.preview", + [""] = "actions.select_vsplit", + [""] = "actions.select_tab", + [""] = "actions.select", + ["K"] = "actions.select", + ["_"] = "actions.open_cwd", + ["`"] = "actions.cd", + ["g."] = "actions.toggle_hidden", + ["g?"] = "actions.show_help", + ["g\\"] = "actions.toggle_trash", + ["gs"] = "actions.change_sort", + ["gx"] = "actions.open_external", + ["~"] = "actions.tcd", + }, + }) - vim.keymap.set("n", "e", function() - vim.cmd("Oil") - end, { desc = "Open file explorer in current file directory" }) + vim.keymap.set("n", "e", function() + vim.cmd("Oil") + end, { desc = "Open file explorer in current file directory" }) - vim.keymap.set("n", "fe", function() - vim.cmd("Oil " .. vim.fn.getcwd()) - end, { desc = "Open file explorer in current working directory" }) - end, + vim.keymap.set("n", "fe", function() + vim.cmd("Oil " .. vim.fn.getcwd()) + end, { desc = "Open file explorer in current working directory" }) + end, } diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index ce69eb4..89af384 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -1,36 +1,41 @@ return { - "telescope.nvim", - after = function() - require("telescope").setup({ - extensions = { - ["ui-select"] = { - require("telescope.themes").get_dropdown({}), - }, - }, - }) + "telescope.nvim", + after = function() + require("telescope").setup({ + extensions = { + ["ui-select"] = { + require("telescope.themes").get_dropdown({}), + }, + }, + }) - require("telescope").load_extension("ui-select") + require("telescope").load_extension("ui-select") - local builtin = require("telescope.builtin") + local builtin = require("telescope.builtin") - vim.keymap.set("n", " ", function() - local is_git = vim.fn.finddir(".git", vim.fn.getcwd() .. ";") - if is_git then - builtin.git_files() - else - builtin.find_files() - end - end, { desc = "Grep through all files tracked by git, or fall back to just cwd" }) + vim.keymap.set("n", " ", function() + local is_git = vim.fn.finddir(".git", vim.fn.getcwd() .. ";") + if is_git then + builtin.git_files() + else + builtin.find_files() + end + end, { desc = "Grep through all files tracked by git, or fall back to just cwd" }) - vim.keymap.set("n", "ff", builtin.find_files, { desc = "Grep through all files in cwd" }) - vim.keymap.set("n", "ca", vim.lsp.buf.code_action) - vim.keymap.set("n", "/", builtin.live_grep) - vim.keymap.set("n", "k", builtin.buffers) - vim.keymap.set("n", "gd", builtin.lsp_definitions, { desc = "Go to LSP definition" }) - vim.keymap.set("n", "gi", builtin.lsp_implementations, { desc = "Go to implementations" }) - vim.keymap.set("n", "j", builtin.lsp_document_symbols, { desc = "Search through document symbols" }) - vim.keymap.set("n", "fs", builtin.lsp_workspace_symbols, { desc = "Search through entire workspace symbols" }) - vim.keymap.set("n", "fd", builtin.diagnostics, { desc = "Search through LSP diagnostics" }) - end, - priority = 60 + vim.keymap.set("n", "ff", builtin.find_files, { desc = "Grep through all files in cwd" }) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action) + vim.keymap.set("n", "/", builtin.live_grep) + vim.keymap.set("n", "k", builtin.buffers) + vim.keymap.set("n", "gd", builtin.lsp_definitions, { desc = "Go to LSP definition" }) + vim.keymap.set("n", "gi", builtin.lsp_implementations, { desc = "Go to implementations" }) + vim.keymap.set("n", "j", builtin.lsp_document_symbols, { desc = "Search through document symbols" }) + vim.keymap.set( + "n", + "fs", + builtin.lsp_workspace_symbols, + { desc = "Search through entire workspace symbols" } + ) + vim.keymap.set("n", "fd", builtin.diagnostics, { desc = "Search through LSP diagnostics" }) + end, + priority = 60, }