You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

116 lines
3.4 KiB

vim.api.nvim_set_hl(0, "YankColor", { fg = "#C8C093", bg = "#000000", ctermfg = 59, ctermbg = 41 })
local aucmd_dict = {
VimEnter = {
{
callback = function()
local function find_project_root()
local current_dir = vim.fn.getcwd()
while current_dir ~= "/" do
if vim.fn.isdirectory(current_dir .. "/.git") == 1 or vim.fn.filereadable(current_dir .. "/.nvim.lua") then
return current_dir
end
current_dir = vim.fn.fnamemodify(current_dir, ":h")
end
return vim.fn.getcwd()
end
local project_root = find_project_root()
local project_specific_conf_file = project_root .. "/.nvim.lua"
if vim.fn.filereadable(project_specific_conf_file) == 1 then
vim.cmd("source " .. project_specific_conf_file)
print("Sourced project specific config file: " .. project_specific_conf_file)
end
end
}
},
FileType = {
{
-- Set tabstop to 2 for Dart, Vue, JavaScript, TypeScript, and JSON files
pattern = "html,dart,vue,javascript,typescript,typescriptreact,json,markdown,css,sass",
callback = function()
vim.opt_local.tabstop = 2
vim.opt_local.softtabstop = 2
vim.opt_local.shiftwidth = 2
end,
},
{
pattern = 'dart',
callback = function()
vim.bo.commentstring = '// %s'
end
},
},
BufWritePre = {
{
-- Remove trailing whitespace on save
command = [[%s/\s\+$//e]],
},
},
BufRead = {
{
-- Set syntax for Dockerfiles
pattern = { '*.docker' },
callback = function()
vim.opt_local.syntax = 'dockerfile'
end
},
},
BufReadPost = {
{
callback = function(event)
local exclude = { 'gitcommit', 'commit', 'gitrebase' }
local buf = event.buf
if
vim.tbl_contains(exclude, vim.bo[buf].filetype)
or vim.b[buf].lazyvim_last_loc
then
return
end
vim.b[buf].lazyvim_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,
},
},
BufNewFile = {
{
-- Set syntax for Dockerfiles
pattern = { '*.docker' },
callback = function()
vim.opt_local.syntax = 'dockerfile'
end
},
},
TextYankPost = {
{
callback = function()
vim.hl.on_yank { higroup = "YankColor", timeout = 250 }
end
},
},
VimResized = {
{
command="wincmd ="
},
},
}
for event, opt_tbls in pairs(aucmd_dict) do
for _, opt_tbl in pairs(opt_tbls) do
vim.api.nvim_create_autocmd(event, opt_tbl)
end
end