January 23, 2016

.vimrc edti binary files in hex mode

Add the following to your ~/.vimrc file, and vim will be able to edit *.bin, *.exe, and *.o files in HEX mode:

if has ("autocmd")
" vim -b : edit binary using xxd-format!
augroup Binary
au BufReadPre  *.bin,*.exe,*.o let &binary=1
au BufReadPost * if &binary | %!xxd
au BufReadPost * so $VIMRUNTIME/syntax/xxd.vim | set filetype=xxd | endif
au BufWritePre * if &binary | %!xxd -r
au BufWritePre * endif
au BufWritePost * if &binary | %!xxd
au BufWritePost * set nomod | endif
augroup END

No comments:

Post a Comment