nvim/lua/config/maps/vue.lua
2025-10-16 11:11:00 +02:00

26 lines
723 B
Lua

-- 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", "<leader><F5>", "<CMD>! npm run format<CR>", { desc = "Prettier" })
end
end,
})