- Notifications
You must be signed in to change notification settings - Fork0
adriaanzon/vim-textobj-blade-directive
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Ever felt like using this text object in a different filetype?I did, so I created this other one.
A text object for Laravel'sBladedirectives.
Depends onvim-textobj-user andvim-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'senabled by running:echo g:loaded_matchit, it should return1.
If it's not enabled yet, you can do so by putting the following in your vimrc:
runtime macros/matchit.vim
When textobj-blade-directive is installed you will gain two new text objects,which are triggered byad andidrespectively. These follow Vim convention, so thatadselectsall of a Blade directive, andid selects theinner portion of a Blade directive.
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 thevim-surround plugin, with thefollowing configuration inafter/ftplugin/blade.vim:
" Use 'd' to surround with a Blade directive.letb:surround_{char2nr("d")}="@\1Blade directive: @\1\r @end\1\r\[(\]\\+.*\r\1"" Some aliases for convenience.letb:surround_{char2nr("D")}=b:surround_{char2nr("d")}letb:surround_{char2nr("@")}=b:surround_{char2nr("d")}
Now you can surround anything with a Blade directive. For example, if youwanted to surround a paragraph, you could select the paragraph withvip, followed by anS to activatevim-surround, followed by ad. This will open a prompt where you maytype your blade directive.
Operations are done line wise, so this text object doesn't work forstatements on a single line.
Some text objects in Vim respond to a count. For example, thea{ text object will selectall of the current
{}delimited block, but if you prefix it with the number 2 (e.g.v2i{) then it will select all ofthe block that contains the current block. The Blade directive text objectdoes not respond in this way if you prefix a count. This is due to alimitation in thetextobj-user plugin.However, you can achieve a similar effect by repeating the Blade directivetext-object manually. So if you pressvad toselect the current Blade directive, you can expand your selection outwards byrepeatingad, or contract your selection inwards byrepeatingid.
Thanks to Drew Neil for his pluginvim-textobj-rubyblock.This plugin was made by simply changing the search patterns in his plugin.
I also thank Kana Natsuno for providinga framework to build custom textobjects.
Copyright © Adriaan Zonnenberg. Distributed under the same terms as Vim itself.See:help license.
About
A text object for Laravel's Blade directives
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
