sponsor Vim development Vim logo Vim Book Ad

deleft.vim : Delete a wrapping if-clause, try-catch block, etc. and shift left.

 script karma  Rating 4/1, Downloaded by 26  Comments, bugs, improvements  Vim wiki

created by
Andrew Radev
 
script type
utility
 
description
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>

Executing the :Deleft command or using the provided "dh" mapping on the container div results in just:

    <a href="#">Something</a>

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").

Note that "dh" is a built-in mapping, but it's a synonym to "x", so I'm okay with overwriting it. Set "g:deleft_mapping" to "" (or whatever else you like) to avoid this.

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`/`elsif`/`else`/`end` lines:

    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

Please read the built-in documentation for settings and additional informaiton.
 
install details
The easiest way to install the plugin is with a plugin manager:

- vim-plug: https://github.com/junegunn/vim-plug
- Vundle:   https://github.com/VundleVim/Vundle.vim

If you use one, just follow the instructions in its documentation.

You can install the plugin yourself using Vim's "packages" functionality by cloning the project (or adding it as a submodule) under `~/.vim/pack/<any-name>/start/`. For example:

    git clone https://github.com/AndrewRadev/deleft.vim ~/.vim/pack/_/start/deleft

This should automatically load the plugin for you on Vim start. Alternatively, you can add it to `~/.vim/pack/<any-name>/opt/` instead and load it in your .vimrc manually with:

    packadd deleft

If you'd rather not use git, you can download the files from the "releases" tab and unzip them in the relevant directory: https://github.com/AndrewRadev/deleft.vim/releases.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
deleft.zip 0.1.1 2021-02-18 7.4 Andrew Radev - Load matchit dependency if it's not loaded
- Implement python fallback
deleft.zip 0.1.0 2021-02-15 7.4 Andrew Radev Initial upload
ip used for rating: 44.192.10.166

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
OSDN