1

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 (-):
CrashNeb
  • 203
  • 1
  • 6

1 Answers1

1

Currently, the g< normal mode command cannot be redirected. We even have a test case in the Vim test-suite that is skipped, because it simply does not work.

This is also mentioned in the docummentation at :h g<:

The "g<" output is not redirected.

Christian Brabandt
  • 25,820
  • 1
  • 52
  • 77