Remapping backtick (`) and tilde (~) keyboard shortcuts on Windows
If you are a developer and work with Windows, it is very likely that at somepoint in time, you faced with an annoying little issue: typing a backtick and/or a tide in your code.
Maybe you use the new ES6 syntax and needed the backtick to interpolate your variables inside a string. Or maybe, you were trying to set up a CSS sibling selector.
In any case, typing these characters on Windows is quite uncomfortable. If you are lucky enough to have the numberpad on your pc, then you could use the default shortcuts provided by windows… if you can remember them!
The native backtick shortcut on Windows is
96 , whereas the native shortcut for the tilde is
The important point is that the numbers for these shortcuts must be typed on the number pad and, alas, not all computers (especially the small laptops) have the number pad on their keyboard, making it impossible to use them, forcing users to find the desirred characters somewhere on the internet or in other parts of code and copy/paste them, a very annoying procedure.
Have you ever heard of AutoHotKey?
AutoHotkey is a free, open-source scripting language for Windows that allows users to easily create small to complex scripts.
Well, this little program will save your life! You can download it free from its official website, and by doing so, you will be able to write and run some code, to remap all of your keyboard shortcuts.
Let’s see how ca we settle our tilde and backtick comfortable shortcuts thanks to AutoHotKey!
As stated above, we can install it from https://www.autohotkey.com/. We just need the Standard Installation. Once the wixard ends the installation, there’s no need to run the program.
Create a .ahk file
The main step is to write the script to bind our desired key combinations to print both
What I want to acheive is the following shortcuts:
If you want to use different key combinations, please refer to the AutoHotKey docs
Let’s start by creating a
startup.ahk file on your desktop. You can edit it with your code editor or with the default Windows Notepad. Now, type this:
Let’s have a look at the script:
There are 2 blocks of code, the first for the tilde and the second for the backtick. The first row of each block represents the key combinations in AutoHotKey language:
So in the firlst block “<^>!” represents the
AltGr key, “-” represents the
- key, while the
:: represent the end of the key combination. In the second block, the
-is substituted by the
' as we decided to use
' for the backtick shortcut.
The second line represents what we want the shortcut to return. In the first block we used
Send ~ (yes, you will have to copy paste the tilde for now); in the second we must use
SendRaw and include our backtick inside backticks(
```)because the backtick is a reserved character in AutoHotKey, so we need to escape it.
Third lines obviously represent the end of our blocks.
Now, save the file, close it and double click on it. Now our shortcuts will magically work in every program on the PC! This means not only your into your favourite code editor but also in the web browser, on Microsoft Word, in the e-mails and so on… at least untill we shut down the pc! :/
Automatically execute the script at PC startup
Although it is possible to put the file on the desktop and double click on it everytime we turn on the computer, there is a much better way to make our shortcut automatically available at all time.
All you need to do is moving this
startup.ahk file, inside this folder:
Remember to replace
YOUR_USER above with your user name. Also note that the
AppData is a hidden folder, so if you don’t see it inside your user’s folder be sure to set the hidden folders as visible.
Startup folder is a special folder whose files will be executed when we access Windows. Moving our file inside there, will ensure our script to be ran behind the scene every time we turn on the computer!