8

Note: I'm interested in knowing if there's a shortcut native to gedit itself. I'm not interested in solutions involving Autokey, etc.

In gedit 3.28.1 (Ubuntu 18.04) and 3.30.0 (Ubuntu 19.04), if I want to insert the date and time (assuming the corresponding plugin is active), I need to

  1. Click on Menu (☰)
  2. Click on Tools
  3. Click on Insert Date and Time …
  4. Click on Insert

This page doesn't list a keyboard shortcut even to get directly to step #3 in the list above.

(I know there are other ways such as using xdotool and xsel to insert time and date.)

DK Bose
  • 42,548
  • 23
  • 127
  • 221
  • 1
    @Graham, I've clarified that I'm not interested in alternatives. I want to know whether gedit itself has a keyboard shortcut. BTW, I think AutoKey constantly runs in the background. You should look at texpander which runs only on demand. An example is here. – DK Bose Aug 24 '19 at 11:44
  • 2
    This question is very justified. Gedit provides a function to insert a date, but apparently wants to make it as difficult as possible to use it. This is a valid issue for Gedit that should be filed if it hasn't already.. – vanadium Aug 24 '19 at 11:57
  • 1
    Ok. I've retracted the close vote accordingly. Thanks for the clarification. – graham Aug 24 '19 at 12:05
  • 1
    Probably you might find this useful, looks like a pretty native solution. – mook765 Aug 24 '19 at 12:08
  • Most useful! I'm trying it out now. If you post an answer, I'd accept it. – DK Bose Aug 24 '19 at 12:12
  • @mook765, I'm struggling to understand the GUI! I posted an answer earlier on a related question. – DK Bose Aug 24 '19 at 12:24
  • 1
    Click + in bottom left. Rename "New tool" to provide a name you want. Now edit the code: the bash "shebang" is already filled in for you (first line). In its simpest form, add a second line "date". Under "Shortcut key", supply your hotkey. Under "Output", select "Insert at cursor position". No saving needed: just close the dialog when done. Pressing the hotkey now should insert the date as provided by the date command. – vanadium Aug 24 '19 at 12:42
  • @vanadium I got it working but if you want, please post an answer. – DK Bose Aug 24 '19 at 12:48
  • 1
    All right, I have some time left ;-) – vanadium Aug 24 '19 at 12:51

2 Answers2

8

In Gedit click the cog-wheel and choose Preferences

Open the Plugin-tab and enable External Tools.

Close the Preferences-window and click the cog-wheel again, you will find the option Manage External Tools... now, select it to open the Manage External Tools-window:

enter image description here

Click the + button to add a new function and give it a name, add the date-command with the options of your choice, click the Shortcut key-button and assgin a shortcut and in the Output-field choose Insert at cursor position from the drop-down-menu.

Close the Manage External Tools-window and test the new keyboard-shortcut in the main gedit window.

Reference: Timestamp Keyboard Shortcut In gedit

DK Bose
  • 42,548
  • 23
  • 127
  • 221
mook765
  • 15,925
2

Adding to the accepted answer, I have put together a GitHub project with some additional information and a Gedit extension file that can be directly downloaded and then copy/pasted into location -

https://github.com/harrison-broadbent/gedit-insert-date

Hope anyone stumbling on this finds this project useful!