Home

Awesome

Ever felt like using this text object in a different filetype? I did, so I created this other one.

vim-textobj-blade-directive

A text object for Laravel's Blade directives.

Example

Installation

Depends on vim-textobj-user and vim-blade.

Plug 'kana/vim-textobj-user'
Plug 'jwalton512/vim-blade'
Plug 'adriaanzon/vim-textobj-blade-directive'

Also requires the matchit.vim plugin to be enabled. You can check if it's enabled by running :echo g:loaded_matchit, it should return 1.

If it's not enabled yet, you can do so by putting the following in your vimrc:

runtime macros/matchit.vim

Usage

When textobj-blade-directive is installed you will gain two new text objects, which are triggered by <kbd>a</kbd><kbd>d</kbd> and <kbd>i</kbd><kbd>d</kbd> respectively. These follow Vim convention, so that <kbd>a</kbd><kbd>d</kbd> selects all of a Blade directive, and <kbd>i</kbd><kbd>d</kbd> selects the inner portion of a Blade directive.

Tips

In the example GIF, the @if statement got surrounded with a @can statement. This isn't directly related to this plugin, but it was achieved using the vim-surround plugin, with the following configuration in after/ftplugin/blade.vim:

" Use 'd' to surround with a Blade directive.
let b:surround_{char2nr("d")} = "@\1Blade directive: @\1 \r @end\1\r\[( \]\\+.*\r\1"
" Some aliases for convenience.
let b:surround_{char2nr("D")} = b:surround_{char2nr("d")}
let b:surround_{char2nr("@")} = b:surround_{char2nr("d")}

Now you can surround anything with a Blade directive. For example, if you wanted to surround a paragraph, you could select the paragraph with <kbd>v</kbd><kbd>i</kbd><kbd>p</kbd>, followed by an <kbd>S</kbd> to activate vim-surround, followed by a <kbd>d</kbd>. This will open a prompt where you may type your blade directive.

Limitations

Credits

Thanks to Drew Neil for his plugin vim-textobj-rubyblock. This plugin was made by simply changing the search patterns in his plugin.

I also thank Kana Natsuno for providing a framework to build custom text objects.

License

Copyright © Adriaan Zonnenberg. Distributed under the same terms as Vim itself. See :help license.