Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Latest commit

 

History

History
97 lines (73 loc) · 3.56 KB

README.md

File metadata and controls

97 lines (73 loc) · 3.56 KB

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 ad and id respectively. These follow Vim convention, so that ad selects all of a Blade directive, and id 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 vip, followed by an S to activate vim-surround, followed by a d. This will open a prompt where you may type your blade directive.

Limitations

  • Operations are done line wise, so this text object doesn't work for statements on a single line.

  • Some text objects in Vim respond to a count. For example, the a{ text object will select all of the current {} delimited block, but if you prefix it with the number 2 (e.g. v2i{) then it will select all of the block that contains the current block. The Blade directive text object does not respond in this way if you prefix a count. This is due to a limitation in the textobj-user plugin.

    However, you can achieve a similar effect by repeating the Blade directive text-object manually. So if you press vad to select the current Blade directive, you can expand your selection outwards by repeating ad, or contract your selection inwards by repeating id.

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.