This plugin allows you to delete wrapping if-clauses, try-catch blocks, and similar constructs. For example:
<div class="container"> <a href="#">Something</a> </div>
:Deleft command or using the provided
dh mapping on the container div results in just:
So, the mapping/command deletes the opening and closing HTML tag and shifts the code to the left (hence the name "deleft", from "delete left").
dh is a built-in mapping, but it's a synonym to
x, so I'm okay with overwriting it. Set
"" (or whatever else you like) to avoid this.
Here's some more examples:
The plugin attempts to use the extended match definitions from
matchit. In ruby, for instance, the matchit.vim (built-in) plugin lets you jump between any related
if one? two elsif two? three else four end
Delefting the if-clause will also remove all other else-like lines, anything that the matchit plugin jumps to, as long as it's at the same level of indent, leaving you with just this:
two three four
If you'd like to handle the "contents" of the code blocks differently, you can decide this using the "remove strategy".
By default, the plugin deletes the "wrapping" if-clauses and else-clauses and such, leaving all the code inside intact, as-is. You might want to do something different, though. You can change this by changing the setting
g:deleft_remove_strategy. By default, its value is "none".
For instance, changing the value to "comment" results in the "inactive" clause being commented out (as long as you have a supported commenting plugin). In this example:
if true puts "OK!" else puts "There's something wrong here!" end
With the cursor on
if true and remove strategy set to "delete", delefting results in:
puts "OK!" # puts "There's something wrong here!"
But, with the cursor on
else, the results is:
# puts "OK!" puts "There's something wrong here!"
You can read the documentation on
g:deleft_remove_strategy for the full list of strategies and supported comment plugins.
Non-matchit ("simple") delefting
If you don't have matchit activated, for some reason, or you're using a filetype that doesn't have matchit definitions, the plugin will just attempt to match the indent of the line you're deleting and the next line with the same indent. Or, in an indent-based language, it would delete the current line and deindent everything "underneath".
So, if you're writing python, which doesn't seem to have matchit definitions at the time of writing, you can still delete, say, a wrapping if-clause with deleft. Do consider adding your own matchit support, though, as described in
In order to determine which languages are indent-based, the plugin just maintains a list of them. If you'd like to add your own to the list, you can add it to
Pull requests are welcome, but take a look at CONTRIBUTING.md first for some guidelines.