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
1 changed files with 25 additions and 0 deletions

View File

@ -31,5 +31,30 @@ function! s:JqScratch()
endfunction
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>s :Shell rg '' %<Left><Left><Left>
nnoremap <LocalLeader>h :call GetDecimal()<CR>
nnoremap <LocalLeader>H :call GetHexaDecimal()<CR>