scorpio 1 năm trước cách đây
mục cha
commit
88c9579d7b
6 tập tin đã thay đổi với 168 bổ sung16 xóa
  1. 2 0
      init.lua
  2. 76 16
      lua/autocmd.lua
  3. 20 0
      lua/plugin-config/fidget.lua
  4. 11 0
      lua/plugin-config/nvim-notify.lua
  5. 7 0
      lua/plugins.lua
  6. 52 0
      lua/util/im-select.lua

+ 2 - 0
init.lua

@@ -9,6 +9,7 @@ require("colorscheme")
 -- 自动命令
 require("autocmd")
 require("ui")
+require("util.im-select")
 -- 插件配置
 require("plugin-config.lualine")
 require("plugin-config.nvim-tree")
@@ -20,6 +21,7 @@ require("plugin-config.null-ls")
 require("plugin-config.gitsigns")
 require("plugin-config.eslint")
 require("plugin-config.indent-blankline")
+require("plugin-config.nvim-notify")
 -- 内置LSP (新增)
 require("lsp.setup")
 require("lsp.config.mason")

+ 76 - 16
lua/autocmd.lua

@@ -1,17 +1,77 @@
 local myAutoGroup = vim.api.nvim_create_augroup("myAutoGroup", {
-    clear = true,
-  })
-  
-  local autocmd = vim.api.nvim_create_autocmd
-
-  -- 修改lua/plugins.lua 自动更新插件
-  autocmd("BufWritePost", {
-    group = myAutoGroup,
-    -- autocmd BufWritePost plugins.lua source <afile> | PackerSync
-    callback = function()
-      if vim.fn.expand("<afile>") == "lua/plugins.lua" then
-        vim.api.nvim_command("source lua/plugins.lua")
-        vim.api.nvim_command("PackerSync")
-      end
-    end,
-  })
+  clear = true,
+})
+
+local autocmd = vim.api.nvim_create_autocmd
+
+-- 自动切换输入法,需要安装 im-select
+-- https://github.com/daipeihust/im-select
+-- autocmd("InsertLeave", {
+--   group = myAutoGroup,
+--   callback = require("utils.im-select").insertLeave,
+-- })
+-- autocmd("InsertEnter", {
+--   group = myAutoGroup,
+--   callback = require("utils.im-select").insertEnter,
+-- })
+
+-- 进入Terminal 自动进入插入模式
+autocmd("TermOpen", {
+  group = myAutoGroup,
+  command = "startinsert",
+})
+
+-- 保存时自动格式化
+autocmd("BufWritePre", {
+  group = myAutoGroup,
+  pattern = { "*.lua", "*.py", "*.sh" },
+  callback = function()
+    vim.lsp.buf.format()
+  end,
+})
+
+-- 修改lua/plugins.lua 自动更新插件
+autocmd("BufWritePost", {
+  group = myAutoGroup,
+  -- autocmd BufWritePost plugins.lua source <afile> | PackerSync
+  callback = function()
+    if vim.fn.expand("<afile>") == "lua/plugins.lua" then
+      vim.api.nvim_command("source lua/plugins.lua")
+      vim.api.nvim_command("PackerSync")
+    end
+  end,
+})
+
+-- Highlight on yank
+autocmd("TextYankPost", {
+  callback = function()
+    vim.highlight.on_yank()
+  end,
+  group = myAutoGroup,
+  pattern = "*",
+})
+
+-- 用o换行不要延续注释
+autocmd("BufEnter", {
+  group = myAutoGroup,
+  pattern = "*",
+  callback = function()
+    vim.opt.formatoptions = vim.opt.formatoptions
+      - "o" -- O and o, don't continue comments
+      + "r" -- But do continue when pressing enter.
+  end,
+})
+
+-- 保存Fold
+local saveable_type = { "*.lua", "*.js", "*.jsx", "*.ts", "*.tsx" }
+
+autocmd("BufWinEnter", {
+  group = myAutoGroup,
+  pattern = saveable_type,
+  command = "silent! loadview",
+})
+autocmd("BufWrite", {
+  group = myAutoGroup,
+  pattern = saveable_type,
+  command = "mkview",
+})

+ 20 - 0
lua/plugin-config/fidget.lua

@@ -0,0 +1,20 @@
+
+local status, fidget = pcall(require, "fidget")
+if not status then
+  vim.notify("没有找到 fidget")
+  return
+end
+
+fidget.setup({
+  text = {
+    spinner = "zip", -- animation shown when tasks are ongoing
+    done = "✔", -- character shown when all tasks are complete
+    commenced = "Started", -- message shown when task starts
+    completed = "Completed", -- message shown when task completes
+  },
+  sources = {
+    ["null-ls"] = {
+      ignore = true,
+    },
+  },
+})

+ 11 - 0
lua/plugin-config/nvim-notify.lua

@@ -0,0 +1,11 @@
+local status, notify = pcall(require, "notify")
+if not status then
+  vim.notify("没有找到 nvim-notify")
+  return
+end
+
+notify.setup({
+  stages = "static",
+  timeout = 5000,
+})
+vim.notify = notify

+ 7 - 0
lua/plugins.lua

@@ -173,6 +173,13 @@ packer.startup({
           end,
         })
 
+       -- fidget.nvim
+        use({
+          "j-hui/fidget.nvim",
+          config = function()
+            require("plugin-config.fidget")
+          end,
+        })
     end,
     config = {
         -- 并发数限制

+ 52 - 0
lua/util/im-select.lua

@@ -0,0 +1,52 @@
+local M = {}
+
+M.defaultIM = "com.apple.keylayout.ABC"
+M.currentIM = M.defaultIM
+
+local macInsertEnter = function()
+  if M.currentIM then
+    vim.cmd(":silent :!im-select" .. " " .. M.currentIM)
+  else
+    vim.cmd(":silent :!im-select" .. " " .. M.defaultIM)
+  end
+end
+
+local macInsertLeave = function()
+  M.currentIM = vim.fn.system({ "im-select" })
+  vim.cmd(":silent :!im-select" .. " " .. M.defaultIM)
+end
+
+local windowsInsertLeave = function()
+  vim.cmd(":silent :!~/.config/nvim/im-select.exe 1033")
+end
+
+local windowsInsertEnter = function()
+  vim.cmd(":silent :!~/.config/nvim/im-select.exe 2052")
+end
+
+M.insertEnter = function()
+  if vim.fn.executable("im-select") ~= 1 and vim.fn.executable("im-select.exe") ~= 1 then
+    vim.notify("没有找到 im-select 无法切换输入法, https://github.com/daipeihust/im-select")
+    return
+  end
+
+  if vim.fn.has("macunix") == 1 then
+    macInsertEnter()
+  elseif vim.fn.has("win32") then
+    windowsInsertEnter()
+  end
+end
+
+M.insertLeave = function()
+  if vim.fn.executable("im-select") ~= 1 and vim.fn.executable("im-select.exe") ~= 1 then
+    vim.notify("没有找到 im-select 无法切换输入法, https://github.com/daipeihust/im-select")
+    return
+  end
+  if vim.fn.has("macunix") == 1 then
+    macInsertLeave()
+  elseif vim.fn.has("win32") then
+    windowsInsertLeave()
+  end
+end
+
+return M