I have some functions and mappings that echo paragraphs of summary output for me to "take a pulse" on some things I'm working on.
I know that if it disappears before I finish perusing, I can use g< to view it again.
Now... I am hoping to capture that output. I can edit my mappings to create splits instead of echoing -- but 99% of the time I prefer just echo and go away.
I also do not want to create duplicate mappings... just more to remember.
Instead, for those very few times I want to capture that output so I can e-mail it, or compare it... I am hoping to capture the output of g<.
I have tried the following. Once this is figured out, the LastOut function could easily be edited to do something different (like create a split with the captured text):
function! LastOut() abort
norm g<
endfunction
When I run this via a mapping:
map <expr> <leader>zz LastOut()
I get an error in the output:
Error detected while processing function LastOut:
line 1:
E523: Not allowed here
That error, E523, is about the 'secure' option, so I am confused how it relates.
This works to simply re-display it:
map <expr> <leader>xx ':norm g<<cr>'
But this does NOT work to capture it:
map <expr> <leader>yy ':redir @"<cr>:norm g<<cr>:redir END<cr>'
The above mapping will re-display it each time it is invoked.
Also -- oddly - it will output more and more each time, appending a copy of the following 3 lines each time.
:redir @"
:norm g<
:redir END
_But_ -- the only thing going into `@"` each time is a `^J` character.
Any ideas? Or does anybody know the bit in the docs that explicitly say this is not possible?
PS: My vim version:
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jan 21 2023 23:28:50)
MS-Windows 64-bit GUI version with OLE support
Included patches: 1-1227
Compiled by appveyor@APPVYR-WIN
Huge version with GUI. Features included (+) or not (-):
:h g<-- The "g<" output is not redirected. – Maxim Kim Feb 16 '24 at 06:15echombe an option? Those are available in:messages– Maxim Kim Feb 16 '24 at 06:16