How do I remap my Ubuntu keyboard shortcuts to match OSX?
Solution 1
There's no need to use xbindkeys
to achieve OSX-like keyboard mapping on Ubuntu. This is a built-in option:
- Go into your Ubuntu Settings
- Navigate to Keyboard → Keyboard Layout Settings
- add English (Macintosh)
Solution 2
couldn't you add custom shortcuts?? If that wasn't possible or didn't work you might want to change the keybindings of your vmbox. You'll need to do the following:
Install xbindkeys
sudo apt-get install xbindkeys
Xbindkeys is a very versatile program that lets you remap keys very easily. It uses a config file, my default located in your home directory, to change key bindings into certain commands.
To create a default config file you use the command:
xbindkeys --defaults
Which prints the default config file. So if you want to create the file containing the default values you would use:
xbindkeys --defaults > $HOME/.xbindkeysrc
Which prints the default values into a hidden file named .xbindkeysrc located in home.
Now to actually change the bindings of keys we first need to know what the name or keysym of those keys is. xbindkeys allows us to use the -k handle to find the name of a key or key combination. Run:
xbindkeys -k
Now press ctrl (of cmd) and check the output
Try pressing ctrl + c (after disabling that shortcut in the terminal using the second part of this explination)
It will tell you the name of the key/key combination.
Now we need to tell linux to call upon cmd when ctrl is pressed.
for this we will need an extra piece of software as xbindkeys does not support this on it's own. I know of two programs which we can use, xdotool and xte. I prefer xte so I'm going to use that.
Install it:
sudo apt-get install xautomation
(
To call a single key press: xte 'key keyName'
To call a key combination: xte 'keydown keyName' 'keydown secondKeyName' 'keyup keyName' 'keyup secondKeyName
For more info you can read the manual man xte
)
Lets open up the config file you made earlier: (the one you made using xbindkeys --defaults > $HOME/.xbindkeysrc
)
gedit .xbindkeysrc
You'll get something like this:
#
# A list of keys is in /usr/include/X11/keysym.h and in
# /usr/include/X11/keysymdef.h
# The XK_ is not needed.
#
# List of modifier:
# Release, Control, Shift, Mod1 (Alt), Mod2 (NumLock),
# Mod3 (CapsLock), Mod4, Mod5 (Scroll).
#
# The release modifier is not a standard X modifier, but you can
# use it if you want to catch release events instead of press events
# By defaults, xbindkeys does not pay attention with the modifiers
# NumLock, CapsLock and ScrollLock.
# Uncomment the lines above if you want to pay attention to them.
#keystate_numlock = enable
#keystate_capslock = enable
#keystate_scrolllock= enable
# Examples of commands:
Earlier you extracted the key/key combination. now that you know the command for simulating key presses you can call it from your xbindkeys script, like this:
"xte 'ctrl'" Cmd (or something like this depended upon the name given to you by xbindkeys)
Add this to you're xbindkeys script and save it.
You'll notice that it doesn't work (yet). That's because xbindkeys isn't running yet. start it with the following command.
xbindkeys
Your commands should work now. If it doesn't work you might wanna try adding commands to your key-combinations like copy and paste. If that doesn't work either there is an alternative but that's quite a lot of writing. You could also try xmodmap or xkeycaps.
I would like to note that xbindkeys and xte don't always work well together.
As for your terminal shortcuts: You can change them ALL by opening your terminal and clicking edit in the top bar. Then click keyboard shortcuts and change the value of copy and paste under the header "edit" into ctrl (or in your case cmd) + c and ctrl + v
Solution 3
Searching in other questions I've found this tool to map the Ctrl to the Macbook key board CMD Left to do CMD + C or CMD + V or something else:
Install gnome-tweaks application:
sudo apt-get install gnome-tweaks
Open the application Applications -> Gnome Tweaks
and map the CTRL to WIN(Same as CMD in Mac) doing this:
- Keyboard and Mouse
- Additional Layout Options(Left Super)
- Alt/Win key Behavior
- Ctrl is mapped to Win and the usual Ctrl keys`
Enjoy the CMD + C or CMD + V
in your OSX VirtualBox using ubuntu-18 VM.
Solution 4
This is an updated answer for anyone struggling with this issue with more recent versions of Ubuntu.
I have just installed Ubuntu 16.04.1 via VirtualBox and was unable to get the keyboard settings to match my MacBook.
Here's what I did to fix it:
- Navigate to System Settings.
- Select Text Entry (i.e. not Keyboard).
- Underneath the list with the heading Input sources to use: there is a plus and a minus sign - click on the plus sign.
- In the text box under Choose an input source type in the keyboard layout that you require (in my case I choose English (UK, macintosh).
- Use the up arrow to make it your default keyboard layout on Ubuntu.
- Remove the other keyboard layouts. It wasn't until I removed the other layouts that the changes took effect.
Solution 5
I'm on Ubuntu 16.04, VirtualBox 5.1.22 and none of these answers worked for me - including David Brower's unfortunately.
Here's what did to get my left OSX Command key working (persistently!):
- First you need to ensure VirtualBox isn't using Left ⌘ as the Host key
- In the top menu bar of your VM window select
Input > Keyboard > Keyboard Settings..
- In the list of settings, find Host Key Combination, and change shortcut to something other than Left ⌘ (I just used Right ⌘ as I never use it).
- In the top menu bar of your VM window select
- Now that you can definitely use the Left ⌘ in within the VM environment, remap the keys with XKB:
- Open and (carefully) edit:
/usr/share/X11/xkb/symbols/pc
- I simply swapped
<LCTL>
and<LWIN>
around, so it looks like this: key <LCTL> { [ Super_L ] };
key <LWIN> { [ Control_L ] };
- Open and (carefully) edit:
- Now clear the old mappings from xkb cache:
rm -rf /var/lib/xkb/*
- Restart ubuntu for changes to take effect.
Word of warning: I'd avoid making more than one change at a time via xkb unless you really know what you're doing, a couple of keys mapped incorrectly at the same time could be a real headache!
Full Credit to Radu Cotescu for the xkb remapping instructions - they were for ubuntu 14.04, however they work fine for ubuntu 16.04.
user209499
Updated on September 18, 2022Comments
-
user209499 over 1 year
I'm using Ubuntu in VirtualBox on Mac. As I switch frequently, I would like to use the same shortcuts. Please, does anyone know how to have the same shortcuts on Ubuntu, as they are on Mac?
Specifically, I would like to Copy, Paste, Select All, ... work with Cmd+C, Cmd+V, Cmd+A, ... (even in terminal - no Ctrl+Shift, just Ctrl).
I tried to change Keyboard Layout to Apple Laptop, but that didn't help.
-
web.learner over 10 yearsIs the Cmd key the alternative to Ctrl or Alt?
-
Kaz Wolfe over 10 yearsIf I remember correctly, Cmd is equal to ctrl.
-
velop over 7 yearscmd is equal to the windows function key (whereas the cmd key is next to the spacebar). Most times between ctrl and alt.
-
-
Akisame over 10 yearsthese are solutions to fix your problem INSIDE the vmbox. You might be able to exchange certain keyscodes by setting up a keycode exchange table in your vmbox but I don't have any experience with vmboxes
-
chovy over 9 yearsI do not see
Keyboard Layout Settings
on Ubuntu 14.0.4 -
chovy over 9 yearsThis does not work on VirtualBox. All i got was a shrunken window when I tried copy/paste.
-
Allisone over 8 yearslol, after so much time trying all the other solutions out there, this one is so easy and worked immediately. (Ubuntu 14.04.3 LTS 64bit in VirtualBox 5.0.4). Thanks
-
Peter Brooks about 8 yearsThis doesn't work for me, on virtualbox.
-
willem dafoe about 8 yearsThis doesn't work at all, bro.
-
boulder_ruby over 7 yearsThis answer clearly no longer works for newer versions of Ubuntu. Whatever the latest version of Ubuntu was in 2014, it worked for that.
-
David Brower over 7 yearsCan confirm. I had the option when installing. Stupidly just went with the default and now can't change it.
-
Coljac almost 7 yearsWhat is the effect of this? For instance, the control key on a Macintosh is in the same place as on a normal keyboard. Since ctrl-c/v still remain the system default copy and paste commands, this won't answer the original question of remapping those sorts of system-wide shortcuts so it mimics a Mac.
-
garmoncheg over 6 yearsWorked like a charm for my Ubuntu... Easy and elegant solution. Many Thanks!
-
Kirkland about 6 yearsI found this setting option in "Region and Language" on Ubuntu 18.04.
-
Zoltan about 6 yearsUnfortunately the layout settings, aka using English (Macintosh), does not change the standard key bindings. For example, you still have to use CTRL+C and CTRL+V for copy and paste.
-
tom over 5 yearsMake sure you take a snapshot before you do this! I fortunately had for another purpose, and after doing this, Ubuntu wouldn't boot properly. I reverted and it started working again. I'm using 18.04 for what it's worth.
-
skwny about 5 yearsWorked. <filler>
-
Chris almost 5 yearsThis is as close as I've ever gotten to getting mac bindings on linux. However it seems
xte 'key Home'
doesn't work when tied to any keystroke in the .xbindkeysrc file. I've tried a variety like "Shift + i". I've also seen it work by doing `sleep 15 && xte 'key Home'" (switching to gedit and seeing home work). The most feedback I get when I have things setup with "Alt + Left" for home is a flash of the cursor. Any assistance on this? gist.github.com/Kikketer/658d89661a044121279afbba04a511fa -
Turgs over 4 yearsThis lost me the ability to use the Win/Apple key. Instead, I did the following for Step 3 and 4:
(3) Ctrl position, (4) Swap Left Win with Left Ctrl
. -
Graham P Heath almost 3 yearsOn PopOS v20.10 (a Ubuntu variant) the path to this setting is: Settings -> Keyboard -> + (add input source) -> English ([your locale]) -> English (Macintosh). I found the last step confusing since I already had English (United States).
-
Shiwakant Bharti over 2 yearsThe above solution lost me the ability to use alt keys. Fixed with Ctrl position: Left Alt as Ctrl, Ctrl as Win, Win as Left alt. Test it via - keyboardtestt.com or onlinemictest.com/keyboard-test
-
Vladimir Tolstikov over 2 yearsVery good solution for latest Ubuntu 20. @Turgs comment is correct as well, need to do that instead of described initial settings. Also would suggest to change
System Settings -> Keyboard Shortcuts -> Switch applications
toCtrl + Tab
after that so you feel more comfortable if mainly using macOS.