Is it possible to use arrow keys alone to expand tree node in package explorer in Eclipse on Linux?

LinuxEclipseUbuntuIdeKeyboard Shortcuts

Linux Problem Overview


When using Eclipse I browse through the package explorer tree using the keyboard arrows a lot.

In Windows I can expand a collapsed node by pressing the ā†’ key. In Linux I need to press Shift + ā†’. Is there a way to reconfigure this so that Shift is not required?

Linux Solutions


Solution 1 - Linux

Put this into your ~/.gtkrc-2.0 and you should be good to go. The Left and Right lines make the requested change, the rest are just my personal additions to make the tree-view act more vim-like. Hope that helps!

binding "gtk-binding-tree-view" {
    bind "j"        { "move-cursor" (display-lines, 1) }
    bind "k"        { "move-cursor" (display-lines, -1) }
    bind "h"        { "expand-collapse-cursor-row" (1,0,0) }
    bind "l"        { "expand-collapse-cursor-row" (1,1,0) }
    bind "o"        { "move-cursor" (pages, 1) }
    bind "u"        { "move-cursor" (pages, -1) }
    bind "g"        { "move-cursor" (buffer-ends, -1) }
    bind "y"        { "move-cursor" (buffer-ends, 1) }
    bind "p"        { "select-cursor-parent" () }
    bind "Left"     { "expand-collapse-cursor-row" (0,0,0) }
    bind "Right"    { "expand-collapse-cursor-row" (0,1,0) }
    bind "semicolon" { "expand-collapse-cursor-row" (0,1,1) }
    bind "slash"    { "start-interactive-search" () }
}
class "GtkTreeView" binding "gtk-binding-tree-view"

then restart your Eclipse to apply new bindings

Solution 2 - Linux

If anyone is wondering how to do this with GTK3 - simply open ~/.config/gtk-3.0/gtk.css and add the following:

@binding-set MyTreeViewBinding
{
    bind "Left"     { "expand-collapse-cursor-row" (0,0,0) };
    bind "Right"    { "expand-collapse-cursor-row" (0,1,0) };
}

GtkTreeView
{
  gtk-key-bindings: MyTreeViewBinding;
}

Solution 3 - Linux

My version for GTK3 that behaves in more natural way. Add the following to ~/.config/gtk-3.0/gtk.css:

@binding-set MyTreeViewBinding
{
    bind "Left"     { "select-cursor-parent" ()
                      "expand-collapse-cursor-row" (0,0,0) };
    bind "Right"    { "expand-collapse-cursor-row" (0,1,0) };
}

GtkTreeView
{
    gtk-key-bindings: MyTreeViewBinding;
}

Solution 4 - Linux

The answer provided by Andrew is correct. Please note that in newer versions of Ubuntu there is no ~/.gtkrc-2.0 file, so you can either create it or you can edit the gtkrc of your current theme, which is stored in

/usr/share/themes/your_theme/gtk-2.0/gtkrc

Solution 5 - Linux

I tried to use the answer from @Andrew Lazarev. However due to a non backward compatible change on GTK3.20 (https://bugzilla.gnome.org/show_bug.cgi?id=766166) the bindings have to be slightly adapted:

@binding-set MyTreeViewBinding
{
   bind "Left"     { "select-cursor-parent" ()
                  "expand-collapse-cursor-row" (0,0,0) };
   bind "Right"    { "expand-collapse-cursor-row" (0,1,0) };
}

treeview
{
   -gtk-key-bindings: MyTreeViewBinding;
}

Note the - before gtk-key-bindings and the GtkTreeView renamed to treeview.

Solution 6 - Linux

The navigation of Tree widget is controlled by underlaying widget toolkit - GTK. SWT/Eclipse has no control over it. If any such configuration is required for changing the short-cut, then it has to be made from the GTK side itself.

Solution 7 - Linux

Basing on YMomb answer I ended up with config bellow (~/.config/gtk-3.0/gtk.css). Works well with Eclipse 2021-09.

@binding-set MyTreeViewBinding
{
    bind "<Ctrl>Left" { "select-cursor-parent" ()
                   "expand-collapse-cursor-row" (0,0,0) };
    bind "Left"     { "expand-collapse-cursor-row" (0,0,0) };
    bind "Right"    { "expand-collapse-cursor-row" (0,1,0) };
}

treeview
{
  -gtk-key-bindings: MyTreeViewBinding;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlbView Question on Stackoverflow
Solution 1 - LinuxAndrewView Answer on Stackoverflow
Solution 2 - Linuxbig data nerdView Answer on Stackoverflow
Solution 3 - LinuxAndrew LazarevView Answer on Stackoverflow
Solution 4 - LinuxSebastianoView Answer on Stackoverflow
Solution 5 - LinuxYMombView Answer on Stackoverflow
Solution 6 - LinuxPinnamuRView Answer on Stackoverflow
Solution 7 - LinuxMarek PodymaView Answer on Stackoverflow