Skip to content

Commit a10ff0d

Browse files
added more doc to the autocmd
1 parent aacc873 commit a10ff0d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lua/core/autocommands.lua

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ vim.api.nvim_create_autocmd({ "BufWritePre" }, {
226226
})
227227

228228
-- CPP purposes
229+
--------------------------------------------------------------------
230+
---------------------- READ TO UNDERSTAND --------------------------
231+
--------------------------------------------------------------------
232+
--- Function to open a new terminal (vertical / horizontal)
233+
--- While starting in INSERT mode
229234
local function TermWrapper(command)
230235
if vim.g.split_term_style == nil then
231236
vim.g.split_term_style = "vertical"
@@ -259,23 +264,26 @@ local function TermWrapper(command)
259264
})
260265
end
261266

267+
-- Invoke a command
268+
-- Runs g++ and compile it into exe
269+
-- After compile, runs the exe
262270
vim.api.nvim_create_user_command("CompileAndRun", function()
263271
local fileName = vim.fn.expand("%")
264272
local exeName = fileName:gsub("%.cpp$", "")
265273
TermWrapper("g++ -std=c++11 -o " .. exeName .. " " .. fileName .. " && ./" .. exeName)
266274
end, {})
275+
vim.api.nvim_create_autocmd("FileType", {
276+
pattern = "cpp",
277+
command = "nnoremap <leader>fw :CompileAndRun<CR>",
278+
})
279+
280+
-- Same as above but theres an input file (use it thru command line)
267281
vim.api.nvim_create_user_command("CompileAndRunWithFile", function(args)
268282
TermWrapper("g++ -std=c++11 " .. vim.fn.expand("%") .. " && ./a.out < " .. args.args)
269283
end, {
270284
nargs = 1,
271285
complete = "file",
272286
})
273-
274-
vim.api.nvim_create_autocmd("FileType", {
275-
pattern = "cpp",
276-
command = "nnoremap <leader>fw :CompileAndRun<CR>",
277-
})
278-
279287
vim.api.nvim_create_autocmd("FileType", {
280288
pattern = "cpp",
281289
command = "nnoremap <leader>fr :CompileAndRunWithFile<CR>",

0 commit comments

Comments
 (0)