From 0dad89e0fb843190cda93957ee0e5f2a67ab0d1d Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Mon, 8 Jan 2024 14:31:28 +0530 Subject: [PATCH] nvim: plugin/shell: Add helper to get decimal & hexadecimal values --- nvim/.config/nvim/plugin/shell.vim | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/nvim/.config/nvim/plugin/shell.vim b/nvim/.config/nvim/plugin/shell.vim index af4760e..5c27139 100644 --- a/nvim/.config/nvim/plugin/shell.vim +++ b/nvim/.config/nvim/plugin/shell.vim @@ -31,5 +31,30 @@ function! s:JqScratch() endfunction command! JqScratch call s:JqScratch() +function! GetDecimal() + execute 'normal! viw' + let hex = expand("") + 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("") + let hex = trim(system("printf '%x\n' " . decimal)) + echo hex + call system('wl-copy ' . string(hex)) + execute "normal! \e\eb" +endfunction + nnoremap j :JqScratch nnoremap s :Shell rg '' % + +nnoremap h :call GetDecimal() +nnoremap H :call GetHexaDecimal()