As programmers 👨💻, we spend most of our working days in front of editors. As the saying goes, to do good work must first sharp tools, master the guy is very necessary to eat.

Think back to the early days when you couldn’t type blind, and how inefficient it was to type code letter by letter. (also can’t play blind students, should go to the next jinshan typing pass, usually practice more) two technical level of programmers, coding efficiency is higher than the low efficiency of the people can output more code.

This is the first of a series of short articles I plan to write about improving coding efficiency (the hard power of programmers). Master it and apply it, and we’ll have more time to save the world.

Major editors such as Sublime Text, Vscode, and Atom support multiple cursors, which is very powerful and allows us to edit multiple places at once without reworking. Duplication of effort here refers to the work we often encounter in the coding process, where multiple pieces of similar code need to be edited, and the effort is not valuable for personal improvement. For example, changing variable names, replacing PX units with REM units, putting double quotes around fields, etc. How about a multi-cursor (below are Mac + VScode effects)

CMD + click(CTRL + click on Windows) to insert the cursor in multiple locations.

Can see by clicking, insert the four cursor, coupled with Alt + [left | right] quick switch to the last Symbol. Realize the effect of fast editing multiple places.

But manually inserting the cursor is still too cumbersome, and if you need to insert the cursor over a hundred lines of code, clicking it a hundred times takes time. Try CMD + Shift + L (CTRL + Shift + L on Windows) and insert the cursor behind the selected text.

If it is to modify the discontinuous content of the common part, for example, or the same data format, quickly replace the title content in the file with fixed text.

[
  {
    userId: 1,
    id: 1,
    title: "delectus aut autem",
    completed: false
  },
  {
    userId: 1,
    id: 2,
    title: "quis ut nam facilis et officia qui",
    completed: false
  },
  ...
]
Copy the code

Search, Alt + click, insert cursor in search matching position.

Inserted after the cursor, in combination with CMD + [left | right] (Windows is CTRL + [left | right]) quickly jump to gear, the end of each line.

The next time you need to edit more than one area of code, try to find commonality and use the multi-cursor feature to improve efficiency 😁. Occasionally, you come across things that are hard to identify at the code level but have physical similarities, such as being on the same column. Try the CMD + opt + [up | down] quick insert cursor in the same column.

Think back to when you first started working with the code, and you didn’t have enough money to do all of these things, and a day went by with your eyes closed. So did I, until I learned how to use multiple cursors, which freed me from repetitive tasks and productivity.

Do you have any tips for using multiple cursors?