score:19

Accepted answer

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;
}

score:1

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;
}

score:2

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.

score:5

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.

score:12

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

score:34

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;
}

score:113

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


Related Query

More Query from same tag