How to Create Keyboard Shortcuts for PHP

I finally grew tired of typing the awkward PHP object operator. Learn how to create keyboard shortcuts for KDE and use my shortcuts for PHP as a starting point.

My preferred server-side language is PHP. It's powerful and flexible, but it's certainly not perfect. One of my pet peeves is the object operator (->). I've programmed in C++, so I can appreciate its heritage. It's simply not needed in this case, so it feels like overkill to have to repeatedly type such an awkward key combination. Why should I move my hand to the top row for one key and hold shift for another when a single dot would be perfect for the task? Is it solely a byproduct of the poor decision to use the dot for string concatenation? I finally got fed up enough to look for a solution.

As with many desktop environments, KDE allows you to configure keyboard shortcuts that trigger a specific set of keystrokes. You can create your own in System Settings -> Shortcuts and Gestures -> Custom Shortcuts. From the Edit menu, select New -> Global Shortcut -> Send Keyboard Input. On the Trigger tab, click the button and provide the shortcut you want to use. Then select the Action tab and enter the keystrokes you want the shortcut to send. Type out the words for meta keys like Shift and Alt, use + to indicate keys that should be pressed simultaneously, and separate the keys using a colon. For example, -:Shift+. will output - and > (the object operator). You can also use directional words (e.g., Left and Right) for the arrow keys to position the cursor within the output.

I created keyboard shortcuts for the object operator, $this member reference, a code block, and the short echo tag. It's not a fancy solution, but it makes PHP development even easier. Rather than listing all the triggers and output in this blog post, I've made my PHP keyboard shortcuts for KDE available to download. You can use them exactly as they are or as a starting point to create your own. If you have other ideas for PHP keyboard shortcuts, list them in the comments below. Happy coding!

comments powered by Disqus