mirror of
https://github.com/Matir/skel.git
synced 2026-05-26 05:29:09 -07:00
Add hex editing function to vim.
This commit is contained in:
41
vimrc
41
vimrc
@@ -32,3 +32,44 @@ cnoremap sudow w !sudo tee % >/dev/null
|
|||||||
set incsearch
|
set incsearch
|
||||||
set ignorecase
|
set ignorecase
|
||||||
set smartcase
|
set smartcase
|
||||||
|
|
||||||
|
" Mediocre Hex editing in vim
|
||||||
|
" Source: http://vim.wikia.com/wiki/Improved_hex_editing
|
||||||
|
nnoremap <C-H> :Hexmode<CR>
|
||||||
|
command -bar Hexmode call ToggleHex()
|
||||||
|
function ToggleHex()
|
||||||
|
" hex mode should be considered a read-only operation
|
||||||
|
" save values for modified and read-only for restoration later,
|
||||||
|
" and clear the read-only flag for now
|
||||||
|
let l:modified=&mod
|
||||||
|
let l:oldreadonly=&readonly
|
||||||
|
let &readonly=0
|
||||||
|
let l:oldmodifiable=&modifiable
|
||||||
|
let &modifiable=1
|
||||||
|
if !exists("b:editHex") || !b:editHex
|
||||||
|
" save old options
|
||||||
|
let b:oldft=&ft
|
||||||
|
let b:oldbin=&bin
|
||||||
|
" set new options
|
||||||
|
setlocal binary " make sure it overrides any textwidth, etc.
|
||||||
|
let &ft="xxd"
|
||||||
|
" set status
|
||||||
|
let b:editHex=1
|
||||||
|
" switch to hex editor
|
||||||
|
%!xxd
|
||||||
|
else
|
||||||
|
" restore old options
|
||||||
|
let &ft=b:oldft
|
||||||
|
if !b:oldbin
|
||||||
|
setlocal nobinary
|
||||||
|
endif
|
||||||
|
" set status
|
||||||
|
let b:editHex=0
|
||||||
|
" return to normal editing
|
||||||
|
%!xxd -r
|
||||||
|
endif
|
||||||
|
" restore values for modified and read only state
|
||||||
|
let &mod=l:modified
|
||||||
|
let &readonly=l:oldreadonly
|
||||||
|
let &modifiable=l:oldmodifiable
|
||||||
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user