]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0033: filetype: sh filetype used for env files v9.2.0033
authorDuckAfire <155199080+duckafire@users.noreply.github.com>
Thu, 19 Feb 2026 18:04:46 +0000 (18:04 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 19 Feb 2026 18:09:09 +0000 (18:09 +0000)
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: #19260

Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: DuckAfire <155199080+duckafire@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/filetype.vim
runtime/syntax/env.vim [new file with mode: 0644]
src/testdir/test_filetype.vim
src/version.c

index 470325d1380c8223171e295288188b5ab534b93e..4bdecfc7c3189076e73bdf1e8982253981b76e28 100644 (file)
@@ -1027,7 +1027,7 @@ au BufNewFile,BufRead *.decl,*.dcl,*.dec
 " NOTE: Patterns ending in a star are further down, these have lower priority.
 au BufNewFile,BufRead .bashrc,bashrc,bash.bashrc,.bash[_-]profile,.bash[_-]logout,.bash[_-]aliases,.bash[_-]history,bash-fc[-.],*.ebuild,*.bash,*.eclass,PKGBUILD,*.bats,*.cygport call dist#ft#SetFileTypeSH("bash")
 au BufNewFile,BufRead .kshrc,*.ksh call dist#ft#SetFileTypeSH("ksh")
-au BufNewFile,BufRead */etc/profile,.profile,*.sh,*.env{rc,} call dist#ft#SetFileTypeSH(getline(1))
+au BufNewFile,BufRead */etc/profile,.profile,*.sh,*.envrc,.envrc.* call dist#ft#SetFileTypeSH(getline(1))
 " Shell script (Arch Linux) or PHP file (Drupal)
 au BufNewFile,BufRead *.install
        \ if getline(1) =~ '<?php' |
@@ -1410,6 +1410,9 @@ au BufNewFile,BufRead drac.*                      call s:StarSetf('dracula')
 " Execline (s6) scripts
 au BufNewFile,BufRead s6-*                     call s:StarSetf('execline')
 
+" Env
+au BufNewFile,BufRead *.env,.env{.*,} setf env
+
 " Fvwm
 au BufNewFile,BufRead */.fvwm/*                        call s:StarSetf('fvwm')
 au BufNewFile,BufRead *fvwmrc*,*fvwm95*.hook
diff --git a/runtime/syntax/env.vim b/runtime/syntax/env.vim
new file mode 100644 (file)
index 0000000..a33eb04
--- /dev/null
@@ -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"
+
index 8da2b8f8ac4cf269befe21ed68cbb549434be125..56046037a040dcab2fa183fe870d82cb39d7e86c 100644 (file)
@@ -278,6 +278,7 @@ def s:GetFilenameChecks(): dict<list<string>>
     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'],
@@ -735,7 +736,7 @@ def s:GetFilenameChecks(): dict<list<string>>
     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'],
index eb20c82739fd8b0e99751f2038dd83486f030513..c2cc8137df977edc797393fcfa68416e1485f461 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    33,
 /**/
     32,
 /**/