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.


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
  • That's amazing, thank you! In order to get all of the output i had to page down until the end, but that was not too much work. Nov 9 '20 at 11:45
  • You're welcome. I think there's a way to avoid that but in the meantime just hit G like in a buffer to go straight to the end.
    – B Layer
    Nov 9 '20 at 11:51
  • :set nomore will disable paging.
    – B Layer
    Nov 9 '20 at 11:53
  • you can also use :sil <cmd> to disable paging Nov 9 '20 at 12:30
  • @ChristianBrabandt That'll block all output. If that still works with redir that's even better! [Verified and added. Thanks.]
    – B Layer
    Nov 9 '20 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.