@@ -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
229234local 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 })
260265end
261266
267+ -- Invoke a command
268+ -- Runs g++ and compile it into exe
269+ -- After compile, runs the exe
262270vim .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 )
266274end , {})
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)
267281vim .api .nvim_create_user_command (" CompileAndRunWithFile" , function (args )
268282 TermWrapper (" g++ -std=c++11 " .. vim .fn .expand (" %" ) .. " && ./a.out < " .. args .args )
269283end , {
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-
279287vim .api .nvim_create_autocmd (" FileType" , {
280288 pattern = " cpp" ,
281289 command = " nnoremap <leader>fr :CompileAndRunWithFile<CR>" ,
0 commit comments