SHARE
TWEET

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!
  1. " jump to byte offset
  2. " (http://vi.stackexchange.com/questions/3845/go-to-x-bytes-from-here)
  3. let s:last_jump_bytes = 0
  4. function! JumpToByte(byte_nr, mul)
  5.         let crt_byte = line2byte(line('.')) + col('.') - 1
  6.         if (a:byte_nr == 0)
  7.                 let dst_byte = crt_byte + a:mul * s:last_jump_bytes
  8.         else
  9.                 let dst_byte = crt_byte + a:mul * a:byte_nr
  10.                 let s:last_jump_bytes = a:byte_nr
  11.         endif
  12.         let dst_byte = dst_byte > 1? dst_byte : 1
  13.         execute "go " . dst_byte
  14. endfunction
  15.  
  16. nnoremap <expr> <silent> GO  ":<c-u>call JumpToByte(" . v:count . ",+1)<cr>"
  17. nnoremap <expr> <silent> Go  ":<c-u>call JumpToByte(" . v:count . ",-1)<cr>"
  18. " for symmetry with 'gg', and .. G is now a prefix ^^^
  19. nnoremap GG G
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top