Repository navigation
Expand file tree
/
Copy pathautocmds.lua
More file actions
134 lines (125 loc) · 3.24 KB
/
Copy pathautocmds.lua
File metadata and controls
134 lines (125 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
local autocmd = vim.api.nvim_create_autocmd
local function augroup(name)
return vim.api.nvim_create_augroup("kide" .. name, { clear = true })
end
-- Highlight on yank
autocmd({ "TextYankPost" }, {
group = augroup("highlight_yank"),
callback = function()
vim.hl.on_yank()
end,
})
-- https://nvchad.com/docs/recipes
autocmd("BufReadPost", {
group = augroup("restore_cursor"),
pattern = "*",
callback = function()
local line = vim.fn.line("'\"")
if
line > 1
and line <= vim.fn.line("$")
and vim.bo.filetype ~= "commit"
and vim.fn.index({ "xxd", "gitrebase" }, vim.bo.filetype) == -1
then
vim.cmd('normal! g`"')
end
end,
})
-- close some filetypes with <q>
-- 最后一个窗口时用 bd! 关掉, 否则 close
autocmd("FileType", {
group = augroup("close_with_q"),
pattern = {
"PlenaryTestPopup",
"help",
"lspinfo",
"man",
"notify",
"qf",
"spectre_panel",
"startuptime",
"tsplayground",
"checkhealth",
"fugitive",
"fugitive://*",
"git",
"dbui",
"dbout",
"httpResult",
-- dap-repl 不在这里: 下面的 dap-* 会覆盖它, 这里写了也是死配置
},
callback = function(event)
vim.bo[event.buf].buflisted = false
vim.keymap.set("n", "q", function()
if vim.fn.winnr("$") == 1 then
vim.cmd("bd!")
else
vim.cmd("close")
end
end, { buffer = event.buf, silent = true })
end,
})
autocmd("FileType", {
group = augroup("close_with_q_bd"),
pattern = {
"oil",
"DressingSelect",
"dap-*",
},
callback = function(event)
vim.keymap.set("n", "q", "<cmd>bd<cr>", { buffer = event.buf, silent = true })
end,
})
autocmd({ "BufRead", "BufNewFile" }, {
group = augroup("spell"),
pattern = "*.md",
command = "setlocal spell spelllang=en_us,cjk",
})
-- outline
autocmd("FileType", {
group = augroup("OUTLINE"),
pattern = {
"OUTLINE",
},
callback = function(_)
vim.api.nvim_set_option_value("signcolumn", "no", { win = vim.api.nvim_get_current_win() })
end,
})
-- ts-ls 同时服务这 4 个 filetype; 用一条 autocmd 代替 4 个内容相同的 ftplugin
autocmd("FileType", {
group = augroup("ts_ls"),
pattern = { "javascript", "javascriptreact", "typescript", "typescriptreact" },
callback = function()
vim.lsp.start(require("kide.lsp.ts-ls").config)
end,
})
-- LSP
local function lsp_command(bufnr)
vim.api.nvim_buf_create_user_command(bufnr, "LspIncomingCalls", vim.lsp.buf.incoming_calls, {
desc = "Lsp incoming calls",
nargs = 0,
})
vim.api.nvim_buf_create_user_command(bufnr, "LspOutgoingCalls", vim.lsp.buf.outgoing_calls, {
desc = "Lsp outgoing calls",
nargs = 0,
})
end
autocmd("LspAttach", {
group = augroup("lsp_a"),
callback = function(args)
local bufnr = args.buf
lsp_command(bufnr)
end,
})
autocmd("TermOpen", {
group = augroup("close_with_q_term"),
pattern = "*",
callback = function(event)
-- mac 下 t 模式执行 bd! dap 终端会导致 nvim 退出
-- 这里使用 n 模式下执行
if vim.b[event.buf].q_close == nil or vim.b[event.buf].q_close == true then
vim.keymap.set("n", "q", "<cmd>bd!<cr>", { buffer = event.buf, silent = true })
end
end,
})
require("kide.melspconfig").init_lsp()