Initial Commit
This commit is contained in:
commit
18da9560c6
31 changed files with 769 additions and 0 deletions
37
lua/config/maps/cpp.lua
Normal file
37
lua/config/maps/cpp.lua
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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",
|
||||
"<leader><F5>",
|
||||
"<CMD>! mkdir -p build && cd build && CC=/usr/bin/clang && CXX=/usr/bin/clang++ && cmake .. -G Ninja && cmake --build . --target copy-compile-commands && cd ..<CR>",
|
||||
{ desc = "CMake Create" }
|
||||
)
|
||||
vim.keymap.set("n", "<leader><F6>", "<CMD>! cd build && cmake --build .<CR>", { desc = "Build Project" })
|
||||
vim.keymap.set(
|
||||
"n",
|
||||
"<leader><F8>",
|
||||
"<CMD>! cd build && cmake --build . --target run<CR>",
|
||||
{ desc = "Run Project" }
|
||||
)
|
||||
end
|
||||
end,
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue