From afda305c2728cae8352385eb131df095890d9f93 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sun, 14 Apr 2024 19:31:47 +0200 Subject: [PATCH] feat: add script for neovim --- vim.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 vim.lua diff --git a/vim.lua b/vim.lua new file mode 100644 index 0000000..9f62265 --- /dev/null +++ b/vim.lua @@ -0,0 +1,22 @@ +-- A script for vim to map the word under the cursor with portingtools by pressing m, and all +-- mapped expressions in the file with M +local function map(name) + return vim.fn.systemlist("portingtools map", name)[1] +end + +vim.keymap.set("n", "m", function() + local word = vim.fn.expand "" + local mapped = map(word) + local replaced = vim.fn.getline("."):gsub(word, mapped); + vim.fn.setline(".", replaced) +end) + +vim.keymap.set("n", "M", function() + local nlines = 99 + for i = 1, nlines do + print(i .. "/" .. nlines) + local line = vim.fn.getline(i) + local mapped = line:gsub("field_%d+_[%a_]+", map):gsub("func_%d+_[%a_]+", map); + vim.fn.setline(i, mapped) + end +end)