ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Fuzzy​File​Path

by sagold ST2/ST3

Autocomplete relative or absolute file paths in Sublime Text project folder

Details

Installs

  • Total 2K
  • Win 1K
  • OS X 1K
  • Linux 382
Mar 2 Mar 1 Feb 28 Feb 27 Feb 26 Feb 25 Feb 24 Feb 23 Feb 22 Feb 21 Feb 20 Feb 19 Feb 18 Feb 17 Feb 16 Feb 15 Feb 14 Feb 13 Feb 12 Feb 11 Feb 10 Feb 9 Feb 8 Feb 7 Feb 6 Feb 5 Feb 4 Feb 3 Feb 2 Feb 1 Jan 31 Jan 30 Jan 29 Jan 28 Jan 27 Jan 26 Jan 25 Jan 24 Jan 23 Jan 22 Jan 21 Jan 20 Jan 19 Jan 18 Jan 17 Jan 16
Windows 3 4 2 7 8 5 1 2 3 4 5 2 5 9 5 4 3 7 13 16 7 6 6 7 7 10 7 6 4 1 4 1 5 11 10 11 2 1 5 4 5 4 5 5 7 6
OS X 3 2 4 5 5 4 7 8 0 2 5 6 8 7 2 1 3 5 4 7 2 4 5 8 5 12 4 4 22 5 5 3 5 7 5 4 2 4 4 2 3 3 4 5 3 5
Linux 0 2 2 0 3 0 0 3 0 2 3 0 7 0 3 3 0 3 2 0 4 1 1 2 6 3 3 0 0 1 0 0 2 3 0 0 1 1 2 1 0 2 1 2 2 2

Readme

Source
raw.​githubusercontent.​com

FuzzyFilePath

Sublime Text Plugin

Fuzzy search filenames inside your current project directory. Highly customizable.

Basic settings support Html, Css and Javascript, but may be adjusted for every language

Breaking changes in 0.1.0

  • change exclude_folders items to be matched as regex
  • remove extensionsToSuggest, now being retrieved from scope settings
  • remove shortcut super+ctrl+space
  • remove option auto_trigger
  • remove option insertExtension. Should now be done by replace_on_insert
  • change and extend default scope rules
  • change absolute paths to start with “/name”
  • change path prefix (./, ../, /) now overwrites scope settings

Installation

Package Control

After Package Control installation, restart Sublime Text. Use the Command Palette cmd+shift+p (OS X) or ctrl+shift+p (Linux/Windows) and search for Package Control: Install Package. Wait until Package Control downloaded the latest package list and search for FuzzyFilePath.

github

in <SublimeConfig>/Packages/ call:
git clone https://github.com/sagold/FuzzyFilePath.git

Sublime Text 2

in <SublimeConfig>/Packages/FuzzyFilePath/ switch to Sublime Text 2 Branch with:
git checkout st2

Usage

Filepaths will be suggested if there is a matching scope-rule for the current context and its property auto is set to true. For a matching scope-rule, filepath completions may be forced (ignoring auto property) by the following shorcuts:

  • ctrl+alt+space inserts filepaths relative, overriding possible settings
  • ctrl+shift+space inserts filepaths absolute, overriding possible settings

The current string may modify the suggested filepaths by the following rules:

  • word suggests all matching files by the type (relative or absolute) as specified in the matched rule
  • ./ suggests matching files within the current directory and inserts selection relative
  • ../ suggests all matching files and inserts selection relative
  • /folder suggests all matching files and insert selection absolute

FuzzyFilePath is disabled for single files or files outside the opened folder.

Special Characters

If your projects contains filenames with special characters, consider modifying Sublime Texts word_separators.

i.e. in AngularJs filenames may start with $. In Sublime Text | Preferences | Settings - User add:

"word_separators": "./\\()\"'-:,.;<>~!@#%^&*|+=[]{}`~?"

Configuration

The default options, as always, should be set in user-settings:
Sublime Text | Preferences | Package Settings | FuzzyFilePath | Settings - User

Project specific settings may be set in Project | Edit Settings:

{
    "settings": {
        "FuzzyFilepath": {
            // adjusted settings
        }
    }
}

Settings

base_directory:String

Default base directory to use if set in scope-rule. i.e. "base_directory": "dev/src" will be used for relative or absolute filepath completions if scope-property scope: { "base_directory": true}.

disable_autocompletions:Boolean

Whenever Sublime Text queries completion suggestions, FuzzyFilePath will propose filepaths if the current query meets its requirements. This may conflict with other plugins. Set "disable_autocompletions": true to disable this automatic behaviour.

disable_keymap_actions:Boolean

Set "disable_keymap_actions": true to disable all FuzzyFilePath commands triggered by shortcuts. Default shortcut definitions are found in Sublime Text | Preferences | Package Settings | FuzzyFilePath | KeyBinding - Default. This may prevent conflicts with other plugins.

exclude_folders:Array

Skips scanning of given folders. This improves performance on startup (read files) and queries (filter file list). Folders are checked via regex, thus you need to escape all regex characters. i.e. "exclude_folders": ["node\\_modules] will ignore all files and folders in node_modules (highly recommended).

Settings Scopes:Array

Each object in scopes triggers a specific configuration for filepaths completions. Objects are iterated in the given order for the current scope-regex. If it matches the current scope, its configuration is used for filepath suggestions and insertions. Configuration properties are as follows:

scope:RegExp

A regular expression to test the current scope. In order to escape a regex character two backslashes are required: \\.. To lookup a scope within your source code, press alt+super+p. The current scope will be displayed in Sublime Text's status bar.

prefix:Array, style:Array, tagName:Array

The scope selection may be further restricted by theese properties. Since scope settings are not easily adjusted, following variables are retrieved from the current context (cursor position and line):

  • The prefix is any string before the matched query. Mostly any string before an =, : or (
  • The style is a string before the prefix, separated by a :
  • The tagName is set with <tagName ... 'query'

Examples

  • <img src="./assets/logo.png"> results in {"prefix": "src", "tagName": "img"}
  • '"property-name": url(./assets/logo.png)' results in {"prefix": "url", "style": "property-name"} and
  • from 'component' results in {"prefix": "from"}

Any unspecified property will be ignored.

auto:Boolean

If "auto": false the specified configuration will only be triggered by shortcuts.

relative:Boolean

Sets the type of the path to insert. If "relative": true paths will be inserted relative to the given file. Else filepaths are inserted absolute to the project folder. This option may also be set by key commands for insert_path. Note: option relative will be overwritten if the string starts with /, ./ or ../.

base_directory:Boolean|String

The base_directory property will adjust the base path from which the filepath is resolved. This is true for relative and absolute paths. If "base_directory": true paths will be resolved from the default base_directory given in main settings. If "base_directory": "/dev/src", any paths matching this scope-item are resolved by /dev/src.

i.e. if the file in /dev/src/components/index.js is inserted absolute, the final path will be /components/index.js

extensions:Array

This will further filter proposed files for this scope (based on extensionsToSuggest).
i.e. "extensions": ["js", "json"] will only list javascript or json files.

replace_on_insert:Array

An array containing substitutions for the inserted path. After a selected filepath completion is inserted, the path may be further adjusted. Each item within replace_on_insert must be another array like [Search:RegExp, Replace:RegExp]. Use cases:

  • If the project path varies, it may be adjusted for the current scope with
    ["\\/base\\_path\\/module", "vendor"].
  • In NodeJs index files are resolved by default, thus set
    ["index$", ""] if "insertExtension": false to resolve a selection of ../module/index.js to ../module
  • i.e. webpack may resolve paths differently. Thus if a bower component is selected, but its folder is not required, the replacement:
    ["^[\\.\\./]*/bower_components/", ""] will fix this.

This option may also be set by key commands for insert_path.

Example

See Sublime Text | Preferences | Package Settings | FuzzyFilePath | Settings - Default for an up to date version

{
    "disable_autocompletions": false,
    "disable_keymap_actions": false,
    "exclude_folders": ["node\\_modules"],

    "scopes": [
        {
            "scope": "string.*\\.html$",
            // match <div style="background: url(path/to/image)">
            "auto": true,
            "relative": true,
            "base_directory": "path/to/base",
            "extensions": ["png"],
            "prefix": ["url"],
            "style": ["background", "background-image"],
            "tagName": ["div"]
        },
        {
            "scope": "\\.js$",
            // enable shortcuts 'insert_path' for all js languages
            "auto": false,
            "extensions": ["js", "json"],
            "replace_on_insert": [
                ["^[\\.\\./]*/bower_components/", ""],
                ["index$", ""]
            ]
        }
    ]
}

Removed settings

extensionsToSuggest:Array Valid filetypes are now retrieved from the extensions property of each scope entry.

insertExtension:Boolean Extensions should now be removed by replace_on_insert.

auto_trigger removed

Keybindings

In addition to automatic filepath suggestions, keybindings may be set to trigger filepath completions, independent of the current scope. While scope rules will be applied

  • the type of the requested path (relative, absolute) may be set explicitly
  • the replacements in replace_on_insert may be overriden
  • the base directory for path resolution may be adjusted by base_directory and
  • extensions are adjusted by extensions

In Sublime Text | Preferences | KeyBinding - User or
Sublime Text | Preferences | Package Settings | FuzzyFilePath | KeyBinding - Default add an object like

{
    "keys": ["ctrl+alt+i"],
    "command": "insert_path"
}

This will trigger filepath suggestions on ctrl+alt+i, with the current scope rules defined in settings. To override the type of the path add an arguments object like:

{
    "keys": ["ctrl+alt+i"],
    "command": "insert_path",
    "args": {
        "type": "relative"
    }
}

To override replacements set

{
    "keys": ["ctrl+shift+space"],
    "command": "insert_path",
    "args": {
        "replace_on_insert": [
            ["^[\\.\\./]*/bower_components/", ""]
        ]
    }
}

Examples

See Sublime Text | Preferences | Package Settings | FuzzyFilePath | KeyBinding - Default for an up to date version

[
    {
        "keys": ["ctrl+alt+space"],
        "command": "insert_path",
        "args": {
            "type": "relative",
            "base_directory": "dev/src",
            "extensions": ["css", "sass", "less", "png", "gif", "jpg", "svg"]
        }
    },
    {
        "keys": ["ctrl+shift+space"],
        "command": "insert_path",
        "args": {
            "type": "absolute",
            "replace_on_insert": [
                ["^[\\.\\./]*/bower_components/", ""]
            ]
        }
    }
]

Related Plugins

AutoFileName
  • uses file discovery based on current directory instead of fuzzy search
  • adds properties for images in autocompletion description