From 78115fb3e009f79e33d4721216abaf4f9bba85ed Mon Sep 17 00:00:00 2001 From: juancwu <46619361+juancwu@users.noreply.github.com> Date: Wed, 30 Jul 2025 22:52:24 -0400 Subject: [PATCH] update bashrc.arch and nvim --- bash/.bashrc.arch | 2 +- nvim/lazy-lock.json | 1 - nvim/lua/juancwu/config/clipboard.lua | 107 +++++++++++++------------- nvim/lua/juancwu/plugins/autotag.lua | 15 ++++ nvim/lua/juancwu/plugins/closetag.lua | 3 - nvim/lua/juancwu/plugins/conform.lua | 99 ++++++------------------ nvim/lua/juancwu/plugins/lsp.lua | 2 +- 7 files changed, 94 insertions(+), 135 deletions(-) delete mode 100644 nvim/lua/juancwu/plugins/closetag.lua diff --git a/bash/.bashrc.arch b/bash/.bashrc.arch index 4d98e12..38396a2 100644 --- a/bash/.bashrc.arch +++ b/bash/.bashrc.arch @@ -234,5 +234,5 @@ ed() { } export GOPATH=$HOME/go -export PATH=$PATH:$GOPATH:$GOPATH/bin +export PATH=$PATH:$GOPATH:$GOPATH/bin:/usr/local/go/bin export EDITOR=nvim diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index f2b4119..346b186 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -45,7 +45,6 @@ "todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" }, "tokyonight.nvim": { "branch": "main", "commit": "057ef5d260c1931f1dffd0f052c685dcd14100a3" }, "undotree": { "branch": "master", "commit": "28f2f54a34baff90ea6f4a735ef1813ad875c743" }, - "vim-closetag": { "branch": "master", "commit": "d0a562f8bdb107a50595aefe53b1a690460c3822" }, "vim-floaterm": { "branch": "master", "commit": "fd4bdd66eca56c6cc59f2119e4447496d8cde2ea" }, "which-key.nvim": { "branch": "main", "commit": "370ec46f710e058c9c1646273e6b225acf47cbed" } } diff --git a/nvim/lua/juancwu/config/clipboard.lua b/nvim/lua/juancwu/config/clipboard.lua index de26aeb..c0bb3ae 100644 --- a/nvim/lua/juancwu/config/clipboard.lua +++ b/nvim/lua/juancwu/config/clipboard.lua @@ -1,59 +1,58 @@ local Utils = require("juancwu.utils") if Utils.os.is_linux() then - local wayland_display = os.getenv("WAYLAND_DISPLAY") - local clipboard_cmd = "xclip" - if wayland_display then - vim.g.clipboard = { - name = "wl-clipboard", - copy = { - ['+'] = "wl-copy", - ['*'] = "wl-copy", - }, - paste = { - ['+'] = "wl-paste", - ['*'] = "wl-paste", - }, - cache_enabled = 1, - } - else - vim.g.clipboard = { - name = "xclip", - copy = { - ['+'] = "xclip -sel clip -i -quiet", - ['*'] = "xclip -sel primary -i -quiet", - }, - paste = { - ['+'] = "xclip -sel clip -o -quiet", - ['*'] = "xclip -sel primary -o -quiet", - }, - cache_enabled = 1, - } - end + local wayland_display = os.getenv("WAYLAND_DISPLAY") + if Utils.os.is_wsl() then + vim.g.clipboard = { + name = "win32yank", + copy = { + ["+"] = "win32yank.exe -i --crlf", + ["*"] = "win32yank.exe -i --crlf", + }, + paste = { + ["+"] = "win32yank.exe -o --lf", + ["*"] = "win32yank.exe -o --lf", + }, + cache_enabled = 0, + } + elseif wayland_display then + vim.g.clipboard = { + name = "wl-clipboard", + copy = { + ["+"] = "wl-copy", + ["*"] = "wl-copy", + }, + paste = { + ["+"] = "wl-paste", + ["*"] = "wl-paste", + }, + cache_enabled = 1, + } + else + vim.g.clipboard = { + name = "xclip", + copy = { + ["+"] = "xclip -sel clip -i -quiet", + ["*"] = "xclip -sel primary -i -quiet", + }, + paste = { + ["+"] = "xclip -sel clip -o -quiet", + ["*"] = "xclip -sel primary -o -quiet", + }, + cache_enabled = 1, + } + end elseif Utils.os.is_mac() then - vim.g.clipboard = { - name = "mac-clipboard", - copy = { - ['+'] = "pbcopy", - ['*'] = "pbcopy", - }, - paste = { - ['+'] = "pbpaste", - ['*'] = "pbpaste", - }, - cache_enabled = 1, - } -elseif Utils.os.is_wsl() then - vim.g.clipboard = { - name = "win32yank", - copy = { - ['+'] = "win32yank.exe -i --crlf", - ['*'] = "win32yank.exe -i --crlf", - }, - paste = { - ['+'] = "win32yank.exe -o --lf", - ['*'] = "win32yank.exe -o --lf", - }, - cache_enabled = 0, - } + vim.g.clipboard = { + name = "mac-clipboard", + copy = { + ["+"] = "pbcopy", + ["*"] = "pbcopy", + }, + paste = { + ["+"] = "pbpaste", + ["*"] = "pbpaste", + }, + cache_enabled = 1, + } end diff --git a/nvim/lua/juancwu/plugins/autotag.lua b/nvim/lua/juancwu/plugins/autotag.lua index 1f8fcb7..92e4961 100644 --- a/nvim/lua/juancwu/plugins/autotag.lua +++ b/nvim/lua/juancwu/plugins/autotag.lua @@ -2,8 +2,23 @@ return { "windwp/nvim-ts-autotag", dependencies = { "nvim-treesitter/nvim-treesitter", build = ':TSUpdate' }, ft = { + 'html', + 'javascript', + 'typescript', 'javascriptreact', 'typescriptreact', + 'svelte', + 'vue', + 'tsx', + 'jsx', + 'xml', + 'php', + 'markdown', + 'astro', + 'glimmer', + 'handlebars', + 'hbs', + 'templ', }, config = function() local autotag = require('nvim-ts-autotag') diff --git a/nvim/lua/juancwu/plugins/closetag.lua b/nvim/lua/juancwu/plugins/closetag.lua deleted file mode 100644 index 53c62cb..0000000 --- a/nvim/lua/juancwu/plugins/closetag.lua +++ /dev/null @@ -1,3 +0,0 @@ -return { - "alvan/vim-closetag" -} diff --git a/nvim/lua/juancwu/plugins/conform.lua b/nvim/lua/juancwu/plugins/conform.lua index 7a217f2..a98e0e8 100644 --- a/nvim/lua/juancwu/plugins/conform.lua +++ b/nvim/lua/juancwu/plugins/conform.lua @@ -1,74 +1,21 @@ local formatters_by_ft = { lua = { "stylua" }, - javascript = { "prettier", "biome" }, - typescript = { "prettier", "biome" }, - javascriptreact = { "prettier", "biome" }, - typescriptreact = { "prettier", "biome" }, - css = { "prettier", "biome" }, - markdown = { "prettier", "biome" }, - jsonc = { "prettier", "biome" }, - json = { "prettier", "biome" }, - go = { "gofmt" }, + javascript = { "biome" }, + typescript = { "biome" }, + javascriptreact = { "biome" }, + typescriptreact = { "biome" }, + css = { "biome" }, + markdown = { "biome" }, + jsonc = { "biome" }, + json = { "biome" }, + go = { "gofmt", "goimports" }, python = { "autopep8" }, + yaml = { "yamlfmt" }, + yml = { "yamlfmt" }, + zig = { "zigfmt" }, + rust = { "rustfmt" }, } --- Function to find the first config file by walking up the directory tree -local function find_first_config() - local current_dir = vim.fn.expand("%:p:h") - local home_dir = vim.fn.expand("$HOME") - - local config_files = { - prettier = { ".prettierrc", ".prettierrc.json", ".prettierrc.js" }, - biome = { "biome.json" }, - } - - while current_dir ~= home_dir and current_dir ~= "/" do - for formatter, patterns in pairs(config_files) do - for _, pattern in ipairs(patterns) do - local config_file = current_dir .. "/" .. pattern - if vim.fn.filereadable(config_file) == 1 then - return formatter - end - end - end - current_dir = vim.fn.fnamemodify(current_dir, ":h") - end - return nil -end - --- Function to determine the formatter based on config files and file type -local function get_formatter() - local filetype = vim.bo.filetype - local available_formatters = formatters_by_ft[filetype] or {} - local formatter = find_first_config() - - if formatter then - if formatter == "prettier" and vim.tbl_contains(available_formatters, "prettier") then - vim.g.current_formatter = "prettier" - return { "prettier" } - elseif formatter == "biome" and vim.tbl_contains(available_formatters, "biome") then - vim.g.current_formatter = "biome" - return { "biome" } - end - end - - -- Default to the first available formatter for the file type, or prettier if none specified - vim.g.current_formatter = available_formatters[1] or "prettier" - return { vim.g.current_formatter } -end - -local function format_on_save(bufnr) - if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then - return - end - local formatters = get_formatter() - return { - timeout_ms = 500, - lsp_format = "fallback", - formatters = formatters, - } -end - return { "stevearc/conform.nvim", event = { "BufWritePre", "BufEnter" }, @@ -77,8 +24,7 @@ return { { "ff", function() - local formatters = get_formatter() - require("conform").format({ async = true, lsp_format = "fallback", formatters = formatters }) + require("conform").format({ async = true, lsp_format = "fallback" }) end, mode = "", desc = "[F]ormat buffer", @@ -88,7 +34,15 @@ return { require("conform").setup({ notify_on_error = false, formatters_by_ft = formatters_by_ft, - format_on_save = format_on_save, + format_on_save = function(bufnr) + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then + return + end + return { + timeout_ms = 500, + lsp_format = "fallback", + } + end, }) vim.api.nvim_create_user_command("FormatDisable", function() @@ -102,11 +56,6 @@ return { end, { desc = "Enable autoformat on save", }) - - vim.api.nvim_create_user_command("Formatter", function() - print("Current formatter: " .. (vim.g.current_formatter or "none")) - end, { - desc = "Show current formatter being used", - }) end, } + diff --git a/nvim/lua/juancwu/plugins/lsp.lua b/nvim/lua/juancwu/plugins/lsp.lua index 8a5096f..c12134c 100644 --- a/nvim/lua/juancwu/plugins/lsp.lua +++ b/nvim/lua/juancwu/plugins/lsp.lua @@ -138,7 +138,7 @@ return { } local ensure_installed = vim.tbl_keys(servers or {}) - vim.list_extend(ensure_installed, { "stylua", "yamlfmt", "autopep8", "biome" }) + vim.list_extend(ensure_installed, { "stylua", "yamlfmt", "autopep8", "biome", "goimports" }) require("mason-tool-installer").setup({ ensure_installed = ensure_installed }) require("mason-lspconfig").setup({