diff options
Diffstat (limited to 'lua/warp/col_selectors/words.lua')
-rw-r--r-- | lua/warp/col_selectors/words.lua | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/lua/warp/col_selectors/words.lua b/lua/warp/col_selectors/words.lua new file mode 100644 index 0000000..8135a45 --- /dev/null +++ b/lua/warp/col_selectors/words.lua @@ -0,0 +1,77 @@ +local vim = assert(vim) + +local M = {} +local alphabet = "etansihrdlocumwfgypkbvjxqz" + +local function split_lines(line) + local i + local j = 1 + + local chars_to_col = {} + local col_to_chars = {} + + local run_regex = function(rx, off) + if #alphabet < j then return end + + if not off then off = 0 end + + i = 0 + while true do + i = string.find(line, rx, i) + if i == nil then break end + i = i + 1 + + if #alphabet < j then return end + + local nextalph = alphabet:sub(j, j) + j = j + 1 + chars_to_col[nextalph] = i + off + col_to_chars[i + off] = nextalph + end + end + + run_regex("%W%w") + run_regex("%s%S") + run_regex("%w%W", -1) + run_regex("[a-z][A-Z]") + + local winstr = "" + i = 1 + while i <= #line do + if col_to_chars[i] then + winstr = winstr .. col_to_chars[i] + else + winstr = winstr .. " " + end + i = i + 1 + end + + return winstr, chars_to_col +end + +M.words_strategy = function() + local chartab + + return { + display = function() + local curpos = vim.api.nvim_win_get_cursor(0) + local line_at = vim.fn.getline(curpos[1]) + local str, tab = split_lines(line_at) + chartab = tab + return str + end, + + on_char = function(ch) + if ch == '$' or ch == '^' then + vim.cmd("normal! " .. ch) + elseif not ch:match('[a-z]') then + vim.cmd("normal! f" .. ch) + else + if chartab[ch] then vim.cmd("norma! " .. chartab[ch] .. "|") end + end + return false + end + } +end + +return M |