Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: replacement string item contains newlines #7

Open
singlexyz opened this issue Jul 10, 2024 · 0 comments
Open

Error: replacement string item contains newlines #7

singlexyz opened this issue Jul 10, 2024 · 0 comments

Comments

@singlexyz
Copy link

singlexyz commented Jul 10, 2024

I have a configuration that can easily add custom surround before and after a motion/text object.

However, when I change the join character from a space to a \n, it throws an error in the case of multiple lines.

local function surround_cword(keymap, left, right)
  local function surround(lines)
    local str = vim.iter(lines):join(" ")
    return { left .. str .. right }
  end
  op_map("v", keymap, surround)
  vim.keymap.set("n", keymap, function()
    return require("yop").operate(surround) .. "iw"
  end, { expr = true, remap = true })
end
surround_cword("8d", "--", "")
surround_cword("8v", "var(--", ")")
surround_cword("8c", "calc(", ")")
surround_cword("8x", "${", "}")
surround_cword("8s", "{ condition ? ", " : null }")
local str = vim.iter(lines):join("\n")  -- error on multiple lines

Record:
ezgif-7-692021a06d

image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant