mirror of
https://github.com/neovim/neovim.git
synced 2026-02-22 02:11:33 +10:00
Problem: filetype: sh filetype used for env files
Solution: Detect *.env and .env.* files as env filetype,
detect .envrc and .envrc.* as sh filetype,
include a simple env syntax script (DuckAfire)
Previously, .env files were handled by the shell syntax. While
functional, this limited the ability to support specific .env
implementations, such as CodeIgniter4 which allows dots in keys
(e.g., "foo.bar=0").
The new dedicated 'env' filetype and syntax script improves legibility
and prevents highlighting from breaking when encountering spaces.
Currently, the syntax does not support indentation; fields, variables,
and comments must start at the beginning of the line.
closes: vim/vim#19260
d0fa375629
Co-authored-by: DuckAfire <155199080+duckafire@users.noreply.github.com>
29 lines
848 B
VimL
29 lines
848 B
VimL
" Vim syntax file
|
|
" Language: env
|
|
" Maintainer: DuckAfire <duckafire@gmail.com>
|
|
" Last Change: 2026 Jan 27
|
|
" Version: 2
|
|
" Changelog:
|
|
" 0. Create syntax file.
|
|
" 1. Remove unused variable (g:main_syntax).
|
|
" 2. Apply changes required by github@dkearns
|
|
|
|
if exists("b:current_syntax")
|
|
finish
|
|
endif
|
|
|
|
syn match envField nextgroup=envValue /^\h\%(\w\|\.\)*/
|
|
syn region envValue matchgroup=Operator start=/=/ end=/$/
|
|
syn match envComment contains=envTodo,envTitles /^#.*$/
|
|
syn keyword envTodo contained CAUTION NOTE TODO WARN WARNING
|
|
syn match envTitle contained /^\s*#\s*\zs[A-Z0-9][A-Z0-9 ]*:/
|
|
|
|
hi def link envField Identifier
|
|
hi def link envValue String
|
|
hi def link envComment Comment
|
|
hi def link envTodo Todo
|
|
hi def link envTitle PreProc
|
|
|
|
let b:current_syntax = "env"
|
|
|