DEV Community

loading...
Cover image for Switching to en-US keyboard layout for development

Switching to en-US keyboard layout for development

equiman profile image Camilo Martinez Updated on ・6 min read

When I started to work I remember a senior developer advise:

Install and use everything in English. The whole developer world is focused on English first. Your life will be easier because when you found an error only need to copy it and paste it on a search engine, sure you will find that this question was already made.

catch(error){
   console.log(`https://stackoverflow.com/search?q={error.message}`)
}
Enter fullscreen mode Exit fullscreen mode

So, the first time that I see this joke, his words got sense. 😎


Last few days, I started to see a lot of non-American developers (Latam, Spain, France, Germany, India, and Hungary) that recommend moving to use the en-US keyboard layout.

And again his advise came before my very eyes:

If we are using the software in English and write code in English. Why not use hardware too?

Programming languages, IDEs, and Code Editors were designed and developed to use in English first, and if I'm not wrong I'm very sure were written with an English keyboard.

enUS

When these people were changed to this layout says that feel more natural, comfortable, and productive. I think this is due because symbols and keyboard shortcuts are made to use with en-US keyboard layout. I don't know if I'm right or not, but it has a lot of sense to me.

Switching to en-US keyboard also comes with an added benefit: never will be easy to buy a mechanical keyboard. For me, it's very hard or even impossible to found a good keyboard with es-LATAM layout.


Sound good, but... where are the accents? and the Ñ letter?

Everyone who needs any sort of diacritic or accent would ask the same question because the use en-US layout makes it unsuitable unless the US International layout is used.

Alt Text

This layout changes the ` (grave), ~ (tilde), ^ (circumflex), " (double quote, to make diaeresis), and ' (apostrophe, to make acute accent) keys into dead keys for producing accented characters: thus for example ' (release) a will produce á. The US International layout also uses the AltGr (Alt+Ctrl) as a modifier to enter special characters.

But this International layout has a critical downside for programming due to dead keys. We are going to lose speed because need to press two keys instead of one: the diacritic or accent followed by an ending character (space, tab or enter) to produce it.


So what can we do?

Just roll back to en-US layout and create a customs script for diacritic or accent.

I will detail the process to create a script to use with AutoHotKey for Spanish accents (my native language) and you can use it as an example in case you need to create your own.

  • First, you need to recognize the accents áéíóúñ letters and symbols ¡¿ that you want to remap and search his correspondent decimal value on the ASCII table.
Char Dec Char Dec
á 0225 Á 0193
é 0233 É 0201
í 0237 Í 0205
ó 0243 Ó 0211
ú 0250 Ú 0218
ñ 0241 Ñ 0209
¿ 0191 ? 63
¡ 0161 ! 33
  • Next, we need to remap each key with desired destinations following this format OriginKey::DestinationKey taken attention of his modifiers keys.
Char Modifier
^ Ctrl
! Alt
+ Shift
# Win
< Left
> Right
  • Create a script file called en-US_accents.ahk adding the remap configuration.
!a::Send {Asc 0225} ; Alt+a -> á
!+a::Send {Asc 0193} ; Shift+Alt+a -> Á
!d::Send {Asc 0233} ; Alt+e -> é
!+d::Send {Asc 0201} ; Shift+Alt+e -> É
!g::Send {Asc 0237} ; Alt+i -> í
!+g::Send {Asc 0205} ; Shift+Alt+i -> Í
!s::Send {Asc 0243} ; Alt+o -> ó
!+s::Send {Asc 0211} ; Shift+Alt+o -> Ó
!f::Send {Asc 0250} ; Alt+u -> ú
!+f::Send {Asc 0218} ; Shift+Alt+u -> Ú
!l::Send {Asc 0241} ; Alt+n -> ñ
!+l::Send {Asc 0209} ;  Shift+Alt+n -> Ñ
Enter fullscreen mode Exit fullscreen mode

In Spanish, the exclamation and question mark symbols need to be open at the beginning and close at the end.

!+/::Send {Asc 0191}{Asc 63}{left 1} ; Alt+/ -> ¿?
!+1::Send {Asc 0161}{Asc 33}{left 1} ; Alt+1 -> ¡!
Enter fullscreen mode Exit fullscreen mode

The last two have another trick. It will create open and close symbols and with the {left 1} command move the cursor between them.

If you work on Javascript, like me, it will be useful to create some shortcuts for logical comparison.

Char Dec Char Dec
= 61 < 60
! 33 > 62
$!7::Send && ; Alt+7 -> &&
!\::Send || ; Alt+\ -> ||
!=:: Send {Asc 61}{Asc 61}{Asc 61} ; Alt+= -> ===
!+=:: Send {Asc 33}{Asc 61}{Asc 61} ; Shift+Alt -> !==
!+,:: Send {Asc 60}{Asc 61} ; Shift+Alt+, -> <=
!+.:: Send {Asc 62}{Asc 61} ; Shift+Alt+. -> >=
!.:: Send ?. ; Alt+. -> ?.
!+/:: Send ?? ; Shift+Alt+/ -> ??
Enter fullscreen mode Exit fullscreen mode
  • Finally, Save the file and open it with AutoHotkey.

Excellent! It was better!

Not too fast my friend. We recently defined the shortcut Alt+Shift+A, but for example, VSCode also uses this same shortcut to toggle comments.

We can define the Left Alt as a modifier changing all the Alt+Shift+ maps to only works with (Right)Alt+Shift+. Just change !+ modifiers with >!+.

Now you can still use the LeftAlt+Shift+a on VScode and (Right)Alt+Shift+a to write the Á (with accent). It's up to you if you like to convert all Alt modifiers to (Right)Alt or only the combinations with conflicts.

Woohoo! Amazing!

Yes, it is! but I have other cool tricks.

If you already have a keyboard with a number pad at the right. Why not use the numbers row directly with symbols when Num Lock is active?

#if GetKeyState("NumLock", "T")
    *1::!
    *2::@
    *3::#
    *4::$
    *5::Send `%
    *6::^
    *7::&
    *8::Send `*
    *9::(
    *0::)
    $+1::Send 1
    $+2::Send 2
    $+3::Send 3
    $+4::Send 4
    $+5::Send 5
    $+6::Send 6
    $+7::Send 7
    $+8::Send 8
    $+9::Send 9
    $+0::Send 0
#if
Enter fullscreen mode Exit fullscreen mode

Those who use a Laptop or a TKL (Ten Key Less) keyboards can use Insert instead of NumLock or remove the if condition.

And how many times did you use the Caps Lock key? For me as developer results more useful to remap it as Backspace and have it directly on the home row.

CapsLock::Backspace
Enter fullscreen mode Exit fullscreen mode

Finally, we will have a compatible, fast, reliable, and useful en-US layout keyboard for development without leaving Qwerty.

en-dev

With a simple AutoHotkey script:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Modifiers
; ^ Ctrl
; ! Alt
; + Shift
; # Win
; < Left
; > Right

; Action
CapsLock::Backspace
PrintScreen::Send #+s

; Accents
!a::Send {Asc 0225} ; Alt+a -> á
>!+a::Send {Asc 0193} ; Shift+(Right)Alt+a -> Á
!e::Send {Asc 0233} ; Alt+e -> é
>!+e::Send {Asc 0201} ; Shift+(Right)Alt+e -> É
!i::Send {Asc 0237} ; Alt+i -> í
>!+i::Send {Asc 0205} ; Shift+(Right)Alt+i -> Í
!o::Send {Asc 0243} ; Alt+o -> ó
>!+o::Send {Asc 0211} ; Shift+(Right)Alt+o -> Ó
!u::Send {Asc 0250} ; Alt+u -> ú
>!+u::Send {Asc 0218} ; Shift+(Right)Alt+u -> Ú
!n::Send {Asc 0241} ; Alt+n -> ñ
>!+n::Send {Asc 0209} ; Shift+(Right)Alt+n -> Ñ

; Symbols
!/::Send {Asc 0191}{Asc 63}{left 1} ; Alt+/ -> ¿?
!1::Send {Asc 0161}{Asc 33}{left 1} ; Alt+1 -> ¡!

; Swap Numbers Row
#if GetKeyState("NumLock", "T")
    *1::!
    *2::@
    *3::#
    *4::$
    *5::Send `%
    *6::^
    *7::&
    *8::Send `*
    *9::(
    *0::)
    $+1::Send 1
    $+2::Send 2
    $+3::Send 3
    $+4::Send 4
    $+5::Send 5
    $+6::Send 6
    $+7::Send 7
    $+8::Send 8
    $+9::Send 9
    $+0::Send 0
#if

; JavaScript
$!7::Send && ; Alt+7 -> &&
!\::Send || ; Alt+\ -> ||
!=:: Send {Asc 61}{Asc 61}{Asc 61} ; Alt+= -> ===
!+=:: Send {Asc 33}{Asc 61}{Asc 61} ; Shift+Alt -> !==
!+,:: Send {Asc 60}{Asc 61} ; Shift+Alt+, -> <=
!+.:: Send {Asc 62}{Asc 61} ; Shift+Alt+. -> >=
!.:: Send ?. ; Alt+. -> ?.
!+/:: Send ?? ; Shift+Alt+/ -> ??
Enter fullscreen mode Exit fullscreen mode

I know there are a lot of keyboard layouts like Devorak, Colemak, Workman, Norman, and so on. I've tested a pair of them and I convinced myself that there is no perfect layout to rule them all.

But with the changes I propose to introduce with AutoHotkey, you will still be using Qwerty and will not have too many problems in case you will need to use another computer or someone use yours.

The good thing is that we have multiple options depending on our needs and tastes. Choose wisely whatever you think it's better for you.


Sources:


That’s All Folks!
Happy Coding 🖖

Buy me a cofee

Discussion (0)

pic
Editor guide