48 lines
1.0 KiB
Lua
Raw Normal View History

2023-08-19 17:22:56 +00:00
local on = vim.api.nvim_create_autocmd
2023-07-29 22:50:07 +00:00
2023-08-20 22:09:00 +00:00
on({ "TermOpen", "TermEnter" }, {
callback = function()
2023-08-23 20:59:04 +00:00
vim.opt_local.signcolumn = "no"
2023-08-20 22:09:00 +00:00
end,
})
on({ "BufNewFile", "BufRead" }, {
pattern = { "*.txt", "*.md" },
callback = function()
2023-08-22 14:51:35 +00:00
vim.opt_local.wrap = true
vim.opt_local.signcolumn = "no"
2023-08-20 22:09:00 +00:00
end,
})
2024-01-22 14:04:33 +00:00
on({ "VimEnter" }, {
callback = function()
2024-02-01 22:59:16 +00: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 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,
path = file,
})[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
vim.api.nvim_set_current_dir(file)
2024-01-22 14:04:33 +00: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,
})