[RUBY] [Beginner] About "Rectangle selection (block selection)" that allows you to correct indentation of multiple lines at once

Introduction

There are times when you want to balance the whole thing after you finish typing the code in Rails. I was absorbed in thinking about the code, and when I looked back, the indentation was scattered and the balance was insanely hard to see. Also, I think there are times when you want to add a parent element later, straddling multiple elements, and you need to indent one space for every row of child elements. As a programming enthusiast, I just kept hitting the TAB key to get rid of the indentation.

Meanwhile, the world has changed since I learned the trick of "rectangle selection". I think many people know it, but if there are people who don't use it or don't know it, I think it's a waste, so I'll share this useful technique.

What are you doing at such times?

See the code below. image.png This is the code that created a new user registration screen using devise. This alone can be used as a function, but it does not look beautiful.

I want to use Bootstrap to balance the whole thing <div class="container"> <div class="row"> I will surround it with.

qiita.rb


<div class="container" >
  <div class="row" >
  -------------← I want to put the above code here! !! !!
  </div >
</div >

I agree. That's fine if you just put it in between, but if you're aware of readable code, it's likely to be more beautiful to indent every line.

But it's a hassle. I understand. In such a case, you can use this "** Rectangle selection **"!

What is rectangle selection (block selection)?

Very useful features are easy to use. For macOS

Keyboard rectangle selection command


Click where you want to start
[Shift] + [Option] + [Command] + arrow keys
Drag as it is

Only this. To explain it more clearly, image.png In this way, click where you want to start. And when you type in the ↑ command, image.png Fortunately, the pointer has been expanded to enclose the entire <div class = "field">. If you can do this, it's easy. To make it easier to see, if you leave the indent only in the ↑ part, it will look like this. image.png Yes, it's very convenient.

Other uses for rectangle selection

Of course, you can not only leave a space but also type letters. image.png By typing the character once, I was able to type the same character on the other lines selected by the rectangle. There are many other ways to use it, so if you are interested, please check it out!

in conclusion

I think there are many small tricks in the programming world that can reduce your work time in this way. It's hard to remember everything at once, but if you get used to it one by one, the day may come when you can become a very smart programmer!

Recommended Posts

[Beginner] About "Rectangle selection (block selection)" that allows you to correct indentation of multiple lines at once
A memo of the program that allows you to realize that the probability of dice rolling is about 1/6