Merge pull request #24639 from zeertzjq/vim-6a500661a9cb

vim-patch:6a500661a9cb,81b8bf5b4a33
This commit is contained in:
zeertzjq
2023-08-10 17:43:35 +08:00
committed by GitHub
2 changed files with 38 additions and 14 deletions

View File

@@ -346,14 +346,26 @@ comma-separated list of extension(s) you find yourself wanting to edit: >
" vim -b : edit binary using xxd-format! " vim -b : edit binary using xxd-format!
augroup Binary augroup Binary
au! autocmd!
au BufReadPre *.bin let &bin=1 autocmd BufReadPre *.bin set binary
au BufReadPost *.bin if &bin | %!xxd autocmd BufReadPost *.bin
au BufReadPost *.bin set ft=xxd | endif \ if &binary
au BufWritePre *.bin if &bin | %!xxd -r \ | execute "silent %!xxd -c 32"
au BufWritePre *.bin endif \ | set filetype=xxd
au BufWritePost *.bin if &bin | %!xxd \ | redraw
au BufWritePost *.bin set nomod | endif \ | 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 augroup END
============================================================================== ==============================================================================

View File

@@ -118,15 +118,27 @@ This switches on three very clever mechanisms:
*restore-cursor* *last-position-jump* > *restore-cursor* *last-position-jump* >
autocmd BufRead * autocmd FileType <buffer> ++once augroup RestoreCursor
\ if &ft !~# 'commit\|rebase' && line("'\"") > 1 && line("'\"") <= line("$") | exe 'normal! g`"' | endif autocmd!
autocmd BufRead * autocmd FileType <buffer> ++once
\ let s:line = line("'\"")
\ | if s:line >= 1 && s:line <= line("$") && &filetype !~# 'commit'
\ && index(['xxd', 'gitrebase'], &filetype) == -1
\ | execute "normal! g`\""
\ | endif
augroup END
Another autocommand. This time it is used after reading any file. The Another autocommand. This time it is used after reading any file. The
complicated stuff after it checks if the '" mark is defined, and jumps to it complicated stuff after it checks if the '" mark is defined, and jumps to it
if so. The backslash at the start of a line is used to continue the command if so. It doesn't do that for a commit or rebase message, which are likely
from the previous line. That avoids a line getting very long. a different one than last time, and when using xxd(1) to filter and edit
See |line-continuation|. This only works in a Vim script file, not when binary files, which transforms input files back and forth, causing them to
typing commands at the command-line. have dual nature, so to speak. See also |using-xxd|.
The backslash at the start of a line is used to continue the command from the
previous line. That avoids a line getting very long. See |line-continuation|.
This only works in a Vim script file, not when typing commands at the
command line.
> >
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis