Code Editor Essentials Part I: How to Speed Up Cursor Movements

19.08.2015 | 3 min read

To edit something you first need to “get there”, i.e. to place your “cursor” close to it. In general, the longer the time you need to reach a given location the more time you waste. Many people don’t do anything to speed up the process, though. They either only use arrow keys or mouse for navigation.

Most editors provide many more commands for placing a cursor where you want it (sometimes even more than one cursor!). Using the right ones can improve cursor positioning speed by a factor of 10 or more, especially on large screens.

The most basic way of moving a cursor around is to use arrow keys, which typically move the cursor by one character or line. Home and End keys move a cursor to start or end of a line. There are also PageUp and PageDown keys that do what their names imply. These are not very interesting, so let’s take a look at more advanced features.

First, all editors and most OSes support Ctrl + Left/Right for moving a cursor by words. Some editors let you customize how they detect word boundaries – for example if you’d like “next word” command stop at parts of camelCasedNames. There are many more commands for moving a cursor by some unit. With a single keypress, you can jump to the next sentence, next paragraph, next expression, top/half/bottom of a screen and more.

Editors vary in how well they recognize the syntactic structure of edited text. You should look for an editor that allows for at least jumping to matching parentheses/quotes, even if it lacks full “forward expression” command.

All the shown movement commands are easy to use, but not always very efficient. Sometimes you need to execute them (press a key shortcut) many times to get what you want. Once in such a situation it’s time to use more advanced commands.

NOTE: some editors allow you to use a “numerical prefix”, which will repeat the next command that many times. It’s not a widely available feature, but almost all editors have plugins for this, even if they don’t support it directly. This lets you alleviate some pain of having to press some key repeatedly.

First is search, which you can (and should) use for navigation on both short and long distances:

NOTE: most editors remember (at least one) last string you were searching for and use this as a default if you don’t provide any string at all. This means that you can tap your search key twice to get quickly to the next class, function, or any other frequently occurring string.

If searching is not fast or convenient enough, we can use its simplified version, known in Vim as “f” command. It searches forward for the first occurrence of a given character:

You can usually press the same key many times for jumping to the following occurrences.

There’s also a way to highlight all characters of a given kind and let the user jump to any of them quickly:

If you know that you want to get to one of the lines containing a word, you can use extended search commands, like “occur” in Emacs:

If you know some other powerful commands for navigating through code let us know in the comments.

Piotr has been programming since forever! He’s passionate about polyglot programming and original, experimental programming languages. He tries to apply knowledge of both to production quality systems in a real life.

You may also like these posts

Start a project with 10Clouds

Hire us