Make Hex command more robust

Hex command now infers more meaning from context.
This commit is contained in:
Talia 2018-04-12 08:19:29 +02:00
parent 2c6b686107
commit c61240c532
1 changed files with 5 additions and 7 deletions

12
vimrc
View File

@ -283,24 +283,22 @@ function! s:hex(...)
else else
let l:args = [] let l:args = []
end end
if !exists("b:hex") if &filetype != "xxd"
silent exec '%!xxd '.join(l:args, " ") silent exec '%!xxd '.join(l:args, " ")
let b:hex = 1 set filetype=xxd
let b:prev_filetype = &filetype
let &filetype = "xxd"
nnoremap <buffer> i i<ins> nnoremap <buffer> i i<ins>
echo "A witch turned your file into a hexadecimal toad!" echo "A witch turned your file into a hexadecimal toad!"
else else
nunmap <buffer> i nunmap <buffer> i
silent exec '%!xxd -r '.join(l:args, " ") silent exec '%!xxd -r '.join(l:args, " ")
unlet b:hex filetype detect
let &filetype = b:prev_filetype
unlet b:prev_filetype
echo "The witch turned your file back into binary data" echo "The witch turned your file back into binary data"
end end
endfunction endfunction
command! -nargs=* Hex call <sid>hex(<q-args>) command! -nargs=* Hex call <sid>hex(<q-args>)
" === GIT STUFF === "
function! s:uncommitted(...) function! s:uncommitted(...)
if a:0 if a:0
let l:commit = a:1 let l:commit = a:1