CodeMirror nginx-renewed mode
This is a CodeMirror mode that brings
syntax highlighting for nginx configuration files.
Features:
- recognize more than 870 nginx directives, including those from OpenResty and nginx-plus;
- unrecognized directives remain accepted (they are shown in italic)
- highlight directives that are recognized but should not occur in the current scope;
- highlight regular expressions -- requires codemirror-mode-pcre
supported in: locations, maps, if conditions, rewrite statements and some proxy_* directives
- highlight variables in strings -- requires codemirror-mode-variables;
- highlight IP addresses -- requires codemirror-mode-ipaddr;
supported in: geo, set_real_ip_from
-
highlight Lua code -- requires CodeMirror's Lua mode; without it, strings and comments are still highlighted;
supported in: blocks (*_by_lua_block
)
not supported in: strings (*_by_lua
)
MIME types defined:
Options:
- initial_scope: string; default value: "main"
- check_directive_scope: boolean; default value: true
MIME types used to invoke nested modes:
- text/x-regex
- text/x-variables
- text/x-ip-address
- text/x-lua
Direct use
By default, codemirror-mode-nginx-renewed:
- assumes the textarea reflects nginx's main scope (i.e. the same scope as nginx.conf);
- checks whether each directive is allowed in the current scope.
The textareas below showcase codemirror-mode-nginx-renewed's capabilities.
Useful commands:
- Ctrl+d: toggle comments
- Ctrl+]: indent
- Ctrl+[: unindent
- Tab: auto-indent the current line or selection
- Shift+Tab: if something is selected, indent it by one indent unit; otherwise, insert a tab character
This textarea is a copy of lua-nginx-module's synopsis:
Custom use without a specific scope
Sometimes, it is hard, if not impossible, to predict the scope of an nginx snippet.
Typical cases:
- include files, which may contain directives suited for various scopes;
- the output of "nginx -T", which may combine many files and thus many scopes.
To deal with these situations, state "check_directive_scope: false" when configuring codemirror-mode-nginx-renewed.
Custom use with specific scopes
By playing with the "initial_scope" setting, it is possible to change the nginx scope of the textarea.
initial_scope defaults to "main" and can take various values reflecting the desired scope.
Examples:
- main/events
- main/http/server/location/limit_except
- main/http/server/location/if
- main/http/server/location/types
- main/http/server/if
- main/mail/server
- main/stream/upstream
Other examples and demonstrations follow.
main/http/map
main/http/geo
main/http/types
main/http/server
main/http/server/location
main/http/upstream