home/.config/nvim/lua/commands.lua
2025-05-28 16:39:25 +02:00

41 lines
No EOL
723 B
Lua

-- ToggleWord
vim.api.nvim_create_user_command("ToggleWord", function()
local inverse = {
["bottom"] = "top",
["horizontal"] = "vertical",
["left"] = "right",
["on"] = "off",
["true"] = "false",
["True"] = "False",
["TRUE"] = "FALSE",
["yes"] = "no",
["Yes"] = "No",
["YES"] = "NO",
["y"] = "n",
["1"] = "0",
["<"] = ">",
["("] = ")",
["["] = "]",
["{"] = "}",
['"'] = "'",
['""'] = "''",
["+"] = "-",
["==="] = "!==",
["=="] = "!=",
}
for key, value in pairs(inverse) do
inverse[value] = key
end
vim.cmd("normal! yiw")
local yanked = vim.fn.getreg('"')
local flipped = inverse[yanked]
if flipped == nil then
return
end
vim.cmd("normal! ciw" .. flipped)
end, {})