Skip to content

Commit d0fa375

Browse files
duckafirezeertzjq
authored andcommitted
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: #19260 Co-authored-by: zeertzjq <[email protected]> Signed-off-by: DuckAfire <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent f26a33d commit d0fa375

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

runtime/filetype.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ au BufNewFile,BufRead *.decl,*.dcl,*.dec
10271027
" NOTE: Patterns ending in a star are further down, these have lower priority.
10281028
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")
10291029
au BufNewFile,BufRead .kshrc,*.ksh call dist#ft#SetFileTypeSH("ksh")
1030-
au BufNewFile,BufRead */etc/profile,.profile,*.sh,*.env{rc,} call dist#ft#SetFileTypeSH(getline(1))
1030+
au BufNewFile,BufRead */etc/profile,.profile,*.sh,*.envrc,.envrc.* call dist#ft#SetFileTypeSH(getline(1))
10311031
" Shell script (Arch Linux) or PHP file (Drupal)
10321032
au BufNewFile,BufRead *.install
10331033
\ if getline(1) =~ '<?php' |
@@ -1410,6 +1410,9 @@ au BufNewFile,BufRead drac.* call s:StarSetf('dracula')
14101410
" Execline (s6) scripts
14111411
au BufNewFile,BufRead s6-* call s:StarSetf('execline')
14121412

1413+
" Env
1414+
au BufNewFile,BufRead *.env,.env{.*,} setf env
1415+
14131416
" Fvwm
14141417
au BufNewFile,BufRead */.fvwm/* call s:StarSetf('fvwm')
14151418
au BufNewFile,BufRead *fvwmrc*,*fvwm95*.hook

runtime/syntax/env.vim

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
" Vim syntax file
2+
" Language: env
3+
" Maintainer: DuckAfire <[email protected]>
4+
" Last Change: 2026 Jan 27
5+
" Version: 2
6+
" Changelog:
7+
" 0. Create syntax file.
8+
" 1. Remove unused variable (g:main_syntax).
9+
" 2. Apply changes required by github@dkearns
10+
11+
if exists("b:current_syntax")
12+
finish
13+
endif
14+
15+
syn match envField nextgroup=envValue /^\h\%(\w\|\.\)*/
16+
syn region envValue matchgroup=Operator start=/=/ end=/$/
17+
syn match envComment contains=envTodo,envTitles /^#.*$/
18+
syn keyword envTodo contained CAUTION NOTE TODO WARN WARNING
19+
syn match envTitle contained /^\s*#\s*\zs[A-Z0-9][A-Z0-9 ]*:/
20+
21+
hi def link envField Identifier
22+
hi def link envValue String
23+
hi def link envComment Comment
24+
hi def link envTodo Todo
25+
hi def link envTitle PreProc
26+
27+
let b:current_syntax = "env"
28+

src/testdir/test_filetype.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def s:GetFilenameChecks(): dict<list<string>>
278278
elmfilt: ['filter-rules'],
279279
elsa: ['file.lc'],
280280
elvish: ['file.elv'],
281+
env: ['.env', '.env.file', 'file.env'],
281282
epuppet: ['file.epp'],
282283
erlang: ['file.erl', 'file.hrl', 'file.yaws', 'file.app.src', 'rebar.config'],
283284
eruby: ['file.erb', 'file.rhtml'],
@@ -735,7 +736,7 @@ def s:GetFilenameChecks(): dict<list<string>>
735736
sh: ['.bashrc', '.bash_profile', '.bash-profile', '.bash_logout', '.bash-logout', '.bash_aliases', '.bash-aliases', '.bash_history', '.bash-history',
736737
'/tmp/bash-fc-3Ozjlw', '/tmp/bash-fc.3Ozjlw', 'PKGBUILD', 'file.bash', '/usr/share/doc/bash-completion/filter.sh',
737738
'/etc/udev/cdsymlinks.conf', 'any/etc/udev/cdsymlinks.conf', 'file.bats', '.ash_history', 'any/etc/neofetch/config.conf', '.xprofile',
738-
'user-dirs.defaults', 'user-dirs.dirs', 'makepkg.conf', '.makepkg.conf', 'file.mdd', 'file.cygport', '.env', '.envrc', 'devscripts.conf',
739+
'user-dirs.defaults', 'user-dirs.dirs', 'makepkg.conf', '.makepkg.conf', 'file.mdd', 'file.cygport', '.envrc', '.envrc.file', 'file.envrc', 'devscripts.conf',
739740
'.devscripts', 'file.lo', 'file.la', 'file.lai'],
740741
shaderslang: ['file.slang'],
741742
sieve: ['file.siv', 'file.sieve'],

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
33,
737739
/**/
738740
32,
739741
/**/

0 commit comments

Comments
 (0)