How to remap or swap special keyboard keys in Linux? (2024)

If you are using Linux on MacBook or a key on your keyboard is broken or you have a special key on your keyboard and you want to use it differently than it is designed then you may feel the need to remap the keys of your keyboard. Remapping the keys means changing the input behaviour of your keyboard and making it work as we want, not as it was intended. In this post you will learn to remap the keys on Linux using ‘xmodmap’ and ‘xkb’ which are pre-installed on most of the linux distros. If you want to remap the keys in Windows then you can follow this post.

The ‘Delete’ key is broken in my laptop so I am going to remap it to ‘Insert’ key. The procedure is same for other keys as well. There are two methods for doing this, first method is safe and recommended method but if first method does not work then go for second method which includes modifying the system file and is not preferred. The steps are as follows:

First Method: Safe and recommended method

Step 1: Find the KeyCode (number assigned to key) and Keysym (name of key) for your desired keys to swap

xmodmap -pk

In my case 118 is KeyCode for Insert key and 119 is for Delete key.

Step 2: Swap the keys by issuing following command:

Now your keys are swapped but this action is not persistent and only works until you reboot. If you want to make your changes persistent then you need to write a script and make it auto execute at startup or you can make a .desktop file and make it run at every startup. I prefer .desktop approach.

Step 3: Create “swap.desktop” file and put it into ~/.config/autostart with following contents in it:

[Desktop Entry]Name=SwapExec=xmodmap -e "keycode 118 = Delete" && xmodmap -e "keycode 119 = Insert"Terminal=falseType=Application

Step 4: Now make it executable

chmod +x ~/.config/autostart/swap.desktop

This way the .desktop file will auto start on every boot and the keys are swapped.

Second Method: If the above method does not work then you can try this method but please be aware that this method modifies the system file so do not mess with the system file and do it carefully.

Step 1: First we will create a backup of the file in case anything goes wrong so that we can restore it later.

sudo cp /usr/share/X11/xkb/symbols/pc /usr/share/X11/xkb/symbols/pc.bak

Step 2: Edit the following file where ‘xkb’ stores the mapping of special keys:

sudo nano /usr/share/X11/xkb/symbols/pc

Step 3: Find the lines of the keys which are to be remapped:

key <INS> {[ Insert]};key <DELE> {[ Delete]};

Step 4: Remap the key behaviour by changing its action:

key <INS> {[ Delete]};key <DELE> {[ Insert]};

Step 5: Press ‘Ctrl+O’ to save and press enter then press ‘Ctrl+X’ to exit the nano editor.

Step 6: Clear the ‘xkb’ cache with following command:

sudo rm -rf /var/lib/xkb/*

Step 7: Finally quit the session and re-login.

Now you have successfully changed your keymap. If you get any unexpected result with this method then restore the backup we created earlier with following command and repeat Step 6 and 7.

sudo mv /usr/share/X11/xkb/symbols/pc.bak /usr/share/X11/xkb/symbols/pc

If you faced any trouble modifying your keymap or need any assistance comment below and I’ll help you to solve your problem. If you find it useful and think it will help others as well you can share the article on your favorite social media.

How to remap or swap special keyboard keys in Linux? (2024)
Top Articles
What is MetaTrader 4 and how do you use it PSO
TradingView Paper Trading - Here Is Why It's The Best In 2024
Gomoviesmalayalam
1970 Chevrolet Chevelle SS - Skyway Classics
Obor Guide Osrs
Pickswise the Free Sports Handicapping Service 2023
Green Bay Press Gazette Obituary
Ub Civil Engineering Flowsheet
More Apt To Complain Crossword
Texas (TX) Powerball - Winning Numbers & Results
Pwc Transparency Report
DIN 41612 - FCI - PDF Catalogs | Technical Documentation
What to do if your rotary tiller won't start – Oleomac
Wgu Admissions Login
Oro probablemente a duna Playa e nomber Oranjestad un 200 aña pasa, pero Playa su historia ta bay hopi mas aña atras
ocala cars & trucks - by owner - craigslist
The fabulous trio of the Miller sisters
Top tips for getting around Buenos Aires
Rhinotimes
Quest Beyondtrustcloud.com
25Cc To Tbsp
Plan Z - Nazi Shipbuilding Plans
Understanding Genetics
Conan Exiles Sorcery Guide – How To Learn, Cast & Unlock Spells
All Obituaries | Verkuilen-Van Deurzen Family Funeral Home | Little Chute WI funeral home and cremation
Costco Gas Hours St Cloud Mn
CVS Health’s MinuteClinic Introduces New Virtual Care Offering
Solo Player Level 2K23
Darknet Opsec Bible 2022
Mumu Player Pokemon Go
Hotel Denizen Mckinney
4083519708
Watchseries To New Domain
Mydocbill.com/Mr
Tiny Pains When Giving Blood Nyt Crossword
The TBM 930 Is Another Daher Masterpiece
2700 Yen To Usd
Google Flights Orlando
Newsweek Wordle
Senior Houses For Sale Near Me
Tlc Africa Deaths 2021
Mountainstar Mychart Login
Motorcycles for Sale on Craigslist: The Ultimate Guide - First Republic Craigslist
UNC Charlotte Admission Requirements
Steam Input Per Game Setting
10 Best Tips To Implement Successful App Store Optimization in 2024
Who Is Nina Yankovic? Daughter of Musician Weird Al Yankovic
Sleep Outfitters Springhurst
Ciara Rose Scalia-Hirschman
Lsreg Att
Craigslist.raleigh
Comenity/Banter
Latest Posts
Article information

Author: Jonah Leffler

Last Updated:

Views: 5979

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Jonah Leffler

Birthday: 1997-10-27

Address: 8987 Kieth Ports, Luettgenland, CT 54657-9808

Phone: +2611128251586

Job: Mining Supervisor

Hobby: Worldbuilding, Electronics, Amateur radio, Skiing, Cycling, Jogging, Taxidermy

Introduction: My name is Jonah Leffler, I am a determined, faithful, outstanding, inexpensive, cheerful, determined, smiling person who loves writing and wants to share my knowledge and understanding with you.