Automatic commands

Autocommands are a way to automatically execute code when certain events happen.

:au :autocmd :au[tocmd]

Execute commands automatically on events.

:au[tocmd] event pat cmd

If the -javascript (short name -js) option is specified, cmd is executed as JavaScript code, with any supplied arguments available as variables.

Add cmd to the list of commands &liberator.appname; will execute on event for a URL matching pat:

  • :autocmd[!] events pat: list/remove autocommands filtered by events and pat
  • :autocmd[!] events: list/remove autocommands matching events
  • :autocmd[!] pat: list/remove autocommands matching pat
  • :autocmd[!]: list/remove all autocommands

Available events:

pat is a regular expression, use .* if you want to match all URLs.

This differs from Vim which uses a glob rather than a regex for pat.

The following keywords are available where relevant:

:doautoa :doautoall :doautoa[ll] event url

Apply the autocommands matching the specified URL to all buffers. If no url is specified use the current URL.

:do :doautocmd :do[autocmd] event url

Apply the autocommands matching the specified URL to the current buffer. If no url is specified use the current URL.

Examples

Enable passthrough mode on all Google sites:

:autocmd LocationChange .* js modes.passAllKeys = /google\.com/.test(buffer.URL)

Enable passthrough mode on some Google sites:

:autocmd LocationChange .* js modes.passAllKeys = /(www|mail)\.google\.com/.test(buffer.URL)

Set the filetype to mail when editing email at Gmail:

:autocmd LocationChange .* :set editor=gvim -f :autocmd LocationChange mail\\.google\\.com :set editor=gvim -f -c 'set ft=mail'