hook global BufCreate .*/\.ssh/config %{ set-option buffer filetype ssh } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=ssh %{ require-module ssh set-option window static_words %opt{ssh_static_words} hook window InsertChar \n -group ssh-insert ssh-insert-on-new-line hook window InsertChar \n -group ssh-indent ssh-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window ssh-.+ } } hook -group ssh-highlight global WinSetOption filetype=ssh %{ add-highlighter window/ssh ref ssh hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ssh } } provide-module ssh %@ # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/ssh regions add-highlighter shared/ssh/code default-region group add-highlighter shared/ssh/double_string region %{(? try %{ evaluate-commands -draft -save-regs '/"' %{ # Ensure previous line is a comment execute-keys -draft kxs^\h*#+\h* # now handle the coment continuation logic try %{ # try and match a regular block comment, copying the prefix execute-keys -draft -save-regs '' k x 1s^(\h*#+\h*)\S.*$ y execute-keys -draft P } catch %{ try %{ # try and match a regular block comment followed by a single # empty comment line execute-keys -draft -save-regs '' kKx 1s^(\h*#+\h*)\S+\n\h*#+\h*$ y execute-keys -draft P } catch %{ try %{ # try and match a pair of empty comment lines, and delete # them if we match execute-keys -draft kKx ^\h*#+\h*\n\h*#+\h*$ } catch %{ # finally, we need a special case for a new line inserted # into a file that consists of a single empty comment - in # that case we can't expect to copy the trailing whitespace, # so we add our own execute-keys -draft -save-regs '' k x1s^(\h*#+)\h*$ y execute-keys -draft P execute-keys -draft i } } } } # trim trailing whitespace on the previous line try %{ execute-keys -draft k x s\h+$ d } } } } define-command -hidden ssh-indent-on-new-line %< evaluate-commands -draft -itersel %< # preserve previous line indent try %{ execute-keys -draft K } # cleanup trailing whitespaces from previous line try %{ execute-keys -draft k x s \h+$ d } > > @