jump to byte offset in vim
a guest Jul 6th, 2015 23 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- " jump to byte offset
- " (http://vi.stackexchange.com/questions/3845/go-to-x-bytes-from-here)
- let s:last_jump_bytes = 0
- function! JumpToByte(byte_nr, mul)
- let crt_byte = line2byte(line('.')) + col('.') - 1
- if (a:byte_nr == 0)
- let dst_byte = crt_byte + a:mul * s:last_jump_bytes
- let dst_byte = crt_byte + a:mul * a:byte_nr
- let s:last_jump_bytes = a:byte_nr
- let dst_byte = dst_byte > 1? dst_byte : 1
- execute "go " . dst_byte
- nnoremap <expr> <silent> GO ":<c-u>call JumpToByte(" . v:count . ",+1)<cr>"
- nnoremap <expr> <silent> Go ":<c-u>call JumpToByte(" . v:count . ",-1)<cr>"
- " for symmetry with 'gg', and .. G is now a prefix ^^^
- nnoremap GG G
RAW Paste Data