Can listings in the awful 'more' be displayed, instead, in a vim window?
Asked Answered
vim
O

2

1

In vim, neovim, when getting listings of mappings (eg :map), or when looking at self-defined or system defined variables (:let or :set), the results are display in a 'more' pager window.

There is probably some dim-recesses-of-time reason why (in vim) 'more' is used to display data - not vim. But what I, and I think millions of others, would like to know is this: How to make it stop!(?)

If, because 'reasons', vim just cannot display this data - in vim - then how can some solution from the third millennium, such as 'less', be used instead of the awful 'more'?

Obumbrate answered 2/3, 2018 at 23:17 Comment(3)
vim does not use more.Diannadianne
If indeed you have an implementation that is using more, 10 to 1 says it's actually using $PAGER and defaulting to more. Set your PAGER appropriately.Granddad
1. Vim doesn't use an external pager; it uses an internal one. 2. less is from the same millenium as more. 3. On some systems, more is even actually less.Slum
V
5

You can redir Vim output, it's a bad system but it works.

redir @a
silent map
redir end

then open a new buffer and paste the contents of a in insert mode:

ctrl-r a

You could create a custom command for this too to make map a dynamic string input.

Valued answered 2/3, 2018 at 23:24 Comment(0)
S
1

To extend on Andy Ray's answer, here is a custom command that will redirect the output of a Vim or external command into a scratch buffer:

function! Redir(cmd)
    for win in range(1, winnr('$'))
        if getwinvar(win, 'scratch')
            execute win . 'windo close'
        endif
    endfor
    if a:cmd =~ '^!'
        execute "let output = system('" . substitute(a:cmd, '^!', '', '') . "')"
    else
        redir => output
        execute a:cmd
        redir END
    endif
    vnew
    let w:scratch = 1
    setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile
    call setline(1, split(output, "\n"))
endfunction

command! -nargs=1 Redir silent call Redir(<f-args>)

Usage:

:Redir hi         " show the full output of command ':hi' in a scratch window
:Redir !ls -al    " show the full output of command ':!ls -al' in a scratch window

:Redir in action:

:Redir in action

What it does:

  1. Close any scratch window created by a previous execution of :Redir.
  2. Grab the output the desired command.
  3. Open a new buffer in a vertical window.
  4. Make the new buffer a scratch buffer.
  5. Insert the output of the desired command.
Slum answered 3/3, 2018 at 11:19 Comment(1)
That is very nice. This scratch buffer is similar to less. Search function is working. Thanks for sharing.Thant

© 2022 - 2024 — McMap. All rights reserved.