This search moves 40 chars (not bytes, though) forward:
/\_.\{40}/e
by searching for exactly 40 chars (\{40}
) of any kind, including newline (\_.
), and placing the cursor at the end of the search (/e
). See: http://vimregex.com/#Non-Greedy, :help search-offset
and :help \_
Also, see :h 23.4
for binary editing.
Update: Based on this answer, here's a function that jumps to byte offset:
let s:last_jump_bytes = 0
function! JumpTo(byte_nr)
let crt_byte = line2byte(line('.')) + col('.')
if (a:byte_nr == 0)
let dst_byte = crt_byte + s:last_jump_bytes
else
let dst_byte = crt_byte + a:byte_nr
let s:last_jump_bytes = a:byte_nr
endif
let dst_line = byte2line(dst_byte)
let dst_col = dst_byte -line2byte(dst_line)
"remove next line if you don't want to record this for `Ctrl-O`
execute "normal " . dst_line . "G"
call setpos('.', [0, dst_line, dst_col])
endfunction
command! -nargs=1 JumpToOffset :call JumpTo(<f-args>)
" silly mapping to Ctrl-C (demo)
nnoremap <expr> <silent> <c-c> ":<c-u>call JumpTo(" . v:count . ")<cr>"
Can be used like this:
:JumpToOffset 400
or typing the mapped keyboard mapping, with a count:
40CTRL-C
If you don't use a count, the previous count number is re-used. So you can do: 40CTRL-C CTRL-C CTRL-C 30CTRL-C CTRL-C
to jump 40, 40, 40, 30, 30 bytes etc.
Hit Ctrl-O
to jump back (see comments inside the function).
Xl
(whereX
is the number of characters) or the number of characters followed by Right arrow.