All Projects → AndrewRadev → deleft.vim

AndrewRadev / deleft.vim

Licence: MIT license
Delete a wrapping if-clause, try-catch block, etc. and shift left.

Programming Languages

Vim Script
2826 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to deleft.vim

rubocop-auto-correct
Auto-correct ruby source code by using rubocop in Atom.
Stars: ✭ 29 (-57.35%)
Mutual labels:  refactoring
flextool
C++ compile-time programming (serialization, reflection, code modification, enum to string, better enum, enum to json, extend or parse language, etc.)
Stars: ✭ 32 (-52.94%)
Mutual labels:  refactoring
refactoring-for-testability-cpp
Hard-to-test patterns in C++ and how to refactor them
Stars: ✭ 40 (-41.18%)
Mutual labels:  refactoring
looong
Discovery of Long Parameter List
Stars: ✭ 16 (-76.47%)
Mutual labels:  refactoring
awesome-programming-books
List of good programming books for beginners and professionals
Stars: ✭ 68 (+0%)
Mutual labels:  refactoring
refactoringtopatterns
A place to practice Refactoring To Patterns that Kerievsky wrote about in his book
Stars: ✭ 46 (-32.35%)
Mutual labels:  refactoring
Escape From Callback Mountain
Example Project & Guide for mastering Promises in Node/JavaScript. Feat. proposed 'Functional River' pattern
Stars: ✭ 249 (+266.18%)
Mutual labels:  refactoring
sublime-jsoncomma
A Sublime Text plugin to deal with those damn JSON commas!
Stars: ✭ 35 (-48.53%)
Mutual labels:  text-manipulation
pro.fessional.wings
WingsBoot=BKB+飞鞋+SpringBoot。其核心价值是:①使团队快速实现业务目标;②快速偿还技术债务;③安全的面向程序和业务重构。
Stars: ✭ 78 (+14.71%)
Mutual labels:  refactoring
colisper
Check and transform Lisp code with Comby (beta)
Stars: ✭ 18 (-73.53%)
Mutual labels:  refactoring
refren
A language agnostic, code-style aware, refactoring/renaming tool.
Stars: ✭ 19 (-72.06%)
Mutual labels:  refactoring
churn
Find refactoring candidates in your Elixir project easily with Churn 🧹
Stars: ✭ 87 (+27.94%)
Mutual labels:  refactoring
seamer
refactoring tool that aims at making it easy to create characterization tests
Stars: ✭ 16 (-76.47%)
Mutual labels:  refactoring
redux-usage-report
A Redux Devtools monitor to audit your app's usage of the store
Stars: ✭ 41 (-39.71%)
Mutual labels:  refactoring
refactoring-koans-js
Refactoring Koans to help you learn to refactor code smells in javascript
Stars: ✭ 15 (-77.94%)
Mutual labels:  refactoring
atom-refactoring
Atom package that provides refactoring capabilities for your PHP source code.
Stars: ✭ 16 (-76.47%)
Mutual labels:  refactoring
IntelliJDeodorant
The project is not actively supported.
Stars: ✭ 53 (-22.06%)
Mutual labels:  refactoring
refactor-css
Helps you identify reoccurring CSS class name combinations in your markup
Stars: ✭ 28 (-58.82%)
Mutual labels:  refactoring
clang-tool
Simple and powerful standalone project for clang-based tools using libtooling (e.g. refactoring, auto-completion, etc.)
Stars: ✭ 35 (-48.53%)
Mutual labels:  refactoring
kata
TDD, Refactoring kata in many languages
Stars: ✭ 14 (-79.41%)
Mutual labels:  refactoring

RestClient demo

Build Status

Screencast

For a video explanation, here's a demo.

Usage

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.

Here's some more examples:

HAML Containers demo Coffeescript callbacks demo Rails controller demo

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

If you'd like to handle the "contents" of the code blocks differently, you can decide this using the "remove strategy".

Remove strategies

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 :help matchit-newlang.

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 g:deleft_indent_based_filetypes.

Custom filetype support

Some filetypes don't have useful matchit definitions for stuff like if-clauses and it's hard to implement them. In that case, the plugin might have a custom definition that handles it. For now, only Rust if-clauses get special treatment.

Contributing

Pull requests are welcome, but take a look at CONTRIBUTING.md first for some guidelines.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].