This plugin provides a set of commands and basic templates for working with Laravel projects in Vim using projectionist.vim.
- Open
vimin your Laravel project with no arguments. - Open your
App\Models\Usermodel 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
pestusing:Make(or better yet,m<cr>). - Press
<C-w><C-w>to move back to the User model window. - Open your
App\Http\Controllers\UserControllercontroller 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,:Makeand:Dispatch.
Recommended, but not required:
- composer.vim is recommended to use its built in support for
gfand 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 'built-fast/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 Userwill:split app/Models/User.phpin a vertical split:Vmodel Userwill:vsplit app/Models/User.phpin a vertical split:Tmodel Userwill:tabedit app/Models/User.phpin a new tab:Dmodel Userwill:read app/Models/User.phpthe template for the model (defined by this plugin) and replace the current buffer's contents with it:Omodel Userwill: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*-:editthe destination file:S*-:splitthe destination file:V*-:vsplitthe destination file:T*-:tabeditthe destination file:D*-:readthe destination file:O*-:dropthe 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
:Makewhile editingcomposer.jsonorcomposer.lockto runcomposer installvia Dispatch.
- Call
:Econfig [arg]- Open the given configuration file. With no argument provided, opensconfig/app.php.- Call
:Makewhile editing a config file to runphp artisan config:clearvia Dispatch.
- Call
:Econtract <arg>- Open the given contract interface.:Econtroller <arg>- Open the given controller.:Ecss [arg]- Open the given CSS file. With no argument provided, opensresources/css/app.css.:Edata <arg>- Open the given data transfer object (DTO).: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.:Efeature <arg>- Open the given Pennant feature class.: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. With no argument provided, opensstorage/logs/laravel.log.- Call
:Startwhile editing a log file to runtail -f {file}via Dispatch.
- Call
:Email <arg>- Open the given mail.:Emiddleware <arg>- Open the given middleware.:Emigration <arg>- Open the given DB migration.- Call
:Makewhile editing a migration file to runphp artisan migratevia Dispatch for that specific migration. - Call
:Dispatchwhile editing a migration file to runphp artisan migratevia Dispatch for all migrations.
- Call
:Emodel [arg]- Open the given model.- Call
:Emodelwithout 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.jsonfile.- Call
:Makewhile editingpackage.jsonorpackage-lock.jsonto runnpm installvia 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.- Call
:Makewhile editing a route file to runphp artisan route:clearvia Dispatch.
- Call
:Erule <arg>- Open the given rule.:Escope <arg>- Open the given scope.:Eseeder [arg]- Open the given seeder. With no argument provided, opensDatabaseSeeder.- Call
:Makewhile editing a seeder file to runphp artisan db:seedvia Dispatch for that specific seeder. - Call
:Dispatchwhile editing a seeder file to runphp artisan seedvia Dispatch for the defaultDatabaseSeeder.
- Call
:Eschema <arg>- Open the given database schema file.:Eservice <arg>- Open the given service.:Etailwind- Open the Tailwind CSS configuration file.:Etest <arg>- Open the given test.- Call
:Dispatchor:Makewhile 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
:Makewhile editingvite.config.jsto runnpm run buildvia Dispatch. - Run
:Startwhile editingvite.config.jsto runnpx run devvia 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.examplefile..env.example- Open the.envfile.
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.