Home Explore Blog CI



neovim

5th chunk of `runtime/doc/tips.txt`
fff31a6b733e0ee4b8ccf3b23f646b8c0ae37d7d06c7f6520000000100000a7d
 must make sure that $VIMRUNTIME is set to where the other Vim files are,
when they are not in the same location as the compressed "doc" directory.  See
|$VIMRUNTIME|.

==============================================================================
Hex editing					*hex-editing* *using-xxd*

See section |23.3| of the user manual.

If one has a particular extension that one uses for binary files (such as exe,
bin, etc), you may find it helpful to automate the process with the following
bit of autocmds for your |init.vim|.  Change that "*.bin" to whatever
comma-separated list of extension(s) you find yourself wanting to edit: >

	" vim -b : edit binary using xxd-format!
	augroup Binary
	  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

==============================================================================
Using <> notation in autocommands			*autocmd-<>*

The <> notation is not recognized in the argument of an :autocmd.  To avoid
having to use special characters, you could use a self-destroying mapping to
get the <> notation and then call the mapping from the autocmd.  Example:

						*map-self-destroy*  >
 " This is for automatically adding the name of the file to the menu list.
 " It uses a self-destroying mapping!
 " 1. use a line in the buffer to convert the 'dots' in the file name to \.
 " 2. store that in register '"'
 " 3. add that name to the Buffers menu list
 " WARNING: this does have some side effects, like overwriting the
 " current register contents and removing any mapping for the "i" command.
 "
 autocmd BufNewFile,BufReadPre * nmap i :nunmap i<CR>O<C-R>%<Esc>:.g/\./s/\./\\./g<CR>0"9y$u:menu Buffers.<C-R>9 :buffer <C-R>%<C-V><CR><CR>
 autocmd BufNewFile,BufReadPre * normal i

Another method, perhaps better, is to use the ":execute" command.  In the
string you can use the <> notation by preceding it with a backslash.  Don't
forget to double the number of existing backslashes and put a backslash before
'"'.
>
  autocmd BufNewFile,BufReadPre * exe "normal O\<C-R>%\<Esc>:.g/\\./s/\\./\\\\./g\<CR>0\"9y$u:menu Buffers.\<C-R>9 :buffer \<C-R>%\<C-V>\<CR>\<CR>"

For a real buffer menu, user functions should be used (see |:function|), but
then the <>

Title: Hex Editing with Vim and Using <> Notation in Autocommands
Summary
This section provides instructions for hex editing using Vim and the xxd tool, including setting up autocmds for handling binary files. It also explains how to use the <> notation within autocommands, which is not directly supported, by either using a self-destroying mapping or the ":execute" command with proper escaping.