From 98f4aae2b177410c96b6d926eba2042f8a16d51e Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 31 Oct 2023 21:44:09 +0200 Subject: RunCode() self code runner for various filetypes --- .config/nvim/lua/user/mods.lua | 91 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to '.config/nvim/lua/user/mods.lua') diff --git a/.config/nvim/lua/user/mods.lua b/.config/nvim/lua/user/mods.lua index 6d357f5..a74d7fb 100644 --- a/.config/nvim/lua/user/mods.lua +++ b/.config/nvim/lua/user/mods.lua @@ -850,5 +850,96 @@ vim.api.nvim_create_autocmd('BufHidden', { -------------------------------------------------- +local function substitute(cmd) + cmd = cmd:gsub('%%', vim.fn.expand('%')) + cmd = cmd:gsub('$fileBase', vim.fn.expand('%:r')) + cmd = cmd:gsub('$filePath', vim.fn.expand('%:p')) + cmd = cmd:gsub('$file', vim.fn.expand('%')) + cmd = cmd:gsub('$dir', vim.fn.expand('%:p:h')) + cmd = cmd:gsub('#', vim.fn.expand('#')) + cmd = cmd:gsub('$altFile', vim.fn.expand('#')) + + return cmd +end + +function M.RunCode() + local file_extension = vim.fn.expand('%:e') + local selected_cmd = '' + local term_cmd = 'bot 10 new | term ' + local supported_filetypes = { + html = { + default = '%', + }, + c = { + default = 'gcc % -o $fileBase && ./$fileBase', + debug = 'gcc -g % -o $fileBase && ./$fileBase', + }, + cs = { + default = 'dotnet run', + }, + cpp = { + default = 'g++ % -o $fileBase && ./$fileBase', + debug = 'g++ -g % -o ./$fileBase', + competitive = 'g++ -std=c++17 -Wall -DAL -O2 % -o $fileBase && $fileBase