neovim
neovim copied to clipboard
":read :cmd" reads :cmd output into a buffer
Problem
Vims' internal pager 'more' sucks: can't search when neovim opens output in it.
Expected behavior
ability to search when paging with neovims internal pager 'more'
Duplicate/part of https://github.com/neovim/neovim/issues/22478 See also https://github.com/neovim/neovim/issues/27811
And
For example open any help topic with :help and try searching with '/', you can't, can you?
Of course you can; :help opens a full buffer.
See also https://github.com/neovim/neovim/issues/5054
Proposal
A short-term, high-leverage, low-cost improvement would be to add :read :<cmd> which opens any :<cmd> output into a buffer. Bram also was favorable to that idea.
Would be nice to see a PR for that... Let's use this issue to track that idea.
Implementation notes
- One way to implement this is to re-use the internals of
:help execute(): https://github.com/neovim/neovim/blob/e049c6e4c08a141c94218672e770f86f91c27a11/src/nvim/eval/funcs.c#L1592-L1594- Or rather than directly using those internals, the C code can invoke vimscript:
execute(printf("put=execute('%s')", substitute(escape(<q-args>, '"')
- Or rather than directly using those internals, the C code can invoke vimscript:
- Note also that "mods" should be supported, i.e.
:split read :fooshould collect the output of:foobefore` splitting the window (otherwise this isn't useful). - A good place for tests would be
test/functional/ex_cmds/. There is currently noread_spec.luain there, but perhaps could usetest/functional/ex_cmds/write_spec.luaas a starting point.
For the sake of completeness, we already have :read at home: :put=execute('cmd') (just missing opening a new buffer). Of course, that is hard enough to know about (and even remember) for a shortcut to be valuable. In fact, we have previously discussed adding even more sugar in the form of, say :^ (which is still free real estate, iirc) in analogy to :=.
Open question: do we want to restrict this to Lua command (which, let's be honest, is the primary use case these days)? Or keep :read for vimscript and add :^ as Lua sugar?
The door is open for those questions, but adding :read :cmd in "vimscript" should be rather low-risk, and makes sense as a first step before the other stuff.
do we want to restrict this to Lua command
why? Ex commands for interactive command line shouldn't require (explicit use of) Lua.
why? Ex commands for interactive command line shouldn't require (explicit use of) Lua.
Because that allows us to make the sugar sweeter, as we did for := (which is arguably the most frequent -- but of course not the only -- way to see the pager these days). The point of my comment is to make sure whatever is added also applies to :=.
The point of my comment is to make sure whatever is added also applies to
:=.
I would expect :read :=... to be supported since any :read :<cmd> should simply capture the output of whatever follows :read :.
https://github.com/AndrewRadev/bufferize.vim does this which is just a light wrapper around :redir.
We could upstream a form of this without introducing another ex command in C.
We could upstream a form of this without introducing another ex command in C.
That's the idea. And this doesn't introduce any new Ex command, it only enhances :read in the same way that it already works for :read !....
:read is a basic feature and it absolutely doesn't make sense to introduce a new command or interface for this. :read is the interface for this kind of thing.
The impl of :read doesn't need to be in C, but that's just a detail anyway. The interface is what matters.
Reading output of cmd-line command into a buffer is useful.
It does not solve the original issue, (which is now renamed to something completely different:))
The use case is to quickly lookup info in large, read-only info pages. Reading the output of a command into a buffer so that you can do search is not it.
Example is :highlight command. It outputs hundreds of lines that need to be searchable to be useful.
If paged output of the command would open in a split window (as :help does) that would be a solution I guess.
... which is exactly what is being proposed here.
Also, I mentioned that https://github.com/neovim/neovim/issues/5054 tracks more elaborate "builtin pager" changes. That is why I renamed this issue to track the more near-term solution of enhancing :read.
I had a go at this, but I am not sure I have the right approach. Could I get some feedback before going any further please?
https://github.com/bwalshe/neovim/blob/read_cmd_to_buffer/src/nvim/ex_docmd.c#L5643
I had a go at this, but I am not sure I have the right approach. Could I get some feedback before going any further please?
https://github.com/bwalshe/neovim/blob/read_cmd_to_buffer/src/nvim/ex_docmd.c#L5643
Your best option will be to open a draft PR. People will give feedback there