Loading ...
Sorry, an error occurred while loading the content.
 

Re: Actual cursor position.

Expand Messages
  • Gerardo Marset
    ... I don t want my code to break if a line has multibyte characters. ... Works like a charm! Thank you! ... That s why I thougth my solution was sloppy: there
    Message 1 of 3 , Aug 31 10:50 AM
      El 31/08/11 01:35, ZyX escribió:
      > Reply to message «Actual cursor position.»,
      > sent 02:12:13 31 August 2011, Wednesday
      > by Gerardo Marset:
      >
      >> I'm looking for a way to get the current cursor position in the line
      >> (that is, the column) in *characters*.
      >> col is no use, because it returns the position in bytes. I can't use
      >> virtcol either because it returns the position on the screen: a tab
      >> counts as 8 characters (or whatever tabstop is set to), the line can be
      >> wrapped, etc.
      > Why do you need it?
      I don't want my code to break if a line has multibyte characters.

      > You can use
      > echo ((col('.')>1)?(strchars(getline(line('.'))[:col('.')-2])):(0))
      > or (if you need to count composing characters as a part of previous character)
      > replace `strchars(...)' with `len(split(..., '\v.@='))'.
      Works like a charm! Thank you!

      > Note that you solution does not work: you forgot that one character can occupy
      > two display cells if it either fullwidth (U+FF00..U+FF60, U+FFE0..U+FFE6,
      > U+3000) or with ambigious width and&ambiwidth is set.
      That's why I thougth my solution was sloppy: there was bound to be a way
      of breaking it.

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    Your message has been successfully submitted and would be delivered to recipients shortly.