DEV Community

Alejandro Bezdjian
Alejandro Bezdjian

Posted on • Updated on

Text editor tips and tricks to boost your productivity

Recently, I was peer programming at work and, whithout thinking, I started to use a few editor tricks I had learned a while ago. My co-worker was amazed with them and picked up a few. At first I thought it was no big deal, but a few days later I began to observe that there are a lot of people who don't know many of these tricks. Since the tools we use have a lot of functionalities to make us more productive, it's a shame that we spoil them. That's why I thought it would be a good opportunity to transfer this useful knowledge and help others improve their productivity.

Building blocks

All the tricks I'll show you are a combination of small pieces that seem insignificant at first sight, but are very powerful when they are combined. At the end I will show you some examples that (hopefully) show how useful these tricks are.

The examples were created using VS Code on a mac, but all these functionalities should be available in every editor and IDE.

Moving cursor

Let's start slowly but surely.

Use the arrows of your keyboard to move the cursor one step at a time:

Move cursor one step at a time

Using option + cursor move the cursor between words:

Move cursor between words

User cmd + cursor to move the cursor to the end or beginning of line:

Move cursor to the beginning of line

Using the option key, you can move any line:

Move line

I use cmd + x to delete a line, this actually cuts it, but I don't really care (if you do care, use cmd + shift + k):

Delete line

Highlighting

This also seems silly, but it's important that we know them all.

Using shift + cursor we can highlight words character by character:

Highlight characters

To improve this, we can use shift + option + cursor to highlight whole words:

Highlight words

We can boost this using shift * cmd + cursor to select the entire line:

Highlight line

Multiple cursor magic

Now we are getting to the most important thing in my opinion, controlling multiple cursors.

First let's create them, we can use cmd + click using the mouse or cmd + option + up/down cursor with the keyboard only:

Create multiple cursors

Normally, the selections of each cursor are copied separately and you can copy and paste them anywhere. If you have the same number of cursors as when you copied this is what happens:

Copy and paste multiple cursors

If you have a smaller or larger number of cursors than when you copied, all the copied selections will be pasted on every cursor you have at the moment.

I use the next one a lot. When you select something, you can use cmd + d to select the next matching selection. This is extremely useful as we will see in one of the examples at the end. Each selection will create a cursor for it:

Same selection cursor

Auto closing characters

These is similar to the HTML auto closing tags function (that I also recommend) but with characters that have a closing pair, for example:

Double quotes

Single quotes

Curly brackets

Parenthesis

Examples

All the previous blocks will be useful in %90 of the times (more or less). The examples I'll show you are simplified real case scenarios and I hope the animations are self-explanatory (if there is something unusual I will try to explain what I did).

Exercise 1

Here I added a space at the beginning so I would get a cursor where I wanted (this is another trick that you learn from practice).

Exercise 2

Exercise 3

Exercise 4

Exercise 5

Exercise 6

Of course there are other ways to solve them, your creativity is your limit!

Extras

There are other features that editors have that you definitely should know:

  • Find and open a file by name: in my case is cmd + d but other editors and IDEs have them mapped differently.
  • Use autocompletion: if you develop in Java or similiar you are probably used to this, but editors have a lot of plugins for other languages that can help you.
  • Find words in a file using regexp. This one is a bit more difficult (because you have to know regular expressions) but is very useful from time to time:

Regexp selection

Once you found the text you want with your regexp, use shift + cmd + L to select it.

I hope you found these tricks useful and help you be more productive!

Buy Me A Coffee

Top comments (7)

Collapse
 
youpiwaza profile image
max

Great articles, especially the common use cases.

I'd also recommand cmd + K (remove Γ  line), and the all mighty cmd + shift + D (duplicate a line, DOESN'T LOOSE the clipboard content).

If you got other tricks (even if they are harder or uncommon) I'd like to see them :)

Collapse
 
alebian profile image
Alejandro Bezdjian

You are right! I use copy and paste so I don’t have to remember another shortcut πŸ˜… But I think I’ll start using them, thanks!

Collapse
 
youpiwaza profile image
max

Yeah it's especially usefull when you get some data/names from elsewhere and need to add them to your code, one way that already exist :)

Simply Ctrl + Shift + D to duplicate (don't loose clipboard content) and paste where needed ^

Collapse
 
joshransley profile image
Josh Ransley

A good overview of the main features/shortcuts available in pretty much every editor.

Multi line editing (& multiple cursors generally) is something that took me a while to really get used to but it's such a powerful feature.

Another thing I'd struggle without now would be some form of autocompletion.

It really pays in the long run to discover and find shortcuts for the feautures your editor has. I use Sublime and have got so used to its features and shortcuts it would take me a long time to be as productive in another editor.

Collapse
 
antoniojboza profile image
Antonio Boza

One of my favourites:

CMD + D after highlighting some text. Multi line editing jumping to the next exact same text you highlighted. Really useful to edit, in example, variable names. You could argue to use the replace functions, but this way you have autocomplete.

Collapse
 
clarity89 profile image
Alex K.

What about one of the greatest inventions after garlic bread - the code snippets?

Collapse
 
alebian profile image
Alejandro Bezdjian • Edited

I may update the post with a little example but I think those deserve another post! I rely on the ones included in the plugins and only had to write one by myself, but they are definitely awesome πŸ˜„