nvim: plugin/shell: Add helper to get decimal & hexadecimal values

This commit is contained in:
Sanchayan Maity 2024-01-08 14:31:28 +05:30
parent 384eed0b5c
commit 0dad89e0fb
Signed by: sanchayanmaity
GPG key ID: 6F6A0609C12038F3

View file

@ -31,5 +31,30 @@ function! s:JqScratch()
endfunction endfunction
command! JqScratch call s:JqScratch() command! JqScratch call s:JqScratch()
function! GetDecimal()
execute 'normal! viw'
let hex = expand("<cword>")
if stridx(hex, "0x") == 0
let decimal = trim(system("printf '%d\n' " . hex))
else
let decimal = trim(system("printf '%d\n' 0x" . hex))
endif
echo decimal
call system('wl-copy ' . string(decimal))
execute "normal! \e\eb"
endfunction
function! GetHexaDecimal()
execute 'normal! viw'
let decimal = expand("<cword>")
let hex = trim(system("printf '%x\n' " . decimal))
echo hex
call system('wl-copy ' . string(hex))
execute "normal! \e\eb"
endfunction
nnoremap <Leader><Leader>j :JqScratch<CR> nnoremap <Leader><Leader>j :JqScratch<CR>
nnoremap <Leader><Leader>s :Shell rg '' %<Left><Left><Left> nnoremap <Leader><Leader>s :Shell rg '' %<Left><Left><Left>
nnoremap <LocalLeader>h :call GetDecimal()<CR>
nnoremap <LocalLeader>H :call GetHexaDecimal()<CR>