atom / find-and-replace

Find and replace in a single buffer and in the project
MIT License
242 stars 219 forks source link

Find and replace auto indent for new lines. #1145

Open tocruise opened 3 years ago

tocruise commented 3 years ago

Summary

When doing a find and replace - a find on a single line, to replace it with multiple other lines - it would be nice if Atom automatically indented the new lines to match the style of surrounding/preceding lines. Similar to how when you go onto a new line, it automatically knows where your cursor should be. It would be nice if this applied to replaces also.

I always have an awful time trying to explain what I mean, so if this isn't clear then please refer to the Additional context section below.

Motivation

In each file, each line of my code has a varying number of tab-indentations, as I'm sure everyone's code does. It seems weird to me that nobody has ever wanted to do a find-and-replace on multiples lines of varying indentation, without having to manually specify a number of tabs.

Describe alternatives you've considered

I've scrolled through all of the issues on this Git and found nothing similar to what I'm trying to do. I've also flicked-through the community packages, and found nothing that works to achieve this.

Additional context

Here's what currently happens...

This is my code:

image

I'd like to add a comment title line above the var output = get_output(data); (the highlighted line). Instinctively the best way to do this, would be to use regex in the find and replace like so:

Find: var output = get_output(data); Replace: /* Get response */\r\n\r\nvar output = get_output_new(data);

The reason I'm using find and replace, and the reason why I can't just use \t to add the correct number of tabs, is because this line of code exists in many files, all with different amounts of indentation. So although, in this specific case, \t\t\t\t would be the correct number of tabs to match the indentation, it wouldn't match in other files - 4 tabs may be too many or too little.

Here is what the result should look like after running the find and replace:

image

But, instead it looks like this:

image

Like I said, without manually adding \t I don't see how I'd be able to get this to look how I desire.

UziTech commented 3 years ago

This issue should be moved to the https://github.com/atom/find-and-replace repo