Skip to content

Instantly share code, notes, and snippets.

@yhirose
Created February 2, 2012 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhirose/1726085 to your computer and use it in GitHub Desktop.
Save yhirose/1726085 to your computer and use it in GitHub Desktop.
Conver number to number at cursor in VIM
" 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