Skip to content

Instantly share code, notes, and snippets.

@benjamintemitope
Created October 14, 2025 13:46
Show Gist options
  • Select an option

  • Save benjamintemitope/9ed59bb4efa67b4d04776dd50e962220 to your computer and use it in GitHub Desktop.

Select an option

Save benjamintemitope/9ed59bb4efa67b4d04776dd50e962220 to your computer and use it in GitHub Desktop.

Sublime Text Plugin: Open Laravel Blade Views from view() Calls

This Sublime Text plugin enables developers to quickly open Laravel Blade template files by parsing view names inside view() function calls.

When the cursor is on a line like this:

view('posts.index');
view('posts.index', compact('posts'));

✨ Features

  • Parses Blade view paths from statements like:
    view('posts.index'), view('posts.index', compact('posts')), etc.
  • Converts dot notation (posts.index) to Blade file paths:
    resources/views/posts/index.blade.php
  • Opens the target view file directly in Sublime Text
  • Supports flexible syntax with multiple arguments and whitespace

⚙️ Installation

  1. Open Sublime Text.
  2. Go to Preferences > Browse Packages.
  3. Inside the User folder, create a new file named open_blade_view.py.
  4. Paste the plugin code into this file and save it.

⌨️ Optional: Set a Keyboard Shortcut

You can press your configured shortcut key (e.g., Ctrl+Alt+V), and the plugin will open:

To add a custom shortcut:

  1. Go to Preferences > Key Bindings.
  2. Add an entry like this to your keymap file:
{ "keys": ["ctrl+alt+v"], "command": "open_blade_view" }

Now you can press Ctrl+Alt+V to open Blade views instantly.

🚀 How to Use It

  1. Open a Laravel project in Sublime Text.
  2. Place the cursor anywhere on a line containing a view('...') call.
  3. Run the command:
    • Either from the Command Palette: View: Open Blade View
    • Or via a keyboard shortcut (see setup below).
  4. The corresponding Blade file will open automatically if it exists.
import sublime
import sublime_plugin
import os
import re
class OpenBladeViewCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
line = self.view.line(region)
text = self.view.substr(line)
# Match first argument inside view() call
# Handles: view('posts.index'), view("posts.index", [...]), view ( 'posts.index' )
match = re.search(r'view\(\s*[\'"]([\w./-]+)[\'"]', text)
if match:
blade_path = match.group(1).replace('.', '/')
full_path = os.path.join(self.get_project_root(), 'resources', 'views', blade_path + '.blade.php')
if os.path.exists(full_path):
sublime.active_window().open_file(full_path)
else:
sublime.error_message(f"Blade view file not found:\n{full_path}")
else:
sublime.error_message("No valid view() function with a string argument found on this line.")
def get_project_root(self):
folders = self.view.window().folders()
if folders:
return folders[0] # You can enhance this to find Laravel root more accurately
else:
sublime.error_message("No folders open in this Sublime project.")
return ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment