Thursday, March 16, 2017

IntelliJ on Ubuntu the false promises

I guess every one who develops with IntelliJ on Ubuntu is disappointed that the keyboard shortcuts do not work as they should.
The problem is that Ubuntu (Linux in general) maps a lot of keyboard shortcuts.

Here is the list of keyboard shortcut doing problems but that I do need in IntelliJ:
  • Ctrl+Alt+Left/Right : back in IntelliJ
  • Ctrl+Alt+L : reformat code
  • Alt+F7 : find usage
  • Alt+F8 : evaluate expression
  • Ctrl+Alt+S : settings dialog
  • Alt+Mouse Button 1 : Block selection
  • Ctrl+Shift+U : to uppercase
  • Alt+F1 : select in

First if you are working in a virtual machine like VmWare

Ctrl+Alt+Left is most probably used to switch between vm. So is you are using VmWare navigate to and change the combination
  • VmWare: Edit->preferences->hot keys

Some of these can be changed in Ubuntu keyboard settings

For these I used to remove the settings in Ubuntu.
  • Ctrl+Alt+L : settings->keyboard->shortcuts->system->lock screen
  • Alt+F7 : settings->keyboard->shortcuts->windows->move window
  • Alt+F8 : settings->keyboard->Windows->resize window 
  • Ctrl+Alt+S : settings->keyboad->windows-> toggle shade state

Some can be set at other places in the gui.

In the dconf editor: 
  • Alt+Mouse Button 1 /org/gnome/desktop/wm/preferences/mouse-button-modifier
    You can't just disable the key, you must assign it to something fancy like Ctrl+Alt+Shift+Super+Escape
This one is still at another location

The interesting part is that some of these can be changed on the console:

Changing keyboard shortcut from the command line

In order to have the complete list of shortcut available, try this command
gsettings list-recursively

Which gives us the following commands
  • Ctrl+F8 : gsettings set org.gnome.desktop.wm.keybindings begin-resize "['disabled']"
  • Ctrl+Alt+S : gsettings set org.gnome.desktop.wm.keybindings toggle-shaded "['disabled']"
  • Ctrl+Alt+L: dconf write /org/gnome/desktop/screensaver/lock-enabled false
  • Alt+Mouse Button 1: gsettings set org.gnome.desktop.wm.preferences mouse-button-modifier "['Escape']"
  • Ctrl+Alt+Right : gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-right "['disabled']"
  • Ctrl+Alt+Left : gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-left "['disabled']"

Ansible

We can take this a step further and use ansible.
By putting this script in a file: e..g, main.yml in ubuntu/tasks folder, with a hosts file containing 

hosts file
[localhost]

localhost ansible_user=dev ansible_connection=local

playbook.yml file
- hosts: localhost
  roles:
  - intellij

  - ubuntu

note that the initellij task do some additional configuration. like a quick list config etc.

Finally the following command should do the trick:

ansible-playbook -i hosts playbook.yml

- name: disable screen lock see http://xmodulo.com/control-screen-lock-settings-linux-desktop.html
  command: dconf write /org/gnome/desktop/screensaver/lock-enabled false
  tags: [ubuntu]

- name: disable mouse-button-modifier do not disable dconf Editor key /org/gnome/desktop/wm/preferences/mouse-button-modifier
  command: gsettings set org.gnome.desktop.wm.preferences mouse-button-modifier "['Escape']"
  tags: [ubuntu]

- name: disable keyboard->Navigation->switch workspace org.gnome.desktop.wm.keybindings switch-to-workspace-right ['Right']
  command: gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-right "['disabled']"
  tags: [ubuntu]

- name: disable keyboard->Navigation->switch workspace org.gnome.desktop.wm.keybindings switch-to-workspace-left ['left']
  command: gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-left "['disabled']"
  tags: [ubuntu]

- name: disable keyboard->Windows->resize window | evaluate expression org.gnome.desktop.wm.keybindings begin-resize ['F8']
  command: gsettings set org.gnome.desktop.wm.keybindings begin-resize "['disabled']"
  tags: [ubuntu]

- name: disable S shortcut. keyboad->windows-> toggle shade state
  command: gsettings set org.gnome.desktop.wm.keybindings toggle-shaded "['disabled']"

  tags: [ubuntu]

Short cut to change in IntelliJ

 - The Navigate -> Select in shortcut is normally mapped to Alt-F1 which I do not want to unmap in Ubuntu. So I add another shortcut in IntelliJ

File->Settings->Keymap->Main menu->Navigate->Select In 
And I give the short cut: Ctrl-§

References

Alt+Left Button  see http://askubuntu.com/questions/118151/how-do-i-disable-window-move-with-alt-left-mouse-button-in-gnome-shell
I don't know how to deactivate Alt+F1 so I have to change the mapping in IntelliJ
check this post : http://askubuntu.com/questions/412046/unable-to-use-intellij-idea-keyboard-shortcuts-on-ubuntu