feat: add script for neovim

This commit is contained in:
LordMZTE 2024-04-14 19:31:47 +02:00
parent 67266797d9
commit afda305c27
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6
1 changed files with 22 additions and 0 deletions

22
vim.lua Normal file
View File

@ -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 "<cword>"
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)