I want to do something like

```vim
let colors = execute(":highlight")

```

This is obviously incorrect; all I can do is `execute(":highlight")` which will open a window, but what I really need is to get the contents of that window into a variable — much like a `system()` call would do for external commands. Can this be done?
['https://Stackoverflow.com/questions/7434865', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/45959/']
There is a command called `:redir` that is specifically designed to
capture the output of one or more commands into a file, a register, or
a variable. The latter option is what we want in this case:

```
:redir => colors
:silent highlight
:redir END

```

To see the complete list of the ways to invoke the command, refer to
`:help :redir`. See also [my answer](https://stackoverflow.com/a/5961837/254635) to the question “[Extending
a highlighting group in Vim](https://stackoverflow.com/q/5172323/254635)” for another practical use of `:redir`.
```
let colors = lh#askvim#exe(':hi')

```

[Which](https://github.com/LucHermitte/lh-vim-lib/blob/master/autoload/lh/askvim.vim#L59) just encapsulates [`:redir`](http://vimhelp.appspot.com/various.txt.html#%3aredir). Or even better: 

```
let colors = lh#askvim#execute(':hi')

```

[which](https://github.com/LucHermitte/lh-vim-lib/blob/master/autoload/lh/askvim.vim#L73) returns the result as a list variable, either through `:redir` if we have no choice, or through [`execute()`](http://vimhelp.appspot.com/eval.txt.html#execute%28%29) when it's defined. This new approach is to be prefered as it has less undesired side effects.