Score:0

Can I configure a keyboard shortcut to input a specific string while typing?

py flag

I use c++ often and need to type the "->" symbol quite a lot.

Because of my german keyboard, I have to first type the dash "-" and then press the FN+SHIFT+L to get the ">" which is quite an annoying combination.

I was just wondering if there was a way to configure a shortcut for example FN+ö or ALTGRP+ö (or some other key that I'm not using) to type "->" automatically.

Score:2
uz flag

You can define a compose key and create an ~/.XCompose file with for instance this line:

<Multi_key> <r> <a> : "->"  # RIGHT ARROW

Next time you log in you should be able to press Compose followed by R followed by A to get ->. Tested in gnome-terminal and gedit.

Sadaharu Wakisaka avatar
pl flag
I have one concern the arrow operator `->` is too special to put it. My Terminal or application doesn't print these characters in this order. I tried `xdotool type "->"` and `xclip` paste from a file, these worked on Terminal but not as a shortcut.
Gunnar Hjalmarsson avatar
uz flag
@SadaharuWakisaka: Right, I have the same concern. The source from where I got the idea mentioned that compose is actually intended for single unicode characters, while this is a string with two characters. The consequence is that you can't expect it to work in all applications. But when I tested successfully in both gedit and gnome-terminal, i decided to provide an answer.
Andrew.M avatar
py flag
Thank you for your answer! It's enough for me if it works with VS Code. If I want the shortcut to be `Alt + l` and my compose key is Alt by default, then I have to write `<Multi_key> <l> : "->"`? If this is correct, then it didn't work for me neither in a terminal nor in gedit.
Gunnar Hjalmarsson avatar
uz flag
@Andrew.M: It's not a shortcut, it's a compose sequence, and I think it needs to be at least two characters.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.