Skip to content

Visual mode counting #106

Answered by diniamo
diniamo asked this question in Q&A
Dec 20, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Thanks! That's broken for a few reasons because the Vim API is apparently a mess. Here is what I came up with:

function()
  local mode = vim.fn.mode()
  if mode == "v" then
    local start_line = vim.fn.line("v")
    local end_line = vim.fn.line(".")

    if start_line == end_line then
      return tostring(math.abs(vim.fn.virtcol(".") - vim.fn.virtcol("v")) + 1)
    else
      return tostring(math.abs(end_line - start_line) + 1)
    end
  elseif mode == "V" then
    return tostring(math.abs(vim.fn.line(".") - vim.fn.line("v")) + 1)
  elseif mode == "" then
    return math.abs(vim.fn.virtcol(".") - vim.fn.virtcol("v")) + 1 .. "x" .. math.abs(vim.fn.line(".") - vim.fn.line("v")) + 1
  else

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@diniamo
Comment options

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