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

2470Re: jumping to a character instead of byte

Expand Messages
  • Tony Mechelynck
    May 3, 2008
      On 03/05/08 23:14, Derick Eddington wrote:
      > I'm trying to figure out how to configure Vim so that ":goto X" will go
      > to character X not byte X. If I have an external thing (in my case, an
      > interpreter) telling me I need to look at character X, when the file is
      > in a multi-byte encoding (typically UTF-8), I need to be able to tell
      > Vim to go to character X. How can this be done?
      > I searched around for the answer but couldn't find it, so thanks for any
      > help.

      ":goto" will always count by bytes, but there's another way to do it:

      :set ww+=s ve=onemore
      :exe "normal gg" . (char_number - 1) . " "

      don't forget the space at the end. When doing it at the keyboard you may
      type just gg then the number (one less than the desired character
      number) followed by a space: "exe 'normal'" is not necessary in that case.

      :help 'whichwrap'
      :help 'virtualedit

      The ":set virtualedit=onemore" is necessary to count linebreaks (but
      each of them as only one character even on Windows). That option value
      doesn't exist in Vim 6 or earlier.

      You can check the result with the Normal-mode command g Ctrl-G

      Best regards,
      It is illegal for anyone to give lighted cigars to dogs, cats, and other
      domesticated animal kept as pets.
      [real standing law in Illinois, United States of America]

      You received this message from the "vim_multibyte" maillist.
      For more information, visit http://www.vim.org/maillist.php
    • Show all 4 messages in this topic