Commit: patch 9.2.0649: filetype: tf files sometimes incorrectly recognized

1 view
Skip to first unread message

Christian Brabandt

unread,
Jun 14, 2026, 12:15:14 PM (15 hours ago) Jun 14
to vim...@googlegroups.com
patch 9.2.0649: filetype: tf files sometimes incorrectly recognized

Commit: https://github.com/vim/vim/commit/522a39a48962f43dabcd5e568c1ee78799599e94
Author: Christian Brabandt <c...@256bit.org>
Date: Sun Jun 14 16:03:22 2026 +0000

patch 9.2.0649: filetype: tf files sometimes incorrectly recognized

Problem: filetype: tf files sometimes incorrectly recognized
(Christian Robinson)
Solution: Add support for g;filetype_tf variable to override detection,
re-write the filetype detection loop

closes: #20510

Supported by AI

Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index f59d95af4..8de017621 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -3,7 +3,7 @@ vim9script
# Vim functions for file type detection
#
# Maintainer: The Vim Project <https://github.com/vim/vim>
-# Last Change: 2026 May 29
+# Last Change: 2026 Jun 14
# Former Maintainer: Bram Moolenaar <Br...@vim.org>

# These functions are moved here from runtime/filetype.vim to make startup
@@ -1498,14 +1498,25 @@ enddef

# Determine if a *.tf file is TF mud client or terraform
export def FTtf()
- var numberOfLines = line('$')
- for i in range(1, numberOfLines)
- var currentLine = trim(getline(i))
- var firstCharacter = currentLine[0]
- if firstCharacter !=? ";" && firstCharacter !=? "/" && firstCharacter !=? ""
- setf terraform
- return
+ if exists("g:filetype_tf")
+ exe "setf " .. g:filetype_tf
+ return
+ endif
+
+ var continuation: bool = false
+ for lnum in range(1, min([line("$"), 100]))
+ var line = getline(lnum)
+ # TF supports backslash line continuation, so a continued line may begin
+ # with any character. Only test the first character of a line that does
+ # not continue a previous one.
+ if !continuation
+ var firstchar = trim(line)[0]
+ if firstchar !=? ";" && firstchar !=? "/" && firstchar !=? ""
+ setf terraform
+ return
+ endif
endif
+ continuation = line =~ '\$'
endfor
setf tf
enddef
diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt
index 36edcaab2..231562758 100644
--- a/runtime/doc/filetype.txt
+++ b/runtime/doc/filetype.txt
@@ -1,4 +1,4 @@
-*filetype.txt* For Vim version 9.2. Last change: 2026 Jun 13
+*filetype.txt* For Vim version 9.2. Last change: 2026 Jun 14


VIM REFERENCE MANUAL by Bram Moolenaar
@@ -183,6 +183,7 @@ variables can be used to overrule the filetype used for certain extensions:
*.sys g:filetype_sys
*.sh g:bash_is_sh |ft-sh-syntax|
*.tex g:tex_flavor |ft-tex-plugin|
+ *.tf g:filetype_tf
*.typ g:filetype_typ
*.v g:filetype_v
*.w g:filetype_w |ft-cweb-syntax|
diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim
index 30f803f24..61a72fd1f 100644
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -2546,6 +2546,25 @@ func Test_tf_file_v2()
call assert_equal('terraform', &filetype)
bwipe!

+ " A backslash continuation line may start with any character
+ let lines =<< trim END
+ /def greet = \
+ plain words that start the continued line
+ ;a comment
+ END
+ call writefile(lines, "Xfile.tf", "D")
+ split Xfile.tf
+ call assert_equal('tf', &filetype)
+ bwipe!
+
+ " The user override wins regardless of content
+ let g:filetype_tf = 'terraform'
+ call writefile([';;; looks like tf'], 'Xfile.tf', 'D')
+ split Xfile.tf
+ call assert_equal('terraform', &filetype)
+ bwipe!
+ unlet g:filetype_tf
+
filetype off
endfunc

diff --git a/src/version.c b/src/version.c
index 329bf5a73..392bae84c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -759,6 +759,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 649,
/**/
648,
/**/
Reply all
Reply to author
Forward
0 new messages