99 lines
3.5 KiB
Lua
99 lines
3.5 KiB
Lua
-- don't auto comment new line
|
|
vim.api.nvim_create_autocmd("BufEnter", { command = [[set formatoptions-=cro]] })
|
|
|
|
-- resize neovim split when terminal is resized
|
|
vim.api.nvim_command("autocmd VimResized * wincmd =")
|
|
|
|
-- enable spell for text files
|
|
vim.api.nvim_create_autocmd("FileType", {
|
|
group = vim.api.nvim_create_augroup("spell", { clear = true }),
|
|
pattern = { "gitcommit" },
|
|
callback = function()
|
|
vim.opt_local.spell = true
|
|
end,
|
|
})
|
|
|
|
-- set some colors
|
|
vim.api.nvim_create_autocmd({ "BufReadPre" }, {
|
|
callback = function()
|
|
vim.api.nvim_set_hl(0, "ColorColumn", { bg = "#770000" })
|
|
vim.api.nvim_set_hl(0, "DiffChange", { bg = "NONE", fg = "#e7c547" })
|
|
vim.api.nvim_set_hl(0, "DiffText", { bg = "NONE", fg = "#ff8700" })
|
|
vim.api.nvim_set_hl(0, "Visual", { bg = "#0094d8", fg = "#ffffff" })
|
|
end,
|
|
})
|
|
|
|
-- fix dimmed elements in Snacks.picker
|
|
vim.api.nvim_create_autocmd("User", {
|
|
pattern = "VeryLazy",
|
|
callback = function()
|
|
Snacks.util.set_hl({
|
|
PickerDir = { link = "Text" },
|
|
PickerPathHidden = { link = "Text" },
|
|
PickerPathIgnored = { link = "Comment" },
|
|
PickerGitStatusUntracked = { link = "Special" },
|
|
}, { prefix = "Snacks" })
|
|
end,
|
|
})
|
|
|
|
-- remember last location
|
|
vim.api.nvim_create_autocmd("BufReadPost", {
|
|
group = vim.api.nvim_create_augroup("last-loc", { clear = true }),
|
|
callback = function(event)
|
|
local exclude = { "gitcommit" }
|
|
local buf = event.buf
|
|
if vim.tbl_contains(exclude, vim.bo[buf].filetype) or vim.b[buf].my_last_loc then
|
|
return
|
|
end
|
|
vim.b[buf].my_last_loc = true
|
|
local mark = vim.api.nvim_buf_get_mark(buf, '"')
|
|
local lcount = vim.api.nvim_buf_line_count(buf)
|
|
if mark[1] > 0 and mark[1] <= lcount then
|
|
pcall(vim.api.nvim_win_set_cursor, 0, mark)
|
|
end
|
|
end,
|
|
})
|
|
|
|
-- lsp
|
|
vim.api.nvim_create_autocmd("LspAttach", {
|
|
group = vim.api.nvim_create_augroup("lsp-attach", { clear = true }),
|
|
callback = function(event)
|
|
local map = function(keys, func, desc)
|
|
vim.keymap.set("n", keys, func, { buffer = event.buf, desc = desc })
|
|
end
|
|
map("<leader>cd", vim.diagnostic.open_float, "diagnostic (float)")
|
|
map("<leader>ch", vim.lsp.buf.hover, "help")
|
|
map("<leader>ca", vim.lsp.buf.code_action, "actions")
|
|
map("<leader>cf", vim.lsp.buf.format, "format file")
|
|
local function client_supports_method(client, method, bufnr)
|
|
if vim.fn.has("nvim-0.11") == 1 then
|
|
return client:supports_method(method, bufnr)
|
|
else
|
|
return client.supports_method(method, { bufnr = bufnr })
|
|
end
|
|
end
|
|
local client = vim.lsp.get_client_by_id(event.data.client_id)
|
|
if
|
|
client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf)
|
|
then
|
|
local highlight_augroup = vim.api.nvim_create_augroup("lsp-highlight", { clear = false })
|
|
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
|
|
buffer = event.buf,
|
|
group = highlight_augroup,
|
|
callback = vim.lsp.buf.document_highlight,
|
|
})
|
|
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
|
|
buffer = event.buf,
|
|
group = highlight_augroup,
|
|
callback = vim.lsp.buf.clear_references,
|
|
})
|
|
vim.api.nvim_create_autocmd("LspDetach", {
|
|
group = vim.api.nvim_create_augroup("lsp-detach", { clear = true }),
|
|
callback = function(event2)
|
|
vim.lsp.buf.clear_references()
|
|
vim.api.nvim_clear_autocmds({ group = "lsp-highlight", buffer = event2.buf })
|
|
end,
|
|
})
|
|
end
|
|
end,
|
|
})
|