]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0742: filetype: SSH keys and related filetypes not recognized v9.2.0742
authorFionn Fitzmaurice <git@fionn.computer>
Sun, 28 Jun 2026 17:04:55 +0000 (17:04 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 28 Jun 2026 17:08:01 +0000 (17:08 +0000)
Problem:  filetype: SSH keys and related filetypes not recognized
Solution: Detect sshpublickey, sshknownhosts sshauthorizedkeys and
          sshallowedsigners filetypes, add syntax scripts for those
          filetypes (Fionn Fitzmaurice)

This adds syntax highlighting for SSH public keys, as well as related
filetypes derived from this (SSH authorized keys, SSH known hosts and
SSH allowed signers).

Also add filetype detection based on the path and name.

closes: #20635

Signed-off-by: Fionn Fitzmaurice <git@fionn.computer>
Signed-off-by: Christian Brabandt <cb@256bit.org>
.github/MAINTAINERS
runtime/filetype.vim
runtime/syntax/sshallowedsigners.vim [new file with mode: 0644]
runtime/syntax/sshauthorizedkeys.vim [new file with mode: 0644]
runtime/syntax/sshknownhosts.vim [new file with mode: 0644]
runtime/syntax/sshpublickey.vim [new file with mode: 0644]
src/testdir/test_filetype.vim
src/version.c

index f2200c4ac663256ea9f6148da532a249aa9156f7..0afec653f2d9239adfa967523934d1f87c78efcc 100644 (file)
@@ -699,8 +699,12 @@ runtime/syntax/sqloracle.vim                               @chrisbra
 runtime/syntax/squirrel.vim                            @zenmatic
 runtime/syntax/srt.vim                                 @ObserverOfTime
 runtime/syntax/ssa.vim                                 @ObserverOfTime
+runtime/syntax/sshallowedsigners.vim                   @fionn
+runtime/syntax/sshauthorizedkeys.vim                   @fionn
 runtime/syntax/sshconfig.vim                           @Jakuje
 runtime/syntax/sshdconfig.vim                          @Jakuje
+runtime/syntax/sshpublickey.vim                                @fionn
+runtime/syntax/sshknownhosts.vim                       @fionn
 runtime/syntax/sudoers.vim                             @e-kwsm
 runtime/syntax/svn.vim                                 @hdima
 runtime/syntax/swayconfig.vim                          @jamespeapen
index 7a39bdd8bf5235beeb89075d81def749f7b0ca0a..d4baad6d8c6a75b176bebb58a833ac4f23726a34 100644 (file)
@@ -1107,6 +1107,12 @@ au BufNewFile,BufRead */etc/ssh/ssh_config.d/*.conf              setf sshconfig
 " OpenSSH server configuration
 au BufNewFile,BufRead */etc/ssh/sshd_config.d/*.conf   setf sshdconfig
 
+" OpenSSH public keys, authorized keys, signing keys, host keys
+au BufNewFile,BufRead */.ssh/?*.pub,/etc/ssh/?*.pub               setf sshpublickey
+au BufNewFile,BufRead */.ssh/authorized_keys                      setf sshauthorizedkeys
+au BufNewFile,BufRead */.ssh/known_hosts,/etc/ssh/ssh_known_hosts setf sshknownhosts
+au BufNewFile,BufRead allowed_signers,*.allowed_signers           setf sshallowedsigners
+
 " OpenVPN configuration
 au BufNewFile,BufRead */openvpn/*/*.conf       setf openvpn
 
diff --git a/runtime/syntax/sshallowedsigners.vim b/runtime/syntax/sshallowedsigners.vim
new file mode 100644 (file)
index 0000000..8392747
--- /dev/null
@@ -0,0 +1,31 @@
+" Vim syntax file
+" Language:     OpenSSH allowed signers file
+" Author:       Fionn Fitzmaurice (github.com/fionn)
+" Maintainer:   Fionn Fitzmaurice (github.com/fionn)
+" License:      Vim & Apache 2.0
+
+if exists("b:current_syntax")
+    finish
+endif
+
+syn match sshAllowedSignersPrincipal "!\?[a-zA-Z0-9.*?_+-]\+@[a-zA-Z0-9.*?-]\+" nextgroup=sshAllowedSignersPrincipalSeparator,sshAllowedSignersOptions,sshKeyType skipwhite
+syn match sshAllowedSignersPrincipalSeparator "," contained nextgroup=sshAllowedSignersPrincipal
+
+syn region sshAllowedSignersOptions start="[a-z]" end="\s\@=" contains=@sshAllowedSignersOption nextgroup=sshKeyType skipwhite oneline contained
+syn cluster sshAllowedSignersOption contains=sshAllowedSignersOptionKeyword,sshAllowedSignersOptionSeparator,sshAllowedSignersOptionAssignment,sshAllowedSignersOptionValue
+syn keyword sshAllowedSignersOptionKeyword namespaces cert-authority valid-after valid-before contained
+syn match sshAllowedSignersOptionSeparator "," contained
+syn match sshAllowedSignersOptionAssignment "=" contained
+syn match sshAllowedSignersOptionValue '"\(\\\"\|[^"]\)*"' contained
+
+runtime! syntax/sshpublickey.vim
+
+hi def link sshAllowedSignersPrincipal Identifier
+hi def link sshAllowedSignersPrincipalSeparator Punctuation
+
+hi def link sshAllowedSignersOptionKeyword Keyword
+hi def link sshAllowedSignersOptionSeparator Punctuation
+hi def link sshAllowedSignersOptionAssignment Operator
+hi def link sshAllowedSignersOptionValue String
+
+let b:current_syntax = "sshallowedsigners"
diff --git a/runtime/syntax/sshauthorizedkeys.vim b/runtime/syntax/sshauthorizedkeys.vim
new file mode 100644 (file)
index 0000000..cf6b912
--- /dev/null
@@ -0,0 +1,25 @@
+" Vim syntax file
+" Language:     OpenSSH authorized keys file
+" Author:       Fionn Fitzmaurice (github.com/fionn)
+" Maintainer:   Fionn Fitzmaurice (github.com/fionn)
+" License:      Vim & Apache 2.0
+
+if exists("b:current_syntax")
+    finish
+endif
+
+syn region sshAuthorizedKeyOptions start="^[a-z]" end="\s" contains=@sshAuthorizedKeyOption nextgroup=sshKeyType skipwhite oneline
+syn cluster sshAuthorizedKeyOption contains=sshAuthorizedKeyOptionKeyword,sshAuthorizedKeyOptionSeparator,sshAuthorizedKeyOptionAssignment,sshAuthorizedKeyOptionValue
+syn match sshAuthorizedKeyOptionKeyword "[a-z-]\+" contained
+syn match sshAuthorizedKeyOptionSeparator "," contained
+syn match sshAuthorizedKeyOptionAssignment "=" contained
+syn match sshAuthorizedKeyOptionValue '"\(\\\"\|[^"]\)*"' contained
+
+runtime! syntax/sshpublickey.vim
+
+hi def link sshAuthorizedKeyOptionKeyword Keyword
+hi def link sshAuthorizedKeyOptionSeparator Punctuation
+hi def link sshAuthorizedKeyOptionAssignment Operator
+hi def link sshAuthorizedKeyOptionValue String
+
+let b:current_syntax = "sshauthorizedkeys"
diff --git a/runtime/syntax/sshknownhosts.vim b/runtime/syntax/sshknownhosts.vim
new file mode 100644 (file)
index 0000000..5d41deb
--- /dev/null
@@ -0,0 +1,27 @@
+" Vim syntax file
+" Language:     OpenSSH known hosts file
+" Author:       Fionn Fitzmaurice (github.com/fionn)
+" Maintainer:   Fionn Fitzmaurice (github.com/fionn)
+" License:      Vim & Apache 2.0
+
+if exists("b:current_syntax")
+    finish
+endif
+
+runtime! syntax/sshpublickey.vim
+
+syn match sshKnownHostsMarker "^@cert-authority\>" nextgroup=sshKnownHostsHostname,sshKnownHostsHashedHostname skipwhite
+syn match sshKnownHostsMarker "^@revoked\>" nextgroup=sshKnownHostsHostname,sshKnownHostsHashedHostname skipwhite
+
+syn match sshKnownHostsHostname "!\?[a-zA-Z0-9.*-]\+" nextgroup=sshKnownHostsHostnameSeparator,sshKeyType skipwhite
+syn match sshKnownHostsHostname "!\?\[[a-zA-Z0-9.*-]\+\]:[0-9]\{1,5}" nextgroup=sshKnownHostsHostnameSeparator,sshKeyType skipwhite
+syn match sshKnownHostsHostnameSeparator "," contained nextgroup=sshKnownHostsHostname
+
+syn match sshKnownHostsHashedHostname "|1|[a-zA-Z0-9/+]\+=\{,2}|[a-zA-Z0-9/+]\+=\{,2}" nextgroup=sshKeyType skipwhite
+
+hi def link sshKnownHostsMarker Statement
+hi def link sshKnownHostsHostname Identifier
+hi def link sshKnownHostsHostnameSeparator Punctuation
+hi def link sshKnownHostsHashedHostname Identifier
+
+let b:current_syntax = "sshknownhosts"
diff --git a/runtime/syntax/sshpublickey.vim b/runtime/syntax/sshpublickey.vim
new file mode 100644 (file)
index 0000000..200378a
--- /dev/null
@@ -0,0 +1,30 @@
+" Vim syntax file
+" Language:     OpenSSH public key
+" Author:       Fionn Fitzmaurice (github.com/fionn)
+" Maintainer:   Fionn Fitzmaurice (github.com/fionn)
+" License:      Vim & Apache 2.0
+
+if exists("b:current_syntax")
+    finish
+endif
+
+setlocal iskeyword=_,.,@-@,-,a-z,A-Z,48-57
+
+syn keyword sshKeyType ssh-ed25519 nextgroup=sshKeyBase64Encoded skipwhite
+syn keyword sshKeyType sk-ssh-ed25519@openssh.com nextgroup=sshKeyBase64Encoded skipwhite
+syn keyword sshKeyType ecdsa-sha2-nistp256 nextgroup=sshKeyBase64Encoded skipwhite
+syn keyword sshKeyType ecdsa-sha2-nistp384 nextgroup=sshKeyBase64Encoded skipwhite
+syn keyword sshKeyType ecdsa-sha2-nistp521 nextgroup=sshKeyBase64Encoded skipwhite
+syn keyword sshKeyType sk-ecdsa-sha2-nistp256@openssh.com nextgroup=sshKeyBase64Encoded skipwhite
+syn keyword sshKeyType ssh-rsa nextgroup=sshKeyBase64Encoded skipwhite
+
+syn match sshKeyBase64Encoded "AAAA[a-zA-Z0-9/+]\{64,8000}=\{,2}" contained nextgroup=sshKeyComment
+syn match sshKeyComment ".*$" contained
+
+syn match sshKeyComment "#.*$"
+
+hi def link sshKeyType Type
+hi def link sshKeyBase64Encoded String
+hi def link sshKeyComment Comment
+
+let b:current_syntax = "sshpublickey"
index 10a1d07d28359f1daabb65a6b0d4a2a5aba2c64f..87b640e02d7e9bce1683d843d5bff5a34351e7be 100644 (file)
@@ -790,8 +790,12 @@ def s:GetFilenameChecks(): dict<list<string>>
     srec: ['file.s19', 'file.s28', 'file.s37', 'file.mot', 'file.srec'],
     srt: ['file.srt'],
     ssa: ['file.ass', 'file.ssa'],
+    sshallowedsigners: ['any/allowed_signers', 'any/.allowed_signers', 'any/file.allowed_signers'],
+    sshauthorizedkeys: ['any/.ssh/authorized_keys'],
     sshconfig: ['ssh_config', '/.ssh/config', '/etc/ssh/ssh_config.d/file.conf', 'any/etc/ssh/ssh_config.d/file.conf', 'any/.ssh/config', 'any/.ssh/file.conf'],
     sshdconfig: ['sshd_config', '/etc/ssh/sshd_config.d/file.conf', 'any/etc/ssh/sshd_config.d/file.conf'],
+    sshpublickey: ['any/.ssh/file.pub', '/etc/ssh/file.pub'],
+    sshknownhosts: ['any/.ssh/known_hosts', '/etc/ssh/ssh_known_hosts'],
     st: ['file.st'],
     starlark: ['file.ipd', 'file.sky', 'file.star', 'file.starlark'],
     stata: ['file.ado', 'file.do', 'file.imata', 'file.mata'],
index ebe7f97093070152ed40785076940dd120b74a06..fe47a6e4e4b14d0284de9184241f3d2bec461f82 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    742,
 /**/
     741,
 /**/