toggle between regular and hex view of current buffer

1 Point

Janusz Kowalczyk Janusz Kowalczyk

7 years ago

Will toggle view between regular and hex editor. Unfortunately switching between these views somehow modifies the file. It'd be great if it haven't had any side effects. Maybe someone knows a better way to do it.

noremap <F10> :call HexMe()<CR>
let $in_hex=0
function! HexMe()
    set binary
    set noeol
    if $in_hex>0
        :%!xxd -r
        let $in_hex=0
    else
        :%!xxd
    let $in_hex=1
    endif
endfunction