6 Tips to Improve Your Coding Speed [LAZY EDITION]
“I choose a lazy person to do a hard job. Because a lazy person will find an easy way to do it.” - Bill Gates
I couldn't agree more with this old quote from Bill Gates. I found that as I'm thriving as a developer, I tend to get lazier and the lazier I get, the more I acquire fast coding techniques. Let me share some of my favorite techniques with you folks.
1. Move cursor by word
Let's start with the most basic one. I believe most of us are already using this. It's simple, you can use the keyboard shortcuts Ctrl +←/→ (Windows) or Alt +←/→ (Mac)
Now you can navigate the codebase faster.
If you hold the Shift button along the way then it selects the word for you. Neat!
2. Add cursors to line ends
Let's say you have to edit multiple lines of content to be the same, you can simply highlight all the lines and split the cursors to each line's end. Then you can edit those lines simultaneously.
The actual command name depends on the editor you use. Mine is Visual Studio Code and the exact command for this is "Add cursors to line ends". The shortcut key is Alt + Shift + I (Windows) or Command + Shift + l (Mac).
3. Add selection to next find match
When you want to replace some "A" with "B" but the "Replace All" function just replaces every occurrence and ruins the mood, try this.
For Visual Studio Code, the shortcut is Ctrl + D (Windows) or Command + D (Mac).
4. Join lines
Sometimes after refactoring, you find out that a part of your code containing multiple lines can be reduced to a single line for better readability. Select all the lines and join them. For VS Code, that's the Join Lines command Ctrl + J (Windows) or Command + J (Mac). You might also notice that I've used tip number 3 to format the space between each function chain. However, if you have some code formatting or linting tool set up with an auto-fix feature, that will solve the problem right away.
Another example would be copying a multiline paragraph and storing it as a string variable.
5. Move Line(s) Up/Down
Want to rearrange function order while refactoring or want to change the order of code execution? Have you been using the Cut/Paste method? Worry not, we have an easier way to do this.
Notice that the editor also takes into account the indentation style if the language syntax is recognized. For VS Code, the key command is Alt + Up/Down Arrow.
6. Duplicate selection
You can actually duplicate your current selection which is very useful for populating a list or any kind of collection depending on the context.
Extra: Use extensions
As mainstream editors are open to extension contributions, we can find many useful plugins that speed up our workflow. What extension to use depends on your use case. I can give you an example. Very often I have to create mock data with running numbers, so I ended up using Insert Numbers.
As you can see, being lazy led me to find better and faster ways of finishing redundant steps. This might not feel like it has a big impact, but when used frequently, it can be a huge time saver resulting in higher productivity.
7. Use multi-caret selection to edit multiple lines at once
Ever wished you could edit multiple lines of code at the same time? Well, you can! Multi-caret selection is a game-changer for making the same edit in multiple places at once. To use this feature, press Ctrl + Alt + mouse click (Windows) or Alt + Shift + mouse click (Mac) to create multiple carets. Then, you can use Ctrl + Shift + arrow keys to expand your selections.
For instance, if you want to add a semicolon at the end of several lines, simply create multiple carets at the end of each line and type a semicolon. Voilà! The semicolon is added to all the selected lines simultaneously. This feature is particularly handy when you want to make repetitive changes without the hassle of editing each line individually.
8. Use the “find and replace” feature to quickly update code
The “find and replace” feature is your best friend when it comes to quickly updating your code. You can use this tool to find specific words, phrases, or patterns and replace them with new ones. To access the “find and replace” feature, press Ctrl + F (Windows) or Command + F (Mac) for finding, and Ctrl + H (Windows) or Command + H (Mac) for replacing.
For example, if you want to replace all instances of a variable name with a new name, simply enter the old variable name in the “find” field and the new variable name in the “replace” field. Then, click the “replace all” button to update your code in one go. This feature saves you from the tedious task of manually searching and replacing each instance, making your coding process much more efficient.
9. Customize user and workspace settings to suit your needs
Customizing your user and workspace settings can significantly enhance your coding efficiency. You can adjust settings like font size, color scheme, and keyboard shortcuts to match your preferences. To access these settings, go to the “settings” menu in your editor and select the options you want to customize.
For example, if you want to change the font size of your code, navigate to the “settings” menu and select the “font size” option. Choose the font size that suits you best. You can also customize keyboard shortcuts for specific actions, such as adding a new line or deleting a selection. By tailoring your user and workspace settings, you create a coding environment that is perfectly suited to your needs, helping you work more efficiently and comfortably.
Which one do you use most often?
I'd like to know which of these matches your preference. Also, I'd like to learn some cool techniques from you as well. Feel free to leave comments in the comment section to share your ideas and methods. If you find this useful please make sure to leave a like and share this blog post. Thank you!
Aun Jessada - A full-stack Javascript developer interested in frontend, animations and user interface interaction. Experienced in game development, React and NodeJS. Also, a part-time musician, singer and songwriter.
Share:
Join the conversation
Comments
Zeus
April 23rd, 2022
My favorite tool is Ditto. Multi clipboard. Map it to control-shift-v and you get a list of your last (x) entries. Arrow keys and you select what you want, hit enter, and it pastes. I honestly believe that it has saved me years in programming time. I'm old, so...
control-end, control-home, control-shift-end, control-shift-home, etc. Just so dang useful.
control-end, control-home, control-shift-end, control-shift-home, etc. Just so dang useful.