|
1 | 1 | local M = {} |
2 | 2 |
|
| 3 | +-- Extended toggle map with multi-value cycling support |
3 | 4 | M.toggles = { |
4 | | - ["true"] = "false", |
5 | | - ["false"] = "true", |
6 | | - ["on"] = "off", |
7 | | - ["off"] = "on", |
8 | | - ["enabled"] = "disabled", |
9 | | - ["disabled"] = "enabled", |
10 | | - ["yes"] = "no", |
11 | | - ["no"] = "yes", |
12 | | - ["up"] = "down", |
13 | | - ["down"] = "up", |
| 5 | + ["true"] = { "false" }, |
| 6 | + ["false"] = { "true" }, |
| 7 | + ["on"] = { "off" }, |
| 8 | + ["off"] = { "on" }, |
| 9 | + ["enabled"] = { "disabled" }, |
| 10 | + ["disabled"] = { "enabled" }, |
| 11 | + ["yes"] = { "no" }, |
| 12 | + ["no"] = { "yes" }, |
| 13 | + ["up"] = { "down" }, |
| 14 | + ["down"] = { "up" }, |
| 15 | + ["start"] = { "stop" }, |
| 16 | + ["stop"] = { "start" }, |
| 17 | + ["open"] = { "close" }, |
| 18 | + ["close"] = { "open" }, |
| 19 | + ["allow"] = { "deny" }, |
| 20 | + ["deny"] = { "allow" }, |
| 21 | + ["accept"] = { "reject" }, |
| 22 | + ["reject"] = { "accept" }, |
| 23 | + ["read"] = { "write" }, |
| 24 | + ["write"] = { "read" }, |
| 25 | + ["push"] = { "pull" }, |
| 26 | + ["pull"] = { "push" }, |
| 27 | + ["inbound"] = { "outbound" }, |
| 28 | + ["outbound"] = { "inbound" }, |
| 29 | + ["public"] = { "private" }, |
| 30 | + ["private"] = { "public" }, |
| 31 | + ["online"] = { "offline" }, |
| 32 | + ["offline"] = { "online" }, |
| 33 | + ["local"] = { "remote" }, |
| 34 | + ["remote"] = { "local" }, |
| 35 | + ["master"] = { "slave" }, |
| 36 | + ["slave"] = { "master" }, |
| 37 | + ["primary"] = { "replica" }, |
| 38 | + ["replica"] = { "primary" }, |
| 39 | + ["active"] = { "passive" }, |
| 40 | + ["passive"] = { "active" }, |
| 41 | + ["manual"] = { "automatic" }, |
| 42 | + ["automatic"] = { "manual" }, |
| 43 | + |
| 44 | + -- Environments toggle |
| 45 | + ["prod"] = { "uat", "dev", "preprod" }, |
| 46 | + ["uat"] = { "dev", "preprod", "prod" }, |
| 47 | + ["dev"] = { "preprod", "prod", "uat" }, |
| 48 | + ["preprod"] = { "prod", "uat", "dev" }, |
14 | 49 | } |
15 | 50 |
|
16 | | ---- Toggle the word under the cursor if it's in the toggle list |
| 51 | +-- Toggle word under cursor, cycling through defined alternates |
17 | 52 | function M.toggle_word() |
18 | 53 | local word = vim.fn.expand("<cword>") |
19 | | - local replacement = M.toggles[word] |
20 | | - if replacement then |
21 | | - vim.cmd("normal! ciw" .. replacement) |
22 | | - else |
23 | | - vim.notify("No toggle match for: " .. word, vim.log.levels.WARN) |
| 54 | + for key, values in pairs(M.toggles) do |
| 55 | + if word == key then |
| 56 | + vim.cmd("normal! ciw" .. values[1]) |
| 57 | + return |
| 58 | + elseif vim.tbl_contains(values, word) then |
| 59 | + local idx = vim.fn.index(values, word) |
| 60 | + local next_idx = (idx + 1) % #values |
| 61 | + vim.cmd("normal! ciw" .. values[next_idx + 1]) |
| 62 | + return |
| 63 | + end |
24 | 64 | end |
| 65 | + vim.notify("No toggle match for: " .. word, vim.log.levels.WARN) |
25 | 66 | end |
26 | 67 |
|
27 | | ---- Setup keybindings and allow custom toggle pairs |
| 68 | +-- Optional setup: override toggles or keybinding |
28 | 69 | -- @param opts table|nil: { key = "<leader>tt", toggles = table } |
29 | 70 | function M.setup(opts) |
30 | 71 | opts = opts or {} |
|
0 commit comments