2

While working on something like laravel, I end up creating the same view files index.blade.php, create.blade.php, show.blade.php within different folders like views/articles, views/comments, etc using the nerdTree mostly.

Is there a way to create the files from the command mode or through any plugin, for which i can create a key mapping to speed up things ?

  • 2
    How about something like :!touch views/{articles,comments}/{index,create,show}.blade.php? – Rastapopoulos Oct 16 '17 at 15:06
  • @Rastapopoulos thats a nice one, thanx! – connectkushal Oct 18 '17 at 12:59
3

You can create a bunch of filenamed buffers from within vim using :argadd:

:argadd dir1/index.blade.php dir2/create.blade.php foo/show.blade.php 

You can also use the syntax

:argadd dir/{foo,bar}.php

From there, you can switch between buffers using :next/:Next, :buffer or any other way.

Note: vim does not default write the empty buffers to disk unless you explicitly :w them. You can easily create them all on disk using:

:argdo w

The plugin vim-projectionist is designed for this use case:

https://github.com/tpope/vim-projectionist

and the vim-laravel plugin already has support for vim-projectionist

https://github.com/noahfrederick/vim-laravel

1

You could do something like this:

command! -nargs=* MakeLaravelFiles call MakeLaravelFiles()
function! MakeLaravelFiles()
  !touch /path/to/first/file /path/to/second/file /path/to/third/file
endfunction

And then setup a keymapping to that function, aka

nnoremap <silent> <leader>ml :MakeLaravelFiles<CR>

(Note: this snippet creates blank files, but you can use any CLI command you prefer instead of touch)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.