Updated config
This commit is contained in:
55
.config/nvim/lua/autocmds.lua
Normal file
55
.config/nvim/lua/autocmds.lua
Normal file
@ -0,0 +1,55 @@
|
||||
local on = vim.api.nvim_create_autocmd
|
||||
|
||||
on({ "BufNewFile", "BufRead" }, {
|
||||
pattern = { "*.txt", "*.md" },
|
||||
callback = function()
|
||||
vim.opt_local.wrap = true
|
||||
vim.opt_local.signcolumn = "no"
|
||||
end,
|
||||
})
|
||||
|
||||
on({ "TermOpen", "TermEnter" }, {
|
||||
callback = function()
|
||||
vim.opt_local.signcolumn = "no"
|
||||
end,
|
||||
})
|
||||
|
||||
on({ "TextYankPost" }, {
|
||||
desc = "Highlight when copying text",
|
||||
group = vim.api.nvim_create_augroup("highlight-yank", { clear = true }),
|
||||
callback = function()
|
||||
vim.highlight.on_yank()
|
||||
end,
|
||||
})
|
||||
|
||||
on({ "VimEnter" }, {
|
||||
callback = function()
|
||||
-- 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
|
||||
|
||||
-- Switch to root directory of the project
|
||||
local root_patterns = { ".git", "go.mod", "init.lua" }
|
||||
local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, {
|
||||
upward = true,
|
||||
path = file,
|
||||
})[1])
|
||||
|
||||
if root_dir then
|
||||
vim.api.nvim_set_current_dir(root_dir)
|
||||
else
|
||||
vim.api.nvim_set_current_dir(file)
|
||||
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,
|
||||
})
|
Reference in New Issue
Block a user