Tip: #448 - Copy the decimal equivalent of a hex number
Created: March 25, 2003 21:04 Complexity: intermediate Author: Mohit Kalra Version: 6.0 Karma: 13/6 Imported from: Tip#448
Here is a mapping that will copy a hexadecimal number in a register after converting it to the decimal equivalent. The tip is pretty useful if you are a programmer.
- map \y g*<esc>:let @*=@/ + 0<enter>
Usage:
1. Place the cursor on any hexadecimal number (eg 0xff, 0xfefe, 0x3434) and press \y.
2. Place the cursor at the location where you want to paste the number in decimal and press "*p
3. The number is also copied to the clipboard (windows) so you can paste it in other applications.
Example:
If the hexadecimal number is 0xff, then 255 will be copied to the clipboard.
Configuring the tip.
If you do not like the above key combinations or the register being used, you can configure the tip to use other mappings as explained below:
1. Change \y in the above mapping to any key combination of your choice.
2. Change @* to @<any_other_lower_case_letter> to copy the contents to another register. If you do this, pasting will require the command "<that_same_lower_case_letter>p
Side effects:
1. The tip uses the search register for the conversion. Therefore any last search will be lost.
2. The tip also uses a register to yank the result. The earlier contents of that register (in our case the * register) will be lost.
-mohit
Comments
There is a way of doing this without changing the search history
map \y :let --AT--*=<C-R><C-W> +0<cr>
And a way to not change the " * " register contents would be to use some global variables instead I guess...Some think like
map \y :let g:HexYank=<C-R><C-W> +0<cr>
for yanking, and..
map \p :if exists("g:HexYank") <Bar> exe "normal i" . g:HexYank <Bar> endif <cr>
for pasting
- Me Thinks
Anonymous , March 26, 2003 4:11
"<some-register>yiw
should also work instead of searching.
Anonymous , March 28, 2003 17:20