How do I jump to a specific byte offset position in a file?
Answer
{count}go
Explanation
The go command moves the cursor to a specific byte offset from the start of the buffer. {N}go jumps to byte N (1-based), counting every byte in the file including newline characters. This is particularly useful when a compiler, parser, or binary analysis tool reports an error or point of interest by byte offset rather than line and column.
How it works
42go— jump to byte 42 from the start of the filego— without a count, equivalent to1go(moves to the first byte, top of file):goto {N}is the Ex command equivalent
Unlike {N}G (line number) or {N}| (column), go uses the absolute byte position counting from the file's beginning.
Example
A parser reports: SyntaxError: unexpected token at byte 1024. Instead of scrolling or counting:
1024go
The cursor jumps directly to the character at byte offset 1024.
Tips
- To find the current byte offset:
g<C-g>shows word count, line, column, and byte position - Bytes are counted as stored on disk — a multi-byte UTF-8 character occupies 2–4 bytes, so the byte offset may not equal the character position
:set fileformat=unixensures consistent newline byte counting (LF only) vs. Windows CRLF- In binary files (
vim -b file),gois the primary navigation tool alongside%xxd - The
:gotoEx form accepts the same argument::goto 1024