Search code examples
laravelsublimetext3

Sublime Goto anything using dot notation


When using Sublime 3, I'd like to search for a file using the "Dot notation", i.e. file names using . as the separator.

E.g. if I press CtrlP (Goto Anything) and type frontend/banks/index it will find, for example, frontend/banks/index.php

But I want to type frontend.banks.index, which are used in Laravel's views.

How do I achieve this? Is this a sublime setting or a package?


Solution

  • This doesn't directly answer the question, and it makes an assumption for Sublime users: that you want/need this functionality to easily find view files in Laravel code, probably blade templates, based on the the de facto dot notation for view paths, eg.

    return view('frontend.banks.index');
    

    PhpStorm users will know about (and rub your nose in) the functionality it offers when hovering over the view path. It will give you a pop-up with a list of files whose path matches the pattern.

    The workaround I use for Sublime though is to use slash notation instead of dot notation, eg.

    return view('frontend/banks/index');
    

    It's not well known that this works and I haven't seen it documented but it functions identically.

    The downside to this is it breaks PhpStorm's above mentioned functionality. I recently got into a debate with a coworker over it. Since PhpStorm is more prevalent in the Laravel world, he won out. For my personal/solo projects, I use this syntax, and newcomers to the project using PhpStorm can suck it.


    So, to wrap up my longwinded rant, here's my workflow to find a Laravel view in Sublime Text:

    Prerequisite: write all view paths using slashes instead of dots in my codebase.

    1. Highlight the view path
    2. Copy to clipboard
    3. cmd+p (or super+p, ctrl+p, based on your OS) to open the fuzzy file finder, whatever it's called
    4. Paste
    5. Open the desired file (if multiples match, otherwise just hit enter)

    It's decent enough and doesn't require a mouse, like half of PhpStorm's best functionality. 😜


    PhpStorm functionality mentioned above:

    (Edit: apparently this PhpStorm tooltip is just for auto-complete, which is nice, but to actually open the file, F12 should work with the cursor on the path string. Also, according to my coworker, F12 also works with slash notation, so that's very nice for PhpStorm users obviously. All said an done, I think slashes should be used for views in Laravel projects.)

    enter image description here