Skip to content

[mini.ai]: Paragraph textobject? #1119

Closed Answered by echasnovski
qtyra asked this question in Q&A
Discussion options

You must be logged in to vote

I am not aware of a better way for paragraph textobject than writing a function which returns either a single target region or an array of regions. I think the latter is easier to implement.

Here is a partial solution showcasing basic approach:

local inner_paragraph = function()
  local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
  local res, cur_paragraph = {}, { vis_mode = 'V' }
  for i, l in ipairs(lines) do
    if l:find('^%s*$') ~= nil then
      if cur_paragraph.from ~= nil then
        cur_paragraph.to = { line = i - 1, col = 1 }
        table.insert(res, cur_paragraph)
        cur_paragraph = { vis_mode = 'V' }
      end
    else
      if cur_paragraph.from == nil then cur…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by echasnovski
Comment options

You must be logged in to vote
5 replies
@echasnovski
Comment options

@qtyra
Comment options

@echasnovski
Comment options

@qtyra
Comment options

@echasnovski
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants