This plugin provides a set of commands and basic templates for working with Laravel projects in Vim using projectionist.vim.
- Open
vim
in your Laravel project with no arguments. - Open your
App\Models\User
model with:Emodel U<tab>
(tab completing toUser
). Add a great new feature. - Open the corresponding test file in a vertical split with
:AV
. Add a test for your new feature. - Run the test file with
pest
using:Make
(or better yet,m<cr>
). - Press
<C-w><C-w>
to move back to the User model window. - Open your
App\Http\Controllers\UserController
controller with:Tcontroller
. - Open the corresponding test file in a horizontal split with
:AS
. - Run the test again with
m<cr>
. - Start a Tinker console to diagnose some issues with
:Console
. - Open your web routes file with
:Eroute
. - Etc...
- projectionist.vim is required to use this plugin.
- dispatch.vim is optional if you want to can be used to leverage
:Start
,:Console
,:Make
and:Dispatch
.
Recommended, but not required:
- composer.vim is recommended to use its built in support for
gf
and friends. It's not all all required to use the projections in this plugin.
Right now, I'm trying to avoid having this plugin do anything fancy. If you
want, you can just copy laravel-projections.json to your
project at .projections.json
.
If you are using plug.vim or a similar plugin manager you can add this to
your vimrc
:
Plug 'tpope/vim-projectionist'
Plug 'tpope/vim-dispatch' " optional, but recommended
Plug 'noahfrederick/vim-composer' " optional, but recommended
Plug 'itspriddle/vim-laravel-projections'
:Console
- Open the tinker console. Requires dispatch.vim.:Start
- Open the tinker console. Requires dispatch.vim. This isn't locked in. I might use it forcomposer dev
.
"Entities" are basically anything under app/
and a few others. Pretty much
everything that there's a php artisan make:*
command is here.
If you're unfamiliar with projectionist, it sets up Vim commands based on the
file path. This means that we can run things like :Emodel User
to open
app/Models/User.php
. It works with tab completion, so you can type
:Emodel U<Tab>
to complete to :Emodel User
. And when you're in other
related files, like app/Models/UserFactory.php
, you can run :Emodel
to
jump to app/Models/User.php
.
In addition to :Emodel User
to :edit app/Models/User.php
, we can also do:
:Smodel User
will:split app/Models/User.php
in a vertical split:Vmodel User
will:vsplit app/Models/User.php
in a vertical split:Tmodel User
will:tabedit app/Models/User.php
in a new tab:Dmodel User
will:read app/Models/User.php
the template for the model (defined by this plugin) and replace the current buffer's contents with it:Omodel User
will:drop app/Models/User.php
, which opens the file in any window it's already opened in
These commands all have the following variants:
:E*
-:edit
the destination file:S*
-:split
the destination file:V*
-:vsplit
the destination file:T*
-:tabedit
the destination file:D*
-:read
the destination file:O*
-:drop
the destination file
The list of commands is as follows:
:Eaction <arg>
- Open the given action.:Ebroadcast <arg>
- Open the given broadcast.:Ecast <arg>
- Open the given cast.:Ecommand <arg>
- Open the given console command.:Ecomposer
- Opencomposer.json
.- Call
:Make
while editingcomposer.json
orcomposer.lock
to runcomposer install
via Dispatch.
- Call
:Econfig [arg]
- Open the given configuration file. With no argument provided, opensconfig/app.php
.:Econtroller <arg>
- Open the given controller.:Ecss [arg]
- Open the given CSS file. With no argument provided, opensresources/css/app.css
.:Edoc [arg]
- Open the documentation file. With no argument provided, opensREADME.md
.:Edotenv [arg]
- Open the dotenv file for the given environment. With no argument provided, opens.env
.:Eenum <arg>
- Open the given enum.:Eevent <arg>
- Open the given event.:Eexception <arg>
- Open the given exception.:Efacade <arg>
- Open the given facade.:Efactory <arg>
- Open the given factory.:Ejob <arg>
- Open the given job.:Ejs [arg]
- Open the given JavaScript file. With no argument provided, opensresources/js/app.js
.:Elang <arg>
- Open the given language file.:Elistener <arg>
- Open the given listener.:Elivewire <arg>
- Open the given Livewire component.:Elog <arg>
- Open the given log file.:Email <arg>
- Open the given mail.:Emiddleware <arg>
- Open the given middleware.:Emigration <arg>
- Open the given DB migration.- Call
:Make
while editing a migration file to runphp artisan migrate
via Dispatch for that specific migration. - Call
:Dispatch
while editing a migration file to runphp artisan migrate
via Dispatch for all migrations.
- Call
:Emodel [arg]
- Open the given model.- Call
:Emodel
without arguments from inside a factory, seeder, observer, policy, or Unit test to open the model for the current file.
- Call
:Enotification <arg>
- Open the given notification.:Enpm <arg>
- Open NPMpackage.json
file.- Call
:Make
while editingpackage.json
orpackage-lock.json
to runnpm install
via Dispatch.
- Call
:Eobserver <arg>
- Open the given observer.:Epolicy <arg>
- Open the given policy.:Eprovider [arg]
- Open the given provider. With no argument provided, opensAppServiceProvider
.:Erepository <arg>
- Open the given repository.:Erequest <arg>
- Open the given form request.:Eresource <arg>
- Open the given API resource.:Eresponse <arg>
- Open the given HTTP response.:Eroute [arg]
- Open the given route file. With no argument provided, opensweb
.:Erule <arg>
- Open the given rule.:Escope <arg>
- Open the given scope.:Escript <arg>
- Open the given script.:Eseeder [arg]
- Open the given seeder. With no argument provided, opensDatabaseSeeder
.- Call
:Make
while editing a seeder file to runphp artisan db:seed
via Dispatch for that specific seeder. - Call
:Dispatch
while editing a seeder file to runphp artisan seed
via Dispatch for the defaultDatabaseSeeder
.
- Call
:Eservice <arg>
- Open the given service.:Etailwind
- Open the Tailwind CSS configuration file.:Etest <arg>
- Open the given test.- Call
:Dispatch
or:Make
while editing a test file to run the test withphp artisan test {file}
via Dispatch.
- Call
:Etrait <arg>
- Open the given trait.:Eview <arg>
- Open the given view.:Evite
- Open the Vite configuration file.- Run
:Make
while editingvite.config.js
to runnpm run build
via Dispatch. - Run
:Start
while editingvite.config.js
to runnpx run dev
via Dispatch.
- Run
:Eworkflow [arg]
- Open the given GitHub workflow. With no argument provided, opens.github/workflows/ci.yml
.
Alternate files allow you to use :A
to switch between the main file and an
alternate. A common use case is to switch between a class and its test file.
app/*.php
- Open the corresponding test file undertests/Feature/
ortests/Unit/
.tests/{Feature,Unit}/*Test.php
- Open the corresponding class file underapp/
.routes/web.php
- Open the API route file (routes/api.php
)..env
- Open the.env.example
file..env.example
- Open the.env
file.
composer.json
- Opencomposer.lock
.composer.lock
- Opencomposer.json
.
package.json
- Openpackage-lock.json
.package-lock.json
- Openpackage.json
.
This also lets you access :E*
projection commands for the alternate file.
For example, if you are editing app/Models/User.php
, you can use :Etest
to
switch to tests/Feature/Models/UserTest.php
; from in UserTest.php
, you can
use :Emodel
to switch back to app/Models/User.php
.
app/*.php
::Etest
app/Models/
::Efactory
:Eseeder
:Eobserver
:Epolicy
A few templates are provided for creating new files through Projectionist.
That happens when you use an :E*
command for a file that doesn't exist yet,
or use :A
to switch to a non-existent alternate file. If you manually create
a file, you can run :AD
to replace the buffer contents with the new file
template.
By default, *.php
files will just contain a declare(strict_types=1);
statement at the top.
Files under app/*.php
will also include a namespace declaration based on the
file path. For example, creating a new file app/Models/User.php
will include
the line namespace App\Models;
.
MIT License - see LICENSE
in this repo.