# http://fishshell.com # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](fish) %{ set-option buffer filetype fish } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=fish %{ require-module fish hook window ModeChange pop:insert:.* -group fish-trim-indent fish-trim-indent hook window InsertChar .* -group fish-indent fish-indent-on-char hook window InsertChar \n -group fish-insert fish-insert-on-new-line hook window InsertChar \n -group fish-indent fish-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window fish-.+ } } hook -group fish-highlight global WinSetOption filetype=fish %{ add-highlighter window/fish ref fish hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/fish } } provide-module fish %{ # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/fish regions add-highlighter shared/fish/code default-region group add-highlighter shared/fish/double_string region (? d } } } define-command -hidden fish-indent-on-char %{ evaluate-commands -no-hooks -draft -itersel %{ # align middle and end structures to start and indent when necessary try %{ execute-keys -draft x^\h*(else)$^\h*(if)s\A|.\z1 } try %{ execute-keys -draft x^\h*(end)$^\h*(begin|for|function|if|switch|while)s\A|.\z1 } try %{ execute-keys -draft x^\h*(case)$^\h*(switch)s\A|.\z1 } } } define-command -hidden fish-insert-on-new-line %{ evaluate-commands -no-hooks -draft -itersel %{ # copy '#' comment prefix and following white spaces try %{ execute-keys -draft k x s ^\h*#\h* y jgh P } } } define-command -hidden fish-indent-on-new-line %{ evaluate-commands -no-hooks -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 } # indent after start structure try %{ execute-keys -draft kx^\h*(begin|case|else|for|function|if|while)\bj } } } }