如何为使用 :registers 命令打开的缓冲区创建自动命令

How to create autocommand for the buffer that is opened with the :registers command

我正在尝试为发出 :registers 命令时打开的缓冲区创建一个自动命令(或通过任何可以映射以显示它的快捷方式或命令)。我想给一些线条涂上不同的颜色(但这不是问题所在)。 问题是我不知道如何检测这个事件

我根据我能想到的与缓冲区相关的所有事件创建了这个用于调试的代码片段(打印到带有 id 3 的缓冲区、缓冲区名称和缓冲区 id),而对于寄存器缓冲区它什么都不做...

function EchoBuf()
  call appendbufline(3, 1, bufname())
  call appendbufline(3, 2, bufnr("%"))
endfunction

autocmd WinEnter,BufAdd,BufNew,BufRead,BufEnter * call EchoBuf()

:registers 不会打开缓冲区,它会打开 :help pager,这不会触发任何事件。

但是你可以在 :help CmdlineLeave:help getcmdline() 的帮助下破解一些东西:

function! DoSomethingWhenIWantToLookAtMyRegisters()
    if getcmdline() =~ '^reg'
        echomsg 'Here is the list of registers and their content'
    endif
endfunction

augroup MyStuff
    autocmd!
    autocmd CmdlineLeave * call DoSomethingWhenIWantToLookAtMyRegisters()
augroup END

至于在 :registers 中为线条着色,您最好自己将数据填充到缓冲区中,并为其分配您自己的语法。