31

I want to see the value of a variable, so I run the command

:let

Vim displays the results of this command using the --more-- pager.
How can I search this for a phrase, e.g. html?
I've looked the man page for the more pager which says +/ is used for search but it doesn't seem to work, neither does / as per the less pager.

the_velour_fog
  • 3,335
  • 3
  • 22
  • 40
  • 2
    AFAIK, it's a Vim internal command - it looks like 'more', but the program is not called by Vim (proof: it works in Windows, too). You can still write the beginning of a variable name, than ask Vim to complete it (e.g. with Ctrl-d). – VanLaser Dec 05 '15 at 08:30
  • thanks, when I type the variable name - or in fact pretty much anything - vim wont accept it - it just prompts with -- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit in the commandline. – the_velour_fog Dec 05 '15 at 08:34
  • 1
    Write :let then don't hit Enter, but Tab or Ctrl-d - you'll have a list of existing variables, displayed in "more" style - now hit Esc, write a few letters, hit Tab or Ctrl-d again ... and so on until you find the variable you want. Actually, to see the value of a variable, perhaps you should use echo instead? (Or set variable-name? for options) – VanLaser Dec 05 '15 at 08:43
  • 1
    very cool, both the Ctrl-d and the echo trick worked nicely, thanks! – the_velour_fog Dec 05 '15 at 09:03

3 Answers3

28

Vim 8 has a execute() command the allows you to get the output of a command. To see it to the current buffer do:

:put =execute('let')

For Vim 7 you can use capture.vim. It is a plugin that wraps the commands from @romainl's answer and lets you use it as

:Capture let
laktak
  • 2,933
  • 13
  • 27
  • thats good to know, thanks. I'll check it out when I upgrade. On vim 7 Im using steve losh's clam plugin to capture large amounts of output into a new buffer. it works well too – the_velour_fog Dec 01 '16 at 20:21
  • 1
    Both this answer and @romainl's are great for different uses. This one (:put =execute(…)) is what I will use when I want to run a command and get the output in the same buffer. If I want the output in a different buffer, I'll use :redir @a; :let; redir END. This is going to help me finally get my highlighting and syntax annoyances figured out after 20 years! – Bruno Bronosky Feb 02 '20 at 02:59
22

This is not the more pager, this is Vim's internal and minimalistic pager which doesn't have search capabilities.

But you can use the :redir command:

:redir @a    redirect output of following commands to register a
:let         list every current option and its value
G<CR>        go straight to the end of the listing and make it disappear
:redir END   stop redirection
:tabnew      open a new buffer in a new window in a new tab page
"ap          put from register a

… then use regular Vim commands.

romainl
  • 40,486
  • 5
  • 85
  • 117
0

Here is working solution (that romainl mentioned in comment under the answer):

Redirect the output of a Vim or external command into a scratch buffer

Description of this script is in this answer for question:

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

Described and used scratch buffer is similar to less command. Navigation and search function is available in it.


Checked in Vim with clipboard support:

VIM - Vi IMproved 8.1 (2018 May 18, compiled Dec 07 2023 15:42:49) Included patches: 1-213, 1840, 214-579, 1969, 580-1848, 4975, 5023, 2110, 1849-1854, 1857, 1855-1857, 1331, 1858, 1858-1859, 1873, 1860-1969, 1992, 1970-1992, 2010, 1993-2068, 2106, 2069-2106, 2108, 2107-2109, 2109-2111, 2111-2112, 2112-2269, 3612, 3625, 3669, 3741, 1847 under Ubuntu 20.04

sudo apt install vim
sudo apt install vim-gtk3

apt - How do I install vim-gnome on Ubuntu 19.10?