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

Bug: Incorrect cursor position reported on lines with tab characters #1276

Open
2 tasks done
Davester47 opened this issue Jul 15, 2024 · 3 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@Davester47
Copy link

Self Checks

  • I'm using the latest lualine.
  • I didn't find the issue in existing issues or PRs.

How to reproduce the problem

  1. Open a blank file
  2. Press 'i' to enter insert mode
  3. Press the tab key
  4. Look at column position in right side of lualine

Expected behaviour

The column position is 9 (or 1 + your tab size).

Actual behaviour

The column position is 2 (1 + 1 tab character).

Minimal config to reproduce the issue

call plug#begin("/home/user/ll_bug/.local/share/nvim/plugged")
Plug 'nvim-lualine/lualine.nvim'
call plug#end()

lua << END
require'lualine'.setup{}
END

Additional information

This was broken by @davidt's PR, #1243. vim.api.virtcol correctly counted tab characters at their proper length, but vim.fn.charcol does not.

@Davester47 Davester47 added the bug Something isn't working label Jul 15, 2024
@omeyenburg
Copy link
Contributor

I believe, this is not a bug. The column number is the number of characters on the left of the cursor and tab is a single character.

Lualine doesn't make this number up. Most likely it is just taken from the vim API. And you can use this number to jump to a specific column, e.g. if you type 5| you jump to the fifth column.

@jwylder1
Copy link

jwylder1 commented Oct 2, 2024

If you want to have the tabs reflected you can use the vim variable %v.

@ListeriaM
Copy link

ListeriaM commented Oct 8, 2024

By default neovim will show the line number, column number and virtual column number (only shown if it differs from the column number), among other things we don't care about in this case. The following config snippet will do just that while preserving the formatting style of the location() function used by lualine, but don't expect it to work with inlay hints:

require('lualine').setup {
  sections = {
    lualine_z = {
      { '%3l:%-2.(%c%V%)', type = 'stl' },
    },
  },
}

if you want to use charcol() instead of %c then this function adapted from location() would do the trick:

require('lualine').setup {
  sections = {
    lualine_z = {
      function()
        local line = vim.fn.line('.')
        local ccol = vim.fn.charcol('.')
        local vcol = vim.fn.virtcol('.')
        if ccol == vcol then
          return string.format('%3d:%-2d', line, ccol)
        else
          return string.format('%3d:%d-%d', line, ccol, vcol)
        end
      end,
    },
  },
}

see :h 'statusline' and :h lualine for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants