Getting efficient with code and IDEs

No Comments

Have you ever wondered why people use their Integrated Development Environment (IDE) in other ways than you do? Noticed people being dramatically slower or faster than you while programming? Remember that person using their mouse for every little action on the computer? Or in contrast, that person doing everything with their keyboard in a way that felt magical?

When it comes to modifying text, efficiency usually is not something that people learn in training or at university. The same applies for features of an IDE that come in handy during the broader activity of software development. Fundamentals are surely learnt while starting a career, so most industry beginners already know the basics about their IDE and one or two keyboard shortcuts. But this is often just the tip of the iceberg and there is much potential left until one “masters an IDE” (or even a simple text editor) and simply rocks concerning everything that has to do with text and files.

Grasping the full potential

Efficiency with text files and IDEs can be slowly learnt over the course of months, years and decades. While moving forward in your career, you pick up things on the side. But since writing text, coding and using IDEs is a core activity of software development – why wouldn’t we try to master it early on, at the beginning of our journey? Do we underestimate the potential of learning to be more efficient text and code workers?

Unfortunately, there are no numbers and metrics that I can present about said potential. We need to use our imagination in the following scenarios:

  1. You’re extending a software’s feature, working with a fully-blown IDE, but not leveraging any of its features compared to a simple Windows Notepad. You’re using your mouse to select text, jump and everything else. The keyboard is only used for typing.
  2. Same feature, same IDE. Your keyboard is strumming like you’re performing an 80’s synth pop keyboard solo. You’re selecting, moving and deleting text with it and activating shortcuts of well-known IDE features. Your mouse mostly lies next to you, cold and dusty.

I hope that you are more excited about your speed of working and time efficiency in scenario B. Even if the task is complex and involves some thinking, going back and forth, one is still faster and maybe even more relaxed afterwards. Carpenters use saws, screw clamps, chisels and other crafting tools for good reasons. Imagine they’d work a big piece of wood with nothing but a rasp. That would be straightforward in terms of what to do, but boring and slow. Have a look at how much fun people can gain from finding a high degree of time efficiency:

YouTube

By loading the video, you agree to YouTube's privacy policy.
Learn more

Load video

For text workers there are also lots of useful tools of different categories. Keyboard (this thing can do so much stuff!) selection features, shortcuts, syntax highlighting, formatting, file navigation, searching and replacing, inspections and many more. Let’s go!

Editing text without a mouse

Everybody knows how to type and delete text. But not everybody knows how to efficiently select and deselect, navigate through and move text without a computer mouse. It’s no question that one can be quick with a mouse (see computer gamers). But undoubtedly there is a limit, especially when working with text. Everything about editing texts can be done with a keyboard, too!

Text editing with only your keyboard

Most basic text selection features come with modern operating systems. Advanced text editing features are substituted by IDEs. Take one more second to think about the huge potential: you can apply this learning to every future text of any computer or human language you are writing. Time to get familiar with your keyboard.

Mac OSWindows & LinuxWhat it does
⌘ + ⬅|➡Home (Pos1) | EndJump to start/end of current line
⌘ + ⬆|⬇Page Up | DownJump to start/end of whole content
Alt** + ⬅|➡Ctrl + ⬅|➡Jump to word on the left/right
Alt** + ⬆|⬇Ctrl + ⬆|⬇Jump to upper/lower paragraph
Shift + ⬅|➡Shift + ⬅|➡Extend* selection to left/right symbol
Shift + ⬆|⬇Shift + ⬆|⬇Extend* selection to upper/lower line
Shift + Alt** + ⬅|➡Shift + Ctrl + ⬅|➡Extend* selection left/right word
Shift + Alt** + ⬆|⬇Shift + Ctrl + ⬆|⬇Extend* selection to upper/lower paragraph
Shift + ⌘ + ⬅|➡Shift + Home (Pos 1) | EndExtend* selection to rest of line to left/right side
Shift + ⌘ + ⬆|⬇Shift + Ctrl + Home (Pos 1) | EndExtend* selection to rest of text upwards/downwards

 

* or start
** “Option” key

As you read carefully, you recognise the pattern of these shortcuts. The arrow keys are as intuitive as they can be. Mac users need to know how to build up these combinations using ⌘, Alt and Shift. A classic Windows keyboard provides Shift, Ctrl, Home and End for that. No matter which operating system you’re working with, knowing these shortcuts takes every computer worker a serious step forward.

Working with text patterns

Programmers do often have to deal with patterns. Variable and symbol names, duplicated words, lines, blocks, files and even directories are something we regularly work with. The above standard shortcuts already help a lot but in most situations you need other tools.

Everybody should use their favorite IDE and there are quite a few available. For simplicity the shortcuts mentioned here are for JetBrains IDEs: IntelliJ IDEA, WebStorm, PyCharm, Rider, PhpStorm. However, exact shortcuts are not the primary message of this article. If you use other tools, go find these functions in your tool, try them out and start incorporating them into your work. In editors like VSCode there are features that you may need to install via separate plugins.

Rename all the things

Rename all the things

IDEs should assist you with renaming files, classes, properties, variables and everything else. A proper renaming feature lets you edit all usages of a symbol at once. In order for this to work, the IDE needs to be able to detect dependencies and usages between files and symbols within your code base. This typically works best with typed languages or languages for which the IDE or plugins offer support. Invoking “rename” by shortcut is often as easy as “Shift + F6” (IntelliJ IDEA).

Renaming variables in IDEA IntelliJ

When renaming things, try to use the renaming feature and let the IDE do the work for you. If this does not work due to missing inference (e.g. loosely coupled, event-driven components, certain cases with JavaScript), you’ll need to get your hands dirty with “Search & Replace”.

Search and replace often

“Search & Replace” is well-known and useful when searching occurrences of text patterns and replacing them. It is also feared because when used incorrectly it can break your whole code base in a second and leave a big pile of messy changes.

Here are some tips that assist you with becoming a self-assured “Find & Replace” user:

  1. Use it regularly to learn. Practice it in difficult situations, too, so you can improve.
  2. Use keyboard shortcuts so you can practice even faster: ⌘/Ctrl (+ Shift) + F for “Find” and + R for “Find & Replace”.
  3. Start with a clean Git working directory so that you can restore changes quickly and start over again.
  4. Learn its options in the IDE you’re using: file masks, case insensitivity, preserve case, patterns/RegEx etc. They help refining your search query and dynamize the replaced value, hopefully giving you better results in difficult cases.
  5. Isolate different cases from each other. If the searched for string occurs in multiple different variations, iterate these one after another. Start with the simplest so you make progress.
  6. If the hardest ones do not seem doable, you can still solve them manually and still end up working more efficiently.

The bigger the change you plan to do, the more of these tips will be helpful for the scenario. For replacing one to three tokens in a small text file, most of it (if not the whole functionality itself) is not worth it. You could still use “Copy & Paste”. If you plan to build up multiple changes on top of each other during a large refactoring, think about this wise quote by Kent Beck:

Tweet of Kent Back about refactoring

Multi cursor the leftovers

This feature of modern IDEs allows you to place multiple active cursors throughout your edited file. These cursors do all behave the same when typing or deleting text. It’s like a visual and interactive way to Search & Replace in one file. It is best used if Search & Replace is not an option because you can’t find common criteria for the text you want to edit.

Multi cursor demonstration in IntelliJ IDEA

The animation shows a case that can also be solved with Search & Replace. Multi cursor is even more helpful when you need to add a value for a column to each statement but the character column is different for each line. Usually one would edit the lines manually one after another. Using multiple cursors could be faster since you start selecting the code places and then only need to do the typing once.

Navigating an IDE

IDEs have many awesome features these days. Important basics are to be learnt when navigating this big pile of tabs and windows. More functionality would go beyond the scope of this article.

Switching between editor and sidebar tabs

A lot of mouse work is usually done when switching focus between file editor window, sidebar and other sidebar tabs (e.g. terminal, test or application execution). This can be avoided if you know what to do with your keyboard instead.

Navigating IntelliJ IDEA with only a keyboard

Mac OSWindows & LinuxWhat it does
EscEscBack to file editing (e.g. after sidebar or other tab focus)
⌘ + WCtrl + F4Close current file or sidebar tab
⌘ + [1-9]Ctrl + [1-9)Jump to file tree sidebar (or other bookmarked tab)
Arrow keys, EnterArrow keys, EnterNavigating file tree, expanding/collapsing directories & opening files

Often one also wants to navigate only the edited file tabs. This is done just like switching tabs in a web browser. In JetBrains IDEs you can additionally use the “Switcher” dialog after holding Ctrl and tapping Tab one time. Pressing Tab in the switcher allows you to switch between lines. There are also other navigation targets next to your currently opened or recently visited files worth looking at.

Finding things

Hunting down a bug, implementing or extending a feature, looking up how things were implemented in other cases – often it all begins with finding the correct place in a code base.

Finding things in IntelliJ IDEA

Fortunately IDE developing companies know that, too, and offer clever search features. During “Search & Replace” we already learned how to search for string occurrences.
IDEs can also search for files, classes, symbols and more.

ShortcutWhat it does
⌘ + Shift + OSearch files by name/pattern
⌘ + OSearch classes
⌘ + Alt + OSearch symbols
⌘ + Shift + ASearch IDE actions
Double ShiftSearch everywhere

Using search functionality is very important in every phase of working on a software project. It will get you started with a codebase to learn the names of files, classes and symbols – even if you have to try multiple times until you find them. While learning more about a codebase, you can go back to known pieces of code directly by name. Sounds stupidly basic but it’s extremely powerful.

More actions in an IDE

As mentioned, this article only scratches the surface of what is possible with IDEs and keyboard shortcuts. For further reference most IDEs have nice PDF cheat sheets. They’re worth printing out for hanging them next to your monitor:

If you don’t know a shortcut but want to execute an action, there is also search functionality for actions. JetBrains IDEs let you search for actions with ⌘/Ctrl + Shift + A. This still saves you many mouse movement meters compared to a mouse-only approach.

A plugin worth mentioning is Key Promoter X which detects actions that are invoked via mouse and promotes their shortcut to you:

IntelliJ IDEA - Key Promoter X plugin

Jetbrains IDEs also contain a tool called “Productivity Guide” that records how often actions are invoked by mouse vs shortcut. It’s a good tool for learning which shortcuts could be further incorporated in your daily use. You can find it by searching through all actions or via the help menu.

Cross-IDE keymaps

Another problem worth mentioning is switching IDEs as it often implies the challenge to learn a new keymap. If you don’t want to learn a new keymap (directly), there is often the possibility to import or imitate the keymap of another IDE.
If you want to use JetBrains’ keymap in VSCode, there is the IntelliJ IDEA Keybindings plugin. For getting started with VSCode keymap in JetBrains IDEs, the other way around is possible using VSCode Keymap. Many people have trouble switching from Eclipse to IntelliJ IDEA which could be easier when sticking with the Eclipse Keymap plugin for JetBrains IDEs.

You can do it!

Give it a try and trust yourself in making progress! It’s always worth investing time in learning or improving skills. Progress also means going two steps forwards followed by one step backwards. Relearning daily routines takes time and you will most probably become slower before your efforts start to pay off. Remember how you learned to type with ten fingers? Take this to the next level.

I am very certain that there are many more coding productivity hacks out there. If you have some at your hand, let me know in the comments – I would be happy to read your experiences!

As a full stack developer, Jonas is passionate about developing digital products in agile, cross-functional teams. He prefers to use cloud native ideas such as Serverless and managed services from AWS (Amazon Web Services). Originally influenced by Java, he now prefers Node.js, TypeScript and modern JavaScript tooling.

Comment

Your email address will not be published. Required fields are marked *