aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-10 13:02:12 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-08-10 17:28:02 +0800
commit5684c415b4857cce954d58b5a334b5abb70be9d2 (patch)
treebaaef29bec252187368a90d90587b1f32005fbd9
parent72e619ca92b527140e1323f4e281b7f3ad35f380 (diff)
downloadrneovim-5684c415b4857cce954d58b5a334b5abb70be9d2.tar.gz
rneovim-5684c415b4857cce954d58b5a334b5abb70be9d2.tar.bz2
rneovim-5684c415b4857cce954d58b5a334b5abb70be9d2.zip
vim-patch:6a500661a9cb
Improve the vimscript code in ":h hex-editing" Save and restore the view position before and after saving the buffer, respectively, to keep the current view of the xxd(1)'s hex dump unchanged after doing ":w", which previously caused the window to scroll back to the very beginning of the buffer. I believe it's needless to say how annoying and counterproductive that was. Get rid of the "Press ENTER or type command to continue" message, which was previously displayed after opening larger binary files. The use of "silent" and "redraw" commands is tailored specifically to avoid screen flickering, e.g. when doing ":w", which is caused by the buffer being filtered by an external command. Increase the number of octets per line, produced by xxd(1), from the default value of 16 to 32. This puts bigger chunks of the hex dump on the screen and makes the whole thing much more usable. While there, reformat the code to make it more readable, and use the long form of the commands and variables to make the code slightly more consistent and more understandable to newcomers. https://github.com/vim/vim/commit/6a500661a9cb7b57093cf1095aa67e9c4aabc709 Co-authored-by: Dragan Simic' via vim_dev <vim_dev@googlegroups.com>
-rw-r--r--runtime/doc/tips.txt28
1 files changed, 20 insertions, 8 deletions
diff --git a/runtime/doc/tips.txt b/runtime/doc/tips.txt
index 7d38b1e0f7..88528b0e4e 100644
--- a/runtime/doc/tips.txt
+++ b/runtime/doc/tips.txt
@@ -346,14 +346,26 @@ comma-separated list of extension(s) you find yourself wanting to edit: >
" vim -b : edit binary using xxd-format!
augroup Binary
- au!
- au BufReadPre *.bin let &bin=1
- au BufReadPost *.bin if &bin | %!xxd
- au BufReadPost *.bin set ft=xxd | endif
- au BufWritePre *.bin if &bin | %!xxd -r
- au BufWritePre *.bin endif
- au BufWritePost *.bin if &bin | %!xxd
- au BufWritePost *.bin set nomod | endif
+ autocmd!
+ autocmd BufReadPre *.bin set binary
+ autocmd BufReadPost *.bin
+ \ if &binary
+ \ | execute "silent %!xxd -c 32"
+ \ | set filetype=xxd
+ \ | redraw
+ \ | endif
+ autocmd BufWritePre *.bin
+ \ if &binary
+ \ | let s:view = winsaveview()
+ \ | execute "silent %!xxd -r -c 32"
+ \ | endif
+ autocmd BufWritePost *.bin
+ \ if &binary
+ \ | execute "silent %!xxd -c 32"
+ \ | set nomodified
+ \ | call winrestview(s:view)
+ \ | redraw
+ \ | endif
augroup END
==============================================================================