fidian / hexmode

Vim plugin to edit binary files in a hex mode automatically.
147 stars 19 forks source link

Add configurable file patterns; fix undojoin usage #6

Closed sstallion closed 8 years ago

sstallion commented 8 years ago

This PR adds support for configurable file patterns and fixes undojoin usage when saving a buffer using the :write command. The latter issue is caused by the BufWritePre and BufWritePost groups being called back-to-back when :write is issued. This requires that the undo block be broken before starting another.

From the vim manual:

To do the opposite, break a change into two undo blocks, in Insert mode use CTRL-G u. This is useful if you want an insert command to be undoable in parts. E.g., for each sentence. |i_CTRL-G_u| Setting the value of 'undolevels' also breaks undo. Even when the new value is equal to the old value.

PS: both changes were quite small, rather than create a pair of smaller PRs, I went ahead and combined these changes. If this is an issue, I'm happy to break these apart!

fidian commented 8 years ago

Sorry for not getting to this earlier. I was on vacation and just showed up in front of my computer today.

I really appreciate the work you did. My only question is about including *.hex as a default hexmode file pattern. I would imagine that files named *.hex are really hex dumps of binary files and shouldn't be edited with a hex editor. In other words, I would imagine you to create these *.hex files using a command similar to this:

hexdump -C somefile.bin > somefile.hex
sstallion commented 8 years ago

Thanks! I added *.hex since that was previously supported by the plugin. It's a bit of an oddity, Intel .hex files are ASCII encoded and commonly used as a loadable format for embedded systems. My personal preference would be to remove it entirely - in fact, the vimrc I am using with this patch only specifies .bin files.

fidian commented 8 years ago

I'll merge this. Thanks for the contribution.

I'll also debate removing *.hex at a later time.

sstallion commented 8 years ago

Great. Thanks!