Results 1 to 7 of 7

Thread: [Hack] Removing the stupid Ctrl-D shortcut from gedit

  1. #1
    Join Date
    Sep 2009
    Beans
    72

    [Hack] Removing the stupid Ctrl-D shortcut from gedit

    Hi all,

    Well, I had a lot of trouble getting rid of the stupid Ctrl-D keyboard shortcut in Gedit, which deletes a line. Why stupid? Because unlike a ton of other shortcuts in the menus in gedit, this one is NOT in the menus, and thus it cannot be edited via "Editable menu shortcut keys" (Gedit/KeyboardShortcuts)

    So basically, the situation is as here:
    Quote Originally Posted by http://osdir.com/ml/gedit-list/2009-11/msg00005.html
    I was helping a buddy who is having the problem that he cannot change the shortcut for Delete Line, CTRL-D.

    We have used a plugin for editing menu shortcuts, but this specifik shortcut does not seem to be a menu shortcut, and thus cannot be edited with the plugin.

    Can somebody tell me how to change/remove the shortcut CTRL-D?

    He is using Ubuntu 9.10
    In my case, I'd want Gedit/LineToolsPlugin which uses Ctrl-D for duplicate line. Of course, by default it will not work either.

    Now, sure I can do:
    Code:
    apt-get source gedit
    cd gedit-2.26.1/
    nano ./gedit/gedit-view.c
    and comment out this section in gedit-view.c:
    Code:
    	/* gtk_binding_entry_add_signal (binding_set, 
    				      GDK_d, 
    				      GDK_CONTROL_MASK,
    				      "delete_from_cursor", 2,
    				      G_TYPE_ENUM, GTK_DELETE_PARAGRAPHS,
    				      G_TYPE_INT, 1); */
    but since I don't know the exact compilation line, in the end, the gedit I can build fails quite miserably; the steps I take are:
    Code:
    sudo apt-get install intltool gedit-dev libgconf2-dev
    ./configure --disable-spell
    make
    and while running gedit built in that way, I get errors:
    Code:
    Error opening directory '/usr/local/lib/gedit-2/plugin-loaders': No such file or directory
    So I thought, maybe there is a way to make a binary hack, so I don't have to go through all this building - and it turns out, there is!

    First, find out where is the binary, and change ownership to yourself
    Code:
    $ which gedit
    /usr/bin/gedit
    $ sudo chown myself\:myself /usr/bin/gedit
    Then open /usr/bin/gedit in a hex editor (I actually used Notepad++ under wine ), then search for the string "delete_from_cursor", and change it to "delete_from_cursXX"; and then save /usr/bin/gedit.

    If now you run gedit under gdb, you will notice that when you press Ctrl-D, you get:
    Code:
    sys:1: GtkWarning: gtk_binding_entry_activate(): binding "GeditView::<Control>d": could not find signal "delete_from_cursXX" in the `GeditView' class ancestry
    and FINALLY - no more deletion of lines happen! In fact, if you have LineToolsPlugin installed, Ctrl-D starts duplicating lines instead - which finally makes gedit truly rock

    Before I found this hack, I also tried using gconf-editor to set the /desktop/gnome/interface/gtk_key_theme from Default to Emacs (Gconf-editor - Wsms - btw, those themes refer to files:
    Code:
    /usr/share/themes/Default/gtk-2.0-key/gtkrc
    /usr/share/themes/Emacs/gtk-2.0-key/gtkrc
    ); of course, while most key bindings changed, Ctrl-D was untouched.

    Also, I tried the suggestion in Proper keyboard shortcuts in GTK+ − JNRowe: that is, I tried to make a new ~/.gtkrc-2.0 file, and place a key theme that would specifically override Ctrl-D:
    Code:
    $ gedit ~/.gtkrc-2.0
    
    binding "gtk-skip-d"
    {
        bind "<ctrl>d" { "move-cursor" (logical-positions, 1, 0) }
    }
    
    class "GtkEntry" binding "gtk-skip-d"
    class "GtkTextView" binding "gtk-skip-d"
    While this also didn't have any effect before the hack, after the hack this Ctrl-D (which moves a cursor) takes precedence in gedit, from the Ctrl-D functionality enforced by the LineToolsPlugin (the line duplication) - so I had to (re)move ~/.gtkrc-2.0 in order to get the proper functioning I wanted.

    Well, hope this helps someone,

    Cheers!

  2. #2
    Join Date
    May 2008
    Location
    Ireland
    Beans
    12
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [Hack] Removing the stupid Ctrl-D shortcut from gedit

    Thanks a million, I normally would use Notepad++ and was always deleting lines just from habit in gedit. I had recently installed the same plugin as you, and thought it would override the Ctrl+D.

    Your little binary hack worked a charm. Took me 2 mins and works great

    Cheers for the hard graft,
    Har

  3. #3
    Join Date
    Apr 2006
    Location
    Nashville, TN. USA
    Beans
    1
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: [Hack] Removing the stupid Ctrl-D shortcut from gedit

    Thanks so much for this tip. It worked perfectly. I've been trying on and off for a week to sort this CTRL+D issue out. I'm also coming from notepad++ and using CTRL+D to duplicate a line was a feature I used constantly. That was the most nagging issue I had in making ubuntu my primary OS. I was still willing to deal with it for all of the advantages though.

    Thanks again,
    -simmond78

  4. #4
    Join Date
    Oct 2006
    Beans
    6
    Distro
    Ubuntu 6.06

    Re: [Hack] Removing the stupid Ctrl-D shortcut from gedit

    Much easier work around....

    Unbind/Rebind Ctrl+D in Gedit
    The second example in page above has code to disable the default CTRL+D. Just make a new file [touch ~/gtkrc-2.0] and paste the code in.

    This gedit plugin now works for duplicating lines using CTRL + D
    Gedit Advanced Editing Plugin

    Awsome! at last I can duplicate lines in gedit! It was doing my head in!
    Last edited by emrys.r; December 2nd, 2010 at 03:45 PM.

  5. #5
    Join Date
    Sep 2010
    Beans
    5

    Re: [Hack] Removing the stupid Ctrl-D shortcut from gedit

    Awesome the ~/.gtkrc-2.0 unbinding worked for me (and the Advance editing tool Ctrl + d short works as well).

  6. #6
    Join Date
    Jan 2011
    Location
    Hartford, US
    Beans
    17
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [Hack] Removing the stupid Ctrl-D shortcut from gedit

    Quote Originally Posted by emrys.r View Post
    Much easier work around....

    Unbind/Rebind Ctrl+D in Gedit
    The second example in page above has code to disable the default CTRL+D. Just make a new file [touch ~/gtkrc-2.0] and paste the code in.

    This gedit plugin now works for duplicating lines using CTRL + D
    Gedit Advanced Editing Plugin

    Awsome! at last I can duplicate lines in gedit! It was doing my head in!
    Thanks... Worked like a charm...
    How would I make that change for all users? Also would this change be wiped with the next version of Gedit?

  7. #7
    Join Date
    Mar 2008
    Beans
    2

    Re: [Hack] Removing the stupid Ctrl-D shortcut from gedit

    Thanks,

    Also, could someone make a plugin that incorporates duplication of selection? Like in notepad++.

    I would do it myself, but am swamped with work right now.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •