2

I would like to print all of my current autocmds to a file so that I can grep through and do further analysis.

From within vim, the list of autocmds can be found with :autocmd, but this prints to a pager within vim. I cannot grep the output of this command, and there are hundreds of entries for all of the ftdetect events.

This question also applies to other long paged output within vim, e.g. getting all mappings with :map, or highlight styles in the current buffer with :highlight.

Simon Walker
  • 123
  • 4

1 Answers1

3

You want the :redir family of commands. See :h :redir. For example...

:redir > /path/to/file

Then run :au. Then

:redir END

And the file will contain the same things you saw on the screen. This should work for any command that emits "messages" (echoes to the screen).

You can also append. And you can redirect to registers and variables. Again, look at the help for all the possibilities.

Update: FYI, if you're doing a redirect and the output is more than a page you'll have to intervene (Hit G. Definitely don't hit <space> a bunch of times!). You can disable paging, though:

:set nomore

That'll dump everything all at once. Re-enable with:

:set more

Update 2: Per @ChristianBrabandt, if you prepend :sil to the command then you won't have to deal with any output at all. So if you don't need the warm reassurance of text flashing by when you redirect...

:redir /path/to/file
:sil :au
:redir END
B Layer
  • 19,834
  • 2
  • 30
  • 57