59 lines
1.4 KiB
Lua
Raw Normal View History

2023-08-19 17:22:56 +00:00
local on = vim.api.nvim_create_autocmd
2024-03-04 23:40:49 +00:00
local group = vim.api.nvim_create_augroup("autocmds", {clear = true})
2023-07-29 22:50:07 +00:00
2024-03-03 16:47:02 +00:00
on({ "BufNewFile", "BufRead" }, {
2024-03-04 23:40:49 +00:00
desc = "Enable word wrap in text files and markdown documents",
group = group,
2024-03-03 16:47:02 +00:00
pattern = { "*.txt", "*.md" },
2023-08-20 22:09:00 +00:00
callback = function()
2024-03-03 16:47:02 +00:00
vim.opt_local.wrap = true
2023-08-23 20:59:04 +00:00
vim.opt_local.signcolumn = "no"
2023-08-20 22:09:00 +00:00
end,
})
2024-03-03 16:47:02 +00:00
on({ "TermOpen", "TermEnter" }, {
2024-03-04 23:40:49 +00:00
desc = "Disable sign column in terminals",
group = group,
2023-08-20 22:09:00 +00:00
callback = function()
2023-08-22 14:51:35 +00:00
vim.opt_local.signcolumn = "no"
2023-08-20 22:09:00 +00:00
end,
})
2024-01-22 14:04:33 +00:00
2024-03-03 16:47:02 +00:00
on({ "TextYankPost" }, {
desc = "Highlight when copying text",
2024-03-04 23:40:49 +00:00
group = group,
2024-03-03 16:47:02 +00:00
callback = function()
vim.highlight.on_yank()
end,
})
2024-01-22 14:04:33 +00:00
on({ "VimEnter" }, {
2024-03-04 23:40:49 +00:00
desc = "Allow opening a directory and jumping to project root",
group = group,
2024-01-22 14:04:33 +00:00
callback = function()
2024-02-01 22:59:16 +00:00
-- Change file to its directory if needed
2024-03-04 23:40:49 +00:00
local name = vim.api.nvim_buf_get_name(0)
2024-03-05 12:28:48 +00:00
local is_directory = vim.fn.isdirectory(name)
2024-02-01 22:59:16 +00:00
2024-03-05 12:28:48 +00:00
if is_directory == 0 then
2024-03-04 23:40:49 +00:00
name = vim.fs.dirname(name)
2024-02-01 22:59:16 +00:00
end
2024-01-22 14:04:33 +00:00
-- Switch to root directory of the project
local root_patterns = { ".git", "go.mod", "init.lua" }
2024-02-01 22:59:16 +00:00
local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, {
upward = true,
2024-03-04 23:40:49 +00:00
path = name,
2024-02-01 22:59:16 +00:00
})[1])
2024-01-22 14:04:33 +00:00
if root_dir then
vim.api.nvim_set_current_dir(root_dir)
2024-02-01 22:59:16 +00:00
else
2024-03-04 23:40:49 +00:00
vim.api.nvim_set_current_dir(name)
2024-01-22 14:04:33 +00:00
end
2024-03-05 12:28:48 +00:00
if is_directory ~= 0 then
require("telescope.builtin").find_files()
2024-01-22 14:04:33 +00:00
end
end,
2024-06-17 14:19:21 +00:00
})