rr- / vim-hexdec

Convert hexadecimal numbers to decimal and vice versa.
MIT License
14 stars 5 forks source link

Add a toggle function #4

Closed ivan-volnov closed 4 years ago

ivan-volnov commented 4 years ago

It would be great to have a toggle function for the converter.

rr- commented 4 years ago

What do you mean by a toggle function?

ivan-volnov commented 4 years ago

I mean something like this:

if (IsHex("text under cursor")) {
    Hex2dec();
else {
    Dec2hex();    
}

And then use just one key mapping.

rr- commented 4 years ago

Updated, please let me know if it's working for you.

ivan-volnov commented 4 years ago

Thank you!

Well, it works, but in a bit strange way.

Firstly it doesn't respect position of the cursor, so it applies to whole string. And it doesn't detect numbers well.

For example:

WHERE id = 3511
WHERE id = 0xDB7
WH14R14 i13 = 3511
WH14R14 i13 = 0xDB7

Every single line is result of every call of the toggle function.

rr- commented 4 years ago

Oh sorry, you're right. I removed a check for 0x in good faith but it see that it backfired greatly. I'll restore 0x requirement for hex number detection and will try to improve word detection in the following weeks.

rr- commented 4 years ago

Updated, please let me know if it's good enough. Anyway I think it'd be good to track the line replacements in a separate issue since this affects also the existing functions.

ivan-volnov commented 4 years ago

Much better, thank you!