From 323db62adbc43613a4a3b4c176f4d5ce4b572960 Mon Sep 17 00:00:00 2001 From: subcrip Date: Sat, 25 May 2024 12:25:20 +0800 Subject: [PATCH] backup --- src/bin/.nvim.lua | 88 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/bin/.nvim.lua diff --git a/src/bin/.nvim.lua b/src/bin/.nvim.lua new file mode 100644 index 0000000..ab7fc86 --- /dev/null +++ b/src/bin/.nvim.lua @@ -0,0 +1,88 @@ +vim.api.nvim_create_autocmd("FileType", { + pattern = "cpp", + callback = function() + vim.api.nvim_buf_set_keymap(0, 'n', "b", '10spte ctext -i $(gcc -xc++ /dev/null -E -Wp,-v 2>&1 | sed -n "s,^ ,,p" | tr "\\n" ",") < % > ctext_out.cc && clang++ -std=c++17 -DONLINE_JUDGE -Wl,-z,stack-size=268435456 -Wall -Ofast -g -fsanitize=address -fsanitize=undefined ctext_out.cc && ./a.out < std.ini', { + silent = true, + noremap = true + }) + end, +}) + +vim.api.nvim_create_autocmd("FileType", { + pattern = "python", + callback = function() + vim.api.nvim_buf_set_keymap(0, 'n', "b", "10spte python3 %i", { + silent = true, + noremap = true + }) + end, +}) + +vim.keymap.set('n', 'y', '!ctext -i $(gcc -xc++ /dev/null -E -Wp,-v 2>&1 | sed -n "s,^ ,,p" | tr "\\n" ",") < % > ctext_out.ccsplit ctext_out.cc:%%y+q') +vim.keymap.set('n', '1', 'CphReceive'); +vim.keymap.set('n', '2', 'CphTest'); +vim.keymap.set('n', '3', 'r ~/RustIsBestLang/src/bin/template.ccG'); +vim.keymap.set('n', 'l', '40vs std.in') + +local function add_timestamp() + local bufnr = vim.api.nvim_get_current_buf() + local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) + + local current_time = os.time() + local current_time_str = os.date("%Y-%m-%d %H:%M:%S", current_time) + local comment_string + + local create_time_str = "" + local elapsed_minutes = 0 + if #lines > 0 and lines[1]:match("/**") then + create_time_str = lines[3]:match(" * Created: (.*)") + local create_time = os.time({ + year = tonumber(create_time_str:sub(1, 4)), + month = tonumber(create_time_str:sub(6, 7)), + day = tonumber(create_time_str:sub(9, 10)), + hour = tonumber(create_time_str:sub(12, 13)), + min = tonumber(create_time_str:sub(15, 16)), + sec = tonumber(create_time_str:sub(18, 19)), + }) + elapsed_minutes = math.floor((current_time - create_time) / 60) + else + create_time_str = current_time_str + end + + comment_string = { + "/**", + " * Author: subcrip", + " * Created: " .. create_time_str, + " * Modified: " .. current_time_str, + " * Elapsed: " .. elapsed_minutes .. " minutes", + " */", + "", + } + + if #lines > 0 and lines[1]:match("/**") then + for i = 1, #comment_string do + lines[i] = comment_string[i] + end + else + for i = #comment_string, 1, -1 do + table.insert(lines, 1, comment_string[i]) + end + end + + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines) +end + +vim.api.nvim_create_autocmd( + "BufWritePost", + { + pattern = "*.cc", + callback = add_timestamp, + } +) +vim.api.nvim_create_autocmd( + "BufWritePre", + { + pattern = "*.cc", + callback = add_timestamp, + } +)