Created
February 2, 2012 22:06
-
-
Save yhirose/1726085 to your computer and use it in GitHub Desktop.
Conver number to number at cursor in VIM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Conver number to number at cursor. | |
function! NumConv(base, fmt) | |
let b = a:base | |
let fmt = a:fmt | |
let w = expand('<cword>') | |
let d = str2nr(w, b) | |
let h = printf(fmt, d) | |
execute "normal ciw" . h | |
endfunction | |
" Dec to Hex example | |
nmap <Leader>h :call NumConv(10, "%x")<CR> | |
" Hex to Dec example | |
nmap <Leader>d :call NumConv(16, "%d")<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment