Score:0

Custom Keyboard Shortcuts for jumping to next word or end of line – Ubuntu 22.04

ly flag

Hej there! I switched from Mac to Linux currently and am still trying to figure out how to adjust some keyboard shortcuts.

For example I mapped Ctrl + Right arrow to End key in the settings by adding this as command:

zsh -c "xdotool getactivewindow key End"

That's working as expected for one liners. But in Mail Clients, Texteditors, etc. I'm not jumping to the end of the line but to the end of the whole text block. However the End key sets the cursor to the end of the current line, not the whole block. What am I missing here? Of course same goes for Ctrl + Left which is mapped to Home key.

A second problem occured when I tried to map Alt + Left and Alt + Right to Ctrl + Left and Ctrl + Right. By pressing Alt + left I want to jump to the previous word and vice versa with Alt + Right:

zsh -c "xdotool getactivewindow key Control_L+Right"

When pressing Alt + Right nothing is happening. I guess it's not working because it's referencing another custom shortcut. Adding a short sleep 0.2s doesn't do the trick:

zsh -c "sleep 0.2s && xdotool getactivewindow key Control_L+Right"

When I'm pressing Alt + Left now it's just working, if I release the Alt key after releasing the Arrow key. The expected behaviour would be to move the cursor word wise just by keeping alt pressed and pressing the arrow keys...

Is there anyone having the same issue or someone who figured out a solution?

Many many thanks in advance!

Sadaharu Wakisaka avatar
pl flag
Welcome to AskUbuntu. For example, Ctrl+End brings the cursor to the end of the document. End brings it to the end of line, Ctrl+Right bring it on the next word on Google Chrome and similar editors. They work differently when the delimiter is set to either 'Line Feed' or "Empty Line". Programmers don't write a paragraph in coding.I suggest you swap Ctrl and Alt key https://askubuntu.com/questions/254424/how-can-i-change-what-keys-on-my-keyboard-do-how-can-i-create-custom-keyboard?noredirect=1&lq=1 It seems to me the simple solution to this than do all shortcut replacement.
Score:0
ly flag

I managed to get all shortcuts working as expected by adding the --clearmodifiers flag. According to the xdotool manual:

Any command taking the --clearmodifiers flag will attempt to clear any active input modifiers during the command and restore them afterwards.

So I added the following command to my custom Alt+Shift+Left shortcut:

zsh -c "xdotool getactivewindow key --clearmodifiers Shift+Control_L+Left"

This solution solved the problem with Ctrl+Arrow keys jumping to beginning and end of paragraphs, too. Now the cursor jumps to the beginning and end of a single line.

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.