1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- local myAutoGroup = vim.api.nvim_create_augroup("myAutoGroup", {
- 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",
- })
|