How to setup AutoKey for text auto-completion

How do I setup AutoKey to get the following result?

  1. I type a word like ubu in a text editor
  2. A window opens with the suggestion ubuntu
  3. I can select ubuntu through TAB-key
  4. ubu gets replaced with ubuntu

Solution 1:

Note: this may not work in a Wayland session!

Texpander:

Texpander is a simple text expander for Linux. It is sort of like Autokey, except it works off of text files that you put in your ~/.texpander directory. Texpander is a bash script that uses xclip, xdotool, and zenity to let you type an abbreviation for something and it expands to whatever you have in the matching text file.

Download the .zip file and extract the contents.

Copy texpander.sh over to ~/bin. Make it executable.

Use your distro's method to assign Ctrl+Shift+~, for example, to texpander.sh. (Note that ~/bin should be in your $PATH.)

Install xsel, not xclip, and xdotool using sudo apt install.

Create a folder ~/.texpander.

In that folder, create the following three files: au.txt, off-topic.txt and os.txt with the following contents:

au.txt

Welcome to Ask Ubuntu!

off-topic.txt

Questions about distros other than Ubuntu or other official flavors are off-topic here.

os.txt

OS: Ubuntu 18.04.1 LTS

Open a text editor and press the assigned shortcut to launch texpander.sh. You'll get a Zenity window like this:

Texpander choices

If you have a longer list, there'll be a handy scrollbar or just type the first letter of a listed item to jump down the list to that item.

Select the one you want and press Enter or click OK.

A longer list with scrollbars

Troubleshooting: If things don't work, try increasing the sleep values in lines 45 and 61 of texpander.sh. xdotool on older machines may benefit.