July 15, 2020 · Potpourri

The Useful Multi-Cursor Feature

Some text editors today have multi-cursor features and at a glance these features seem pretty useless. Why would I ever want to type in two places at once? Well let’s dive into that….

What

A multi-cursor is just allowing you to have more than one cursor active in your text editor. Some notable editors that have this are Sublime Text and VS Code.

Why

Your initial reaction to a multi-cursor might be "It's as useful as typing with two people on the same keyboard." But if used properly this could be very beneficial. Look at the following simple game code:


public string Name { get; protected set; }
public int Level { get; protected set; }
public float CurrentHP { get; protected set; }
public bool IsGrounded { get; protected set; }
public double EXP { get; protected set; }

This code is missing the 'very' important summary tags, and we can add them very quickly with multi-cursor!

This is just a very simple example that saves a lot of time for anyone that can not auto-generate these docs strings. But wait let's look at another example:


public void foo { ... }
public static void bar { ... }
public void spam { ... }
public void ham { ... }
public static void eggs { ... }

For this example we will use multi-cursor searching. I will be using Sublime Text as it has a find all feature that works well with multi-cursor. Let’s assume we want to move all the static single line methods to the top to better maintain our code. Well multi-cursor has the perfect answer here.

Find all with the following text:

Then it's a simple copy and paste job. An easy trick to quickly move code around.

Want more?

This is just diving into the basics of multi-cursor editing and its uses. If you want to learn more see the sublime text documentation on muli-selection with the keyboard.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket