-- Function to check if pom.xml exists in current or parent directories local function is_npm_project() local uv = vim.loop local dir = uv.fs_realpath(vim.fn.expand("%:p:h")) while dir do if uv.fs_stat(dir .. "/package-lock.json") then return true end local parent_dir = uv.fs_realpath(dir .. "/..") if parent_dir == dir then break end dir = parent_dir end return false end -- Create autocommand on FileType java or whatever filetype you want vim.api.nvim_create_autocmd("FileType", { pattern = "typescript", callback = function() if is_npm_project() then vim.keymap.set("n", "", "! npm run format", { desc = "Prettier" }) end end, })