2023-08-19 19:22:56 +02:00
|
|
|
local on = vim.api.nvim_create_autocmd
|
2023-07-30 00:50:07 +02:00
|
|
|
|
2024-03-03 17:47:02 +01:00
|
|
|
on({ "BufNewFile", "BufRead" }, {
|
|
|
|
pattern = { "*.txt", "*.md" },
|
2023-08-21 00:09:00 +02:00
|
|
|
callback = function()
|
2024-03-03 17:47:02 +01:00
|
|
|
vim.opt_local.wrap = true
|
2023-08-23 22:59:04 +02:00
|
|
|
vim.opt_local.signcolumn = "no"
|
2023-08-21 00:09:00 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2024-03-03 17:47:02 +01:00
|
|
|
on({ "TermOpen", "TermEnter" }, {
|
2023-08-21 00:09:00 +02:00
|
|
|
callback = function()
|
2023-08-22 16:51:35 +02:00
|
|
|
vim.opt_local.signcolumn = "no"
|
2023-08-21 00:09:00 +02:00
|
|
|
end,
|
|
|
|
})
|
2024-01-22 15:04:33 +01:00
|
|
|
|
2024-03-03 17:47:02 +01:00
|
|
|
on({ "TextYankPost" }, {
|
|
|
|
desc = "Highlight when copying text",
|
|
|
|
group = vim.api.nvim_create_augroup("highlight-yank", { clear = true }),
|
|
|
|
callback = function()
|
|
|
|
vim.highlight.on_yank()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2024-01-22 15:04:33 +01:00
|
|
|
on({ "VimEnter" }, {
|
|
|
|
callback = function()
|
2024-02-01 23:59:16 +01:00
|
|
|
-- Change file to its directory if needed
|
|
|
|
local file = vim.api.nvim_buf_get_name(0)
|
|
|
|
|
|
|
|
if vim.fn.isdirectory(file) == 0 then
|
|
|
|
file = vim.fs.dirname(file)
|
|
|
|
end
|
|
|
|
|
2024-01-22 15:04:33 +01:00
|
|
|
-- Switch to root directory of the project
|
|
|
|
local root_patterns = { ".git", "go.mod", "init.lua" }
|
2024-02-01 23:59:16 +01:00
|
|
|
local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, {
|
|
|
|
upward = true,
|
|
|
|
path = file,
|
|
|
|
})[1])
|
2024-01-22 15:04:33 +01:00
|
|
|
|
|
|
|
if root_dir then
|
|
|
|
vim.api.nvim_set_current_dir(root_dir)
|
2024-02-01 23:59:16 +01:00
|
|
|
else
|
|
|
|
vim.api.nvim_set_current_dir(file)
|
2024-01-22 15:04:33 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Open file explorer if we have enough space
|
|
|
|
local files = require("nvim-tree.api")
|
|
|
|
local width = vim.go.columns
|
|
|
|
|
|
|
|
if width > 120 then
|
|
|
|
files.tree.toggle({ focus = false })
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|