Skip to content

Indent and prettify

Phidica Veia edited this page Oct 26, 2019 · 8 revisions

This plugin provides a command to automatically indent and prettify your fish code, powered by fish_indent (a program that comes with fish). The indentation will respect your view's current tab size preferences, including your choice of spaces or tabs.

Under normal execution the entire file will be formatted, but by selecting some text before running the command you can limit the formatting to only that section or sections (multiple individual selection regions are permitted).

How to use

There are several ways to format the active fish file:

  • Press ctrl+alt+i.
  • Save the file (if you have turned on this feature).
  • Press your build system shortcut (ctrl+b by default), and if prompted select fish - Indent and Prettify in the quick panel.
  • Open the command palette (shift+ctrl+p by default) and lazy type fish: Indent and Prettify to find and select it.
  • Add your own keyboard shortcut by modifying the keymap (Preferences > Key Bindings) and adding a section like this:
    { "keys": ["ctrl+alt+i"], "command": "do_fish_indent", "context":
      [
        {"key": "selector", "operator": "equal", "operand": "source.shell.fish"}
      ]
    }
    Just change the ctrl+alt+i string; refer to the official Sublime Text documentation on the topic of key bindings.

Run when saved

(Modify via fish settings.) This feature will format a file every time you save it. It is disabled by default; to enable it, set indent_on_save to true.

To prevent a certain file being formatted on save, add the basename (that is, the filename with leading directory components removed) to the indent_on_save_blacklist list. There is currently no support for globbing characters (*, ?) or regular expressions in the blacklist.

Troubleshooting

If fish is installed in a nonstandard location on your system, then you must manually configure its install directory by setting fish_directory.

User guide

Development

Clone this wiki locally