17

How can I move the cursor to the nth byte in the buffer?

How can I display the current cursor position in the ruler in terms of the byte offset, rather than lines and columns? (Follow-up question: can it be displayed in both decimal and hexadecimal?)

24
:goto 2356

jumps to the 2356th byte in the buffer.

Use the %o field in 'statusline' or 'rulerformat' to display the byte number of the character under your cursor.

Use %O to display the value in hexadecimal format.

Reference:

:help :goto
:help 'statusline'
:help 'rulerformat'
2

You can hit g Ctrl+g and you get the full information about the position:

Col 13 of 35; Line 18 of 2272; Word 70 of 7767; Char 410 of 50021; Byte 410 of 50118
1

To display the byte position you can use the following command

:echo line2byte(line("."))+col(".")-1

See Question: Get offset of current buffer in vim

3
  • 1
    Probably, Vivian De Smedt forgot one ) in the end of line. Let me guess that he meant :echo(eval(line2byte(line("."))+col(".")-1)) – Sam Cenzored Dec 9 '20 at 8:55
  • 3
    I would rather recommend to use :echo eval(line2byte(line("."))+col(".")-1) (e.g. remove the very first parenthesis) – Christian Brabandt Dec 9 '20 at 9:16
  • 1
    @SamCenzored I've converted your answer to a comment, for now, since it seemed like you were clarifying a post (see vi.stackexchange.com/help/privileges/comment). Welcome to Vi and Vim! – D. Ben Knoble Dec 9 '20 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.