35 lines
635 B
Lua
Raw Normal View History

2024-03-04 23:40:49 +00:00
-- ToggleWord
vim.api.nvim_create_user_command("ToggleWord", function()
local inverse = {
2024-03-07 12:09:05 +00:00
["horizontal"] = "vertical",
["on"] = "off",
2024-03-04 23:40:49 +00:00
["true"] = "false",
["True"] = "False",
["TRUE"] = "FALSE",
2024-03-07 12:09:05 +00:00
["yes"] = "no",
2024-03-04 23:40:49 +00:00
["Yes"] = "No",
["YES"] = "NO",
["1"] = "0",
["<"] = ">",
["("] = ")",
["["] = "]",
["{"] = "}",
['"'] = "'",
['""'] = "''",
["+"] = "-",
["==="] = "!==",
2024-03-07 12:09:05 +00:00
["=="] = "!=",
2024-03-04 23:40:49 +00:00
}
vim.tbl_add_reverse_lookup(inverse)
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, {})