LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-27-2005, 06:35 PM   #1
rmartine
Member
 
Registered: Dec 2002
Location: San Luis Obispo, CA
Distribution: Fedora Core 3
Posts: 618

Rep: Reputation: 30
Hex Editor Trouble


Hey all! Long time no see....

OK I'm trying to edit a hex file by hand. If I make a change and save then run a diff on the original and the modified version, of course I see a difference. The problem is when I try and return the file to its original state diff still complains. It also looks like the file grew. I need to be able to return it to its original state.


I open the file up using the following command:

vi test.bin

Fire up xxd:

:%!xxd

I then edit a couple bytes until I'm happy then revert it with this command:

:%!xxd -r

Then save and quit

:wq

I can't return the file back to its original state to make diff stop complaining. Any suggestion?
 
Old 05-27-2005, 07:00 PM   #2
rmartine
Member
 
Registered: Dec 2002
Location: San Luis Obispo, CA
Distribution: Fedora Core 3
Posts: 618

Original Poster
Rep: Reputation: 30
Found it!

For those of you that ever have this problem, here is the solution. Apparenly xxd -r does interesting things when inside vi and not in binary mode. To avoid this, put the following in your .vimrc, and open the file in binary mode: vim -b

" vim -b : edit binary using xxd-format!
augroup Binary
au!
au BufReadPre *.bin let &bin=1
au BufReadPost *.bin if &bin | %!xxd
au BufReadPost *.bin set ft=xxd | endif
au BufWritePre *.bin if &bin | %!xxd -r
au BufWritePre *.bin endif
au BufWritePost *.bin if &bin | %!xxd
au BufWritePost *.bin set nomod | endif
augroup END

Using this, Vim can be used as a pretty cool hex editor. Happy editing!!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hex editor SUSE 9.1 ionmich SUSE / openSUSE 3 10-11-2005 10:56 AM
a good simple hex editor w/ gui nkoplm Linux - General 4 09-17-2005 12:43 PM
Trouble changing default editor downinthemine Linux - Software 4 12-11-2003 03:48 PM
Trouble with Kate (editor) Gerardoj Linux - Software 3 09-25-2003 06:00 PM
Diassembler/hex editor? JMC Linux - Software 0 06-06-2002 11:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration