Some practical keyboard tips for the newbie coder

After I started writing code professionally 2 years ago, my code writing speed increased drastically. This definitely has a lot to do with using the same language and framework, however I realized that this increase in speed also applies to different programming languages and frameworks. The key to writing code faster and easier is to have high control over your keyboard. The keyboard is both your friend and your partner in crime. Below I will list some advice on how to improve your code writing skills, though some of them might be editor/IDE dependent.

  1. First things first, if you want to code efficiently, use an English layout on your keyboard no matter what your native language is. For example in the Turkish-Q layout, most of the characters that are used frequently while coding (i.e. {}, [], <>, |, ;, :, \ and so on) are all scattered across the keyboard and some of them require Ctrl+Alt to generate. In the English layout, these are mostly packed on the right side of the keyboard and don’t require more than Ctrl to generate.
  2. Being a teaching assistant to an introductory programming course at my university, I saw that students don’t even use the simplest keyboard shortcuts like Ctrl+S, Ctrl+Z, etc. Use them. Instead of using the menu on top of your IDE to save (which you should after writing even a line of code) or undo/redo, you can simply use Ctrl+S to save, Ctrl+Z to undo, Ctrl+Y (or Ctrl+Shift+Z on some editors/IDEs) and some other key-bindings provided by your editor/IDE.
  3. Use the mouse as little as possible. To those of you who would complain how to navigate between lines and words, I would like to remind you that the keyboard is your friend. Remember those buttons you’ve never used before like Home, End, Page Up and Page Down? They are there to help you. Home will bring the text cursor to the beginning of the line and End will do the exact opposite, bringing the text cursor to the end of the line. To scroll up and down on the file you’re working on, you can simply use Page Up and Page Down. If you don’t want to navigate to the end or the beginning of the line, you can use Ctrl to navigate between words. Use Ctrl+→ to go to the next word and Ctrl+← to go the previous one. These keys can all be used with the Shift key so that you can highlight the text. Using these keys will save you a lot of time when you get used to it, compared to using the mouse to achieve all these.
  4. Using the Tab key is a must for having beautifully indented code. To indent multiple lines, instead of indenting each line one by one, you can select the lines you want to indent and then use Tab. Sometimes you may need to reverse-indent in situations where you change the scope of a line (or multiple lines). You can select the lines you want to indent and use Shift+Tab to reverse indent.
  5. indentation

  6. Some editors allow you to cut and paste whole lines without selection. For example in IntelliJ IDEA and Sublime Text 2, using Ctrl+C without selection will copy the whole line where the text cursor is currently at and Ctrl+X will have the same effect. One thing I learned recently is the use of Ctrl+D, which simply duplicates the current line.
  7. When you need to delete some words in your code, you can just press Ctrl+Backspace or Ctrl+Delete, depending on the direction you want to delete. These shortcuts will delete the portion of the word from the text cursor to the end or beginning, again, depending on the direction you want to delete.
  8. This one is heavily convention and editor dependent but using camel case on an editor where code completion is enabled will save a you a lot of time. Let’s say we have a variable named grassBladeTextureImage, typing the first letters of each word (gBTI in this case) will give you a smarter code completion suggestion if you have variables with a similar name to this one.
  9. indentation

  10. Edit: Okay I know I said use the mouse as little as possible but there are some cases where you might need to. This one shortcut simply blew my mind when a friend suggested me after reading this post. You can select multiple rows and columns of text using Alt+mouse selection. This is perfect for changing a piece of code for multiple lines. I’m not sure if this works on many editors but I’ve tried Visual Studio and Notepad++ and it seems to be working like a charm.
  11. indentation

These are the little tricks I use while coding. There may be a few that I’m missing and some of which I don’t know about. Please do tell me if I am missing any.

Please note that some of the stuff I wrote above are editor/IDE dependent and simple IDE’s or editors will not support them. Some editors I can suggest are Sublime Text 2 or Atom, which both give the user a great deal of flexibility via their support for plugins and useful key-bindings. As for IDE’s, you can use any IDE of JetBrains depending on the platform you’re working on, or Visual Studio together with ReSharper if you’re working with a language that they support.

P.S. I’m personally considering on switching to Atom myself because someone just wrote a plugin that lets you do this:

WHAT THIS IS SORCERY?

One comment

  • s

    Hello Halil, on point #4, consider letting your IDE enforce indentation policy, something like Ctl-A to select all, then Ctl-F to format all. You might want to change the formatter defaults… it’s best of course if your whole team uses the same settings. I’ve never tried Alt-Mouse 🙂 Happy coding!

    Reply

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.