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

Re: jumping to a character instead of byte

Expand Messages
  • Tony Mechelynck
    ... 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
    Message 1 of 4 , 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.

      see
      :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,
      Tony.
      --
      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
      -~----------~----~----~----~------~----~------~--~---
    • Derick Eddington
      Thanks Tony. That s a lot to have to type every time I want to go to a character. I m thinking there must be a way to package that code into a Vim
      Message 2 of 4 , May 5, 2008
        Thanks Tony.

        That's a lot to have to type every time I want to go to a character.
        I'm thinking there must be a way to package that code into a Vim
        function/procedure/command, say :gotoc, but I'm totally new to Vim,
        could you or anyone quickly tell/point me how to do that and where to
        put it so it's available when I start Vim? Thank you very much. I
        imagine adding a new :gotoc to Vim would be greatly appreciated by
        many others, now that multi-byte encodings are becoming so much more
        prevalent.

        [TMI, I never received your response, I'm having to use the Google
        Groups interface to read and reply, even though I subscribed.]

        --
        : Derick
        ----------------------------------------------------------------

        On May 3, 5:05 pm, Tony Mechelynck <antoine.mechely...@...>
        wrote:
        > 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.
        >
        > see
        > :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,
        > Tony.
        > --
        > 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
        -~----------~----~----~----~------~----~------~--~---
      • Tony Mechelynck
        ... You would in any case have had to either type the character-count manually, or (in a script) get it from a variable. Manually, it s usually just as many
        Message 3 of 4 , May 5, 2008
          On 05/05/08 17:38, Derick Eddington wrote:
          > Thanks Tony.
          >
          > That's a lot to have to type every time I want to go to a character.
          > I'm thinking there must be a way to package that code into a Vim
          > function/procedure/command, say :gotoc, but I'm totally new to Vim,
          > could you or anyone quickly tell/point me how to do that and where to
          > put it so it's available when I start Vim? Thank you very much. I
          > imagine adding a new :gotoc to Vim would be greatly appreciated by
          > many others, now that multi-byte encodings are becoming so much more
          > prevalent.

          You would in any case have had to either type the character-count
          manually, or (in a script) get it from a variable. Manually, it's
          usually just as many keypresses (and sometimes one less) to type "one
          less than the number". Prefix that by gg and postfix that by one hit on
          the spacebar and you're done (assuming that the correct settings are set
          once and for all).

          In a script, you can write the appropriate ex-commands where you need to
          use them; or if you need them at several places in various scripts, you
          can define a user-command or function and invoke that.

          >
          > [TMI, I never received your response, I'm having to use the Google
          > Groups interface to read and reply, even though I subscribed.]

          Make sure your Google Groups are set to forward all group posts to your
          email address. If you use a gmail address, set it up for POP (or IMAP
          but personally I prefer POP).


          Best regards,
          Tony.
          --
          It's always darkest just before it gets pitch black.

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_multibyte" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        Your message has been successfully submitted and would be delivered to recipients shortly.