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.
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.
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!