neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 93a8acb1b8049867d9ab459de3e9f8feadc42c1c
parent 595b4cc48eaad3cd5b6bb018382807bdecf0cf45
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Fri, 20 Feb 2026 09:18:23 +0800

vim-patch:9.2.0033: filetype: sh filetype used for env files

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

https://github.com/vim/vim/commit/d0fa375629b1bfdb8dc054894ca81d7473268455

Co-authored-by: DuckAfire <155199080+duckafire@users.noreply.github.com>

Diffstat:
Mruntime/lua/vim/filetype.lua | 5++++-
Aruntime/syntax/env.vim | 28++++++++++++++++++++++++++++
Mtest/old/testdir/test_filetype.vim | 3++-
3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua @@ -446,6 +446,7 @@ local extension = { lc = 'elsa', elv = 'elvish', ent = detect.ent, + env = 'env', epp = 'epuppet', erl = 'erlang', hrl = 'erlang', @@ -1151,7 +1152,6 @@ local extension = { cygport = detect.bash, ebuild = detect.bash, eclass = detect.bash, - env = detect.sh, envrc = detect.sh, ksh = detect.ksh, sh = detect.sh, @@ -1627,6 +1627,7 @@ local filename = { Earthfile = 'earthfile', ['.editorconfig'] = 'editorconfig', ['elinks.conf'] = 'elinks', + ['.env'] = 'env', ['rebar.config'] = 'erlang', ['mix.lock'] = 'elixir', ['filter-rules'] = 'elmfilt', @@ -2652,11 +2653,13 @@ local pattern = { ['^%.cshrc'] = detect.csh, ['^%.login'] = detect.csh, ['^%.notmuch%-config%.'] = 'dosini', + ['^%.env%.'] = 'env', ['^%.gitsendemail%.msg%.......$'] = 'gitsendemail', ['^%.kshrc'] = detect.ksh, ['^%.article%.%d+$'] = 'mail', ['^%.letter%.%d+$'] = 'mail', ['^%.reminders'] = starsetf('remind'), + ['^%.envrc%.'] = detect.sh, ['^%.tcshrc'] = detect.tcsh, ['^%.zcompdump'] = starsetf('zsh'), }, diff --git a/runtime/syntax/env.vim b/runtime/syntax/env.vim @@ -0,0 +1,28 @@ +" 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" + diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim @@ -278,6 +278,7 @@ func s:GetFilenameChecks() abort \ 'elmfilt': ['filter-rules'], \ 'elsa': ['file.lc'], \ 'elvish': ['file.elv'], + \ 'env': ['.env', '.env.file', 'file.env'], \ 'epuppet': ['file.epp'], \ 'erlang': ['file.erl', 'file.hrl', 'file.yaws', 'file.app.src', 'rebar.config'], \ 'eruby': ['file.erb', 'file.rhtml'], @@ -732,7 +733,7 @@ func s:GetFilenameChecks() abort \ 'sh': ['.bashrc', '.bash_profile', '.bash-profile', '.bash_logout', '.bash-logout', '.bash_aliases', '.bash-aliases', '.bash_history', '.bash-history', \ '/tmp/bash-fc-3Ozjlw', '/tmp/bash-fc.3Ozjlw', 'PKGBUILD', 'file.bash', '/usr/share/doc/bash-completion/filter.sh', \ '/etc/udev/cdsymlinks.conf', 'any/etc/udev/cdsymlinks.conf', 'file.bats', '.ash_history', 'any/etc/neofetch/config.conf', '.xprofile', - \ 'user-dirs.defaults', 'user-dirs.dirs', 'makepkg.conf', '.makepkg.conf', 'file.mdd', 'file.cygport', '.env', '.envrc', 'devscripts.conf', + \ 'user-dirs.defaults', 'user-dirs.dirs', 'makepkg.conf', '.makepkg.conf', 'file.mdd', 'file.cygport', '.envrc', '.envrc.file', 'file.envrc', 'devscripts.conf', \ '.devscripts', 'file.lo', 'file.la', 'file.lai'], \ 'shaderslang': ['file.slang'], \ 'sieve': ['file.siv', 'file.sieve'],