@@ -226,6 +226,11 @@ vim.api.nvim_create_autocmd({ "BufWritePre" }, {
226
226
})
227
227
228
228
-- CPP purposes
229
+ ---- ----------------------------------------------------------------
230
+ ---- ------------------ READ TO UNDERSTAND --------------------------
231
+ ---- ----------------------------------------------------------------
232
+ --- Function to open a new terminal (vertical / horizontal)
233
+ --- While starting in INSERT mode
229
234
local function TermWrapper (command )
230
235
if vim .g .split_term_style == nil then
231
236
vim .g .split_term_style = " vertical"
@@ -259,23 +264,26 @@ local function TermWrapper(command)
259
264
})
260
265
end
261
266
267
+ -- Invoke a command
268
+ -- Runs g++ and compile it into exe
269
+ -- After compile, runs the exe
262
270
vim .api .nvim_create_user_command (" CompileAndRun" , function ()
263
271
local fileName = vim .fn .expand (" %" )
264
272
local exeName = fileName :gsub (" %.cpp$" , " " )
265
273
TermWrapper (" g++ -std=c++11 -o " .. exeName .. " " .. fileName .. " && ./" .. exeName )
266
274
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)
267
281
vim .api .nvim_create_user_command (" CompileAndRunWithFile" , function (args )
268
282
TermWrapper (" g++ -std=c++11 " .. vim .fn .expand (" %" ) .. " && ./a.out < " .. args .args )
269
283
end , {
270
284
nargs = 1 ,
271
285
complete = " file" ,
272
286
})
273
-
274
- vim .api .nvim_create_autocmd (" FileType" , {
275
- pattern = " cpp" ,
276
- command = " nnoremap <leader>fw :CompileAndRun<CR>" ,
277
- })
278
-
279
287
vim .api .nvim_create_autocmd (" FileType" , {
280
288
pattern = " cpp" ,
281
289
command = " nnoremap <leader>fr :CompileAndRunWithFile<CR>" ,
0 commit comments