Making Snake Case More Convenient

One thing that I've always hated about snake_case naming style is that I've always found typing an underscore (_) to be an awkward keystroke. The best thing that I've done to make snake_case typing easier is to use AutoHotkey to create a hotkey to insert an underscore when typing Shift-Space. Here is the AutoHotkey script:

; Make typing the underscore '_' easier for snake_case_names while programming (now Shift+SpaceBar)
+space::_

After some practice, using Shift-Space to insert an underscore becomes natural.

One minor issue is that I sometimes accidentally type an underscore when I type a capital letter before a space by leaving the shift key down a bit too long. This can be worked around by making the hotkey above only active when certain programming applications (Visual Studio Code, Vim, etc.) have focus.

Here is an example that makes the hotkey active only if Visual Studio Code or Notepad has focus:

#HotIf WinActive("ahk_exe Code.exe") or WinActive("ahk_class Notepad")
+space::_

I hope this tip is as valuable to others as it has been for me.

5
Subscribe to my newsletter

Read articles from Michael R. Taylor directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Michael R. Taylor
Michael R. Taylor

I am an embedded software engineer in the industrial products market by day. During any free time I have, I enjoy working on desktop and Android applications.