|
@@ -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",
|
|
|
+})
|