local function is_cpp_project() local uv = vim.loop local dir = uv.fs_realpath(vim.fn.expand("%:p:h")) while dir do if uv.fs_stat(dir .. "/vcpkg.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 = { "cppm", "h", "cpp", "CMakeLists.txt" }, callback = function() if is_cpp_project() then vim.keymap.set( "n", "", "! mkdir -p build && cd build && CC=/usr/bin/clang && CXX=/usr/bin/clang++ && cmake .. -G Ninja && cmake --build . --target copy-compile-commands && cd ..", { desc = "CMake Create" } ) vim.keymap.set("n", "", "! cd build && cmake --build .", { desc = "Build Project" }) vim.keymap.set( "n", "", "! cd build && cmake --build . --target run", { desc = "Run Project" } ) end end, })