Methods to move entire text line in .txt file ?

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Methods to move entire text line in .txt file ?

Post by greengeek »

I rely on "ToDo" lists written via Leafpad or Geany. eg: "todo.txt"

As I complete (or fail to complete) each task (one line per task) - I need to re-order the lines in the file.

Rather than relying on copy/paste to relocate an individual line I would like to use some other method to do this.

One possibility is to highlight an entire line of text, then use a keyboard shortcut to move it up one notch - to elevate it above the line above it.
Another possibility is to highight a line then perhaps "rightclick" on it - and have this push it upwards by one line.
Or to push a line to top of the document.
There are probably many other possible methods.

There are many utilities that are used to manipulate todo lists (especially many ways to utilise or extend the utility found at http://todotxt.org) - but I don't need or want the complexity or fancy features they are designed for.

I guess I am hoping for some method that uses "in place" sed modifcation (or similar) to push a text line upwards. I don't need to push lines downwards as all I want to achieve is to bring the highest priority line up to the top of the list (or at least upwards by one line at a time). "Non-prioritised" lines will automatically drop down the list.

I want to use text files so that they are easy to print (ie: online apps no use, spreadsheets too complex, etc etc).

I wondered about more advanced methods of doing this (such as Markdown, Markup, html) or perhaps even some way of using fields.awk - but my ideal would be to find some way of using the rightclick or keyboard shortcut methods on a plain text file.

If anyone has any thoughts - even rudimentary or just weird or creative ideas - I am all ears.

I consider this potential functionality to be less of a "ToDo" utility and more of a "Priority selection" utility. Text based. Simple. Printable.

EDIT : My preference is to be able to do this within Leafpad as it is inbuilt in my Pup. (Geany would still be acceptable but does require me to load quite a few extra libs)

.

ToDo_Priority_app.png
ToDo_Priority_app.png (19.73 KiB) Viewed 10751 times

.
Best solution See this post: https://www.forum.puppylinux.com/viewto ... 18#p142518

Other solutions that may be useful:
- Mousepad text editor: https://www.forum.puppylinux.com/viewto ... 10#p143010
- Geany https://www.forum.puppylinux.com/viewto ... 57#p142157

Last edited by greengeek on Mon Feb 17, 2025 1:39 am, edited 6 times in total.
User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Methods to shift entire text line in .txt file ?

Post by MochiMoppel »

xdotool will be your friend ;)

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

Ooooh, I just found that Geany has an inbuilt Alt+Pageup shortcut which does exactly this.

Very happy with that - but would still love to achieve it within Leafpad due to it being inbuilt within my Pup and not needing the extra libs that Geany requires.

Will see what xdotool may be capable of.

ToDo_Geany.png
ToDo_Geany.png (56.95 KiB) Viewed 10735 times
User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Methods to shift entire text line in .txt file ?

Post by MochiMoppel »

- removed -

Last edited by MochiMoppel on Sat Feb 08, 2025 1:51 am, edited 2 times in total.
User avatar
Trapster
Posts: 228
Joined: Sat Aug 01, 2020 7:44 pm
Location: Texas
Has thanked: 2 times
Been thanked: 71 times

Re: Methods to shift entire text line in .txt file ?

Post by Trapster »

It works with geany on my netbook.
Ctrl-Fn-PgUp,

Learned something

User avatar
Chelsea80
Posts: 389
Joined: Tue Mar 09, 2021 12:44 am
Has thanked: 48 times
Been thanked: 84 times

Re: Methods to shift entire text line in .txt file ?

Post by Chelsea80 »

@greengeek

I am using Geany 1.29 in Signature 1

Highlight line of text to be moved then:

Edit > Commands > Move Line(s) Up

Or

Edit > Commands > Move Line(s) Down

Will only make one move at a time

Hope this helps

Chelsea80

1. BionicPup32+28 19.03 - Linux 4.9.163 - lxpup - 32-pae [i686] - (UPup Bionic Beaver)
....Frugal Install - Internal HDD - Gateway MX8716b - HDD 120GB - RAM 2GB

2. Friendly-Bionic32 v1.1
....USB Stick 2GB

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

Trapster wrote: Fri Feb 07, 2025 12:23 pm

It works with geany on my netbook.
Ctrl-Fn-PgUp,

Learned something

Good find. How did you come up with that key combination? Did you just try a whole bunch of different combinations or is there something on your netbook keytops that indicated such a possibility?
(And i assume it does not work with Leafpad??)

User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Methods to shift entire text line in .txt file ?

Post by MochiMoppel »

Chelsea80 wrote: Fri Feb 07, 2025 8:33 pm

Highlight line of text to be moved then:

Not necessary. Just place cursor somewhere into the line.
Moving a bunch of consecutive lines at once works the same: Place cursor somewhere into first line, select (highlight) to the last line you want to move and end the selection somewhere within this line.

@greengeek Not as elegant as Geany, but something like this should work in any editor:

Code: Select all

xdotool key End Shift+Home ctrl+x Delete Up ctrl+v Return Up

Tested in BW64 with Leafpad. Probably best not to waste a global shortcut for this but rather create a desktop/panel/tray button.

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

MochiMoppel wrote: Sat Feb 08, 2025 2:31 am

Not as elegant as Geany, but something like this should work in any editor:

Code: Select all

xdotool key End Shift+Home ctrl+x Delete Up ctrl+v Return Up

Tested in BW64 with Leafpad. Probably best not to waste a global shortcut for this but rather create a desktop/panel/tray button.

Many thanks for the sample code. I was taking a very different approach with xdotool and getting myself rather tangled trying to work out how to save the contents of whole lines to separate variables - then planning to use xdotool to place them as needed.
Your code looks much more simple.
However - not sure what I am doing wrong but at the moment all I seem to be doing is introducing line feeds (and some other buffered stuff..) into the todo.txt file.

What i did:
Modified /root/.jwm/jwmrc-personal to include the following line:
<Key mask="A" keycode="111">exec:/root/stepup</Key>
key 111 is my "arrow up".
/root/stepup contains:

Code: Select all

 #!/bin/sh
xdotool key End Shift+Home ctrl+x Delete Up ctrl+v Return Up

Have I gone horribly wrong somewhere and misunderstood how I should use this? (Happy to use a global shortcut at this stage of testing...)
(Testing on Fossa64 9.5)

EDIT : I tried to duplicate these codes manually but does not appear to be working - I think when I go "End" followed by "Shift+Home" - maybe this should highlight or select the line I am wanting to work with? But it does not seem to select it - so when I go "ctrl+x" it is just deleting one character rather than the whole line.
(Sorry not the best explanation)
I wonder if there needs to be a mousedown and mouseup somewhere during the "End, Shift+Home" phase? (or rather "keydown, keyup")

EDIT 2 : This link makes me think I am having a "Text selection" issue with xdotool:
https://askubuntu.com/questions/863537/ ... r-shiftend

EDIT 3 : I am experimenting with the following but obviously my syntax for doubleclick is wrong:
xdotool key End Shift+Home doubleclick key ctrl+x Delete Up ctrl+v Return Up
The experiment continues...

EDIT 4 : Also tried this but still not hitting the sweet spot:

Code: Select all

#!/bin/sh
xdotool key End Shift+Home 
xdotool click --delay 10 --repeat 2 1
xdotool key ctrl+x Delete Up ctrl+v Return Up
some1
Posts: 100
Joined: Wed Aug 19, 2020 4:32 am
Has thanked: 19 times
Been thanked: 22 times

Re: Methods to shift entire text line in .txt file ?

Post by some1 »

@greengeek:Try Shift+End instead of End to Select rest of line

williams2
Posts: 1069
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 306 times

Re: Methods to shift entire text line in .txt file ?

Post by williams2 »

move the text EDITOR'S cursor to the line
NOT the MOUSE CURSOR
then press the shortcut key

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

some1 wrote: Sat Feb 08, 2025 6:14 am

Try Shift+End instead of End to Select rest of line

Thanks - that definitely works if I do it manually - but not when I ask xdotool to do it.

There seems to be some timing issue with xdotool. I am needing to add some "sleep" terms in places. It seems a bit unstable.

Getting closer though i think.

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

Well, this version will work - but only if I have the cursor placed at the beginning of the line - not if the cursor is in the middle of a word:

Code: Select all

#!/bin/sh
xdotool key Shift+Home
sleep 1
xdotool key Shift+End
xdotool key ctrl+x
xdotool key Delete
xdotool key Up
xdotool key ctrl+v
xdotool key Return
xdotool key Up

(Using the commands manually DOES work regardless of where the cursor is - just using xdotool seems to be having slightly different effects somehow)

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

williams2 wrote: Sat Feb 08, 2025 6:52 am

move the text EDITOR'S cursor to the line
NOT the MOUSE CURSOR
then press the shortcut key

Do you mean that i should position the cursor by using the arrow keys rather than the mouse?
(Have tried both of those methods but no change in symptoms unfortunately)

User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Methods to shift entire text line in .txt file ?

Post by MochiMoppel »

greengeek wrote: Sat Feb 08, 2025 8:13 am

Well, this version will work - but only if I have the cursor placed at the beginning of the line - not if the cursor is in the middle of a word:

Code: Select all

#!/bin/sh
xdotool key Shift+Home
sleep 1
xdotool key Shift+End
xdotool key ctrl+x
xdotool key Delete
xdotool key Up
xdotool key ctrl+v
xdotool key Return
xdotool key Up

Using the commands manually DOES work regardless of where the cursor is

No, it does NOT work when you do this manually.
With the text cursor in the middle of the line, Shift+Home followed by Shift+End does not select the whole line! Instead start with Home.

libertas
Posts: 146
Joined: Thu Apr 22, 2021 8:35 pm
Has thanked: 31 times
Been thanked: 5 times

Re: Methods to shift entire text line in .txt file ?

Post by libertas »

User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Methods to shift entire text line in .txt file ?

Post by MochiMoppel »

@greengeek Rereading your edits

EDIT : I tried to duplicate these codes manually but does not appear to be working - I think when I go "End" followed by "Shift+Home" - maybe this should highlight or select the line I am wanting to work with? But it does not seem to select it

Are you saying that when you try these keys manually at your keyboard, the line is not selected? And what means "does not seem to select it"? You should see if it is selected or not.

You are right that xdotool has timing issues, and that's one of the reasons why I avoid this tool whenever I can. I suspect that it may have something to do with the key auto-repeat rate (the time it takes a key to repeat characters when you keep a key pressed). As mentioned in my earlier post, xdotool key End Shift+Home works for me to select a whole line.
Using xdotool's --delay option I can instruct xdotool to add a delay between keystroke. The default is 12 ms. So let's add a delay of 0.5sec:
xdotool key --delay 500 End Shift+Home . Works as expected (at least for me). The line is selected
However if I increase the delay to 1sec xdotool key --delay 1000 End Shift+Home I see that the line is selected, but the highlighting does not "stick", it disappears. Yery odd. BUT: The code works and the highlighting stays on as it should when I disable the key auto-repeat function:

Code: Select all

xset r off
xdotool key --delay 1000 End Shift+Home
xset r on

Maybe xset r off will do the trick to make my original code work for you, even without delay.

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

MochiMoppel wrote: Sun Feb 09, 2025 2:35 am

@greengeek Rereading your edits

EDIT : I tried to duplicate these codes manually but does not appear to be working - I think when I go "End" followed by "Shift+Home" - maybe this should highlight or select the line I am wanting to work with? But it does not seem to select it

Are you saying that when you try these keys manually at your keyboard, the line is not selected? And what means "does not seem to select it"? You should see if it is selected or not.

Ok - two answers to this:
1) When I manually place the cursor in the middle of a word - then hit the "End" key - the cursor moves to the end of the line.
Then when I hit "Shift+Home" - the number "7" appears at the end of the line. Obviously no selection going on here.

However, if I first turn on the Numlock key the symptoms are different.
With Numlock on:
When I manually place the cursor in the middle of a word - then hit the "End" key - the cursor moves to the end of the line.
Then when I hit "Shift+Home" - the cursor jumps to the beginning of the line. But nothing is highlighted.

This behaviour appeared to be similar to why the script was failing.

But my conclusion now is that I am possibly being confused by the fact that my HOME key is part of the numeric keypad.

(ie: "Shift+home" is probably generating a different code when Numlock is on or off)

2) Part of my "manual" testing was actually running the script with various "sleeps" inserted in various places as a debugging tool. Probably wrong of me to have called that "manual" testing. This way I could visually see the impacts of the script and try to make sense of it.
However - in that phase of testing I noticed that the script would highlight from the middle of the word - to the end of the word. Then would highlight from the middle of the word to the beginning of the word. Obviously this was "not selecting correctly".

I am about to trial your suggestion further above (with "Home" vs "Shift+Home") in an effort to get "whole line selection" when the cursor is not at the beginning of the line. Not sure how this will go due to my previous confusion over the "7&Home" key on the numeric keypad. (May have to attach a different keyboard at some point)

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

MochiMoppel wrote: Sat Feb 08, 2025 8:44 am

No, it does NOT work when you do this manually.
With the text cursor in the middle of the line, Shift+Home followed by Shift+End does not select the whole line! Instead start with Home.

Confirmed.
(With Numlock off) - if I place the cursor in the middle of the line, then press "Home" then "Shift+End" - the whole line is highlighted.

However - if I write this sequence into the script - then try with the cursor in the middle of the line - it creates a mess. (Seems to revert to highlighting half the line and copying only that to the new line).

Hope that makes sense...

Sometimes the outcome seems negatively impacted by how long I hold the Alt key - so I need to try your suggestion of switching off repeat.

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

MochiMoppel wrote: Sun Feb 09, 2025 2:35 am

You are right that xdotool has timing issues, and that's one of the reasons why I avoid this tool whenever I can. I suspect that it may have something to do with the key auto-repeat rate (the time it takes a key to repeat characters when you keep a key pressed). As mentioned in my earlier post, xdotool key End Shift+Home works for me to select a whole line.

Well, I just tried a bunch of stuff based on the delay/norepeat syntax and got (almost) nowhere.

BUT - finally I found this:

If I add a sleep 1 prior to your syntax - IT WORKS !!!!!

Code: Select all

#!/bin/sh
sleep 1
xdotool key End Shift+Home

I will go back and do some more testing of the whole process now.

ALSO - I added your norepeat suggestion to the script that I was (previously) most satisfied with - and it definitely seems to stabilise it (especially when I am typing/editing quickly)

So - best script so far (for my needs) is:

Code: Select all

#!/bin/sh
xset r off
xdotool key Home
sleep 0.5
xdotool key Shift+End
xdotool key ctrl+x
xdotool key Delete
xdotool key Up
xdotool key ctrl+v
xdotool key Return
xdotool key Up
xset r on

.

But as I say - I am about to retrace my steps based on your original code but with the "sleep 1" added at the start.

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

MochiMoppel wrote: Sat Feb 08, 2025 2:31 am

Not as elegant as Geany, but something like this should work in any editor:

Code: Select all

xdotool key End Shift+Home ctrl+x Delete Up ctrl+v Return Up

Tested in BW64 with Leafpad. Probably best not to waste a global shortcut for this but rather create a desktop/panel/tray button.

YESSSSSSSSSsssssss !!!!!!!!
With the "sleep 1" introduced at the beginning this works beautifully for me.

Code: Select all

#!/bin/sh
sleep 1
xdotool key End Shift+Home ctrl+x Delete Up ctrl+v Return Up

THANKS ! !

I will play with the sleep value and see how much I can trim it.

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

greengeek wrote: Sun Feb 09, 2025 8:06 am

With the "sleep 1" introduced at the beginning this works beautifully for me.

Code: Select all

#!/bin/sh
sleep 1
xdotool key End Shift+Home ctrl+x Delete Up ctrl+v Return Up

THANKS ! !

I will play with the sleep value and see how much I can trim it.

It appears that I can go as low as "sleep 0.2"

If I go to "sleep 0.1" I definitely get all sorts of corruption.

(Very close to marking this thread solved. Just want to keep using this script for a few days, and also try Autokey if I can get it going).

Thanks all for the input - and especially @MochiMoppel for the code and patience !

User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Methods to shift entire text line in .txt file ?

Post by MochiMoppel »

greengeek wrote: Sun Feb 09, 2025 8:06 am

YESSSSSSSSSsssssss !!!!!!!!
With the "sleep 1" introduced at the beginning this works beautifully for me.

🥳 Congratulations!

It's incomprehensible to me that a sleep at the beginning of a script can affect the following command, but here we are. Miracles happen :lol:

What also works for me is running xdotool directly from a desktop shortcut. May create again a mess at your side but worth a try:

ShiftLineUp.png
ShiftLineUp.png (33.38 KiB) Viewed 6897 times
User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

MochiMoppel wrote: Sun Feb 09, 2025 11:28 am

It's incomprehensible to me that a sleep at the beginning of a script can affect the following command, but here we are. Miracles happen :lol:
What also works for me is running xdotool directly from a desktop shortcut. May create again a mess at your side but worth a try:
ShiftLineUp.png

Thanks for the suggestion.
Yes, that does work. :thumbup:
At least - it does work if I click the desktop icon.
I seem unable to trigger the icon by using the Alt+Up shortcut.

However I can make the shortcut work if I assign a different function to the icon (ie something other than xdotool).

So - clicking the icon xdotool functions normally.
Assigning Alt+Up shortcut to the icon fails to trigger xdotool.

(Testing with Fossa64 9.5 generic)

EDIT : Just re-ran this test after a clean boot.
I now realise that I had to restart X server for the shortcut to stick to the icon.
Now that I have run Fixmenus (not sure if needed?) then Restart X - the icon works perfectly if I click it with the mouse, but creates a horrible mess of my document if I trigger it with the Alt+Up shortcut.

(I assume that in my prior comment about shortcut working with another function - it's possible that I got myself tangled. Not sure how I thought I got the shortcut working without an X restart at that time)

I'm going to have a cup of tea. :roll:

User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Methods to shift entire text line in .txt file ?

Post by MochiMoppel »

greengeek wrote: Sun Feb 09, 2025 8:14 pm

it does work if I click the desktop icon.
I seem unable to trigger the icon by using the Alt+Up shortcut.

You already have an Alt+Up JWM shortcut for your script. You can't use the same shortcut for the ROX icon. The global JWM shortcut will have precedence and the ROX shortcut is ignored.Use a different key combi for your icon.

EDIT : Just re-ran this test after a clean boot.
I now realise that I had to restart X server for the shortcut to stick to the icon.
Now that I have run Fixmenus (not sure if needed?) then Restart X - the icon works perfectly if I click it with the mouse

It did so already before, right? I assume that you removed the JWM shortcut and then restarted X. Restarting X after editing JWM config files is not necessary. Just run the command jwm -restart. Now that the JWM shortcut is gone, the icon shortcut will take effect.

, but creates a horrible mess of my document if I trigger it with the Alt+Up shortcut.

Yes, I can see that. The same here. However it works when using the --clearmodifiers option:
key --clearmodifiers End Shift+Home ctrl+x Delete Up ctrl+v Return Up

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to shift entire text line in .txt file ?

Post by greengeek »

MochiMoppel wrote: Mon Feb 10, 2025 2:01 am

The same here. However it works when using the --clearmodifiers option:
key --clearmodifiers End Shift+Home ctrl+x Delete Up ctrl+v Return Up

Sorry for the delay in replying. The clearmodifiers argument is having some impacts when used in a script - but still does not make my desktop icons trigger correctly.

I need to triplecheck myself and be sure of the symptoms , on different hardware and a range of pups, then I will post my conclusions.

For now you have given me a couple of options to get this working - but there is an issue with my shortcut behaviour that I need to understand.

Cheers!

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to move entire text line in .txt file ?

Post by greengeek »

MochiMoppel wrote: Mon Feb 10, 2025 2:01 am

it works when using the --clearmodifiers option:
key --clearmodifiers End Shift+Home ctrl+x Delete Up ctrl+v Return Up

Using the clearmodifiers argument has given me a solution that I am happy with.

I have tested this on Fossa64 9.5, Fossa96-CE4 and Bookworm64 - and on two different brands of laptops so far.
At the moment I am avoiding the use of desktop icons (more testing of that later)

Current best solution for my needs:

1) Place two scripts in /root as follows:

"stepup" :

Code: Select all

#!/bin/sh
xset r off
sleep 0.4
xdotool key --clearmodifiers End Shift+Home ctrl+x Delete Up ctrl+v Return Up

"stepdown" :

Code: Select all

#!/bin/sh
xser r off
sleep 0.4
xdotool key --clearmodifiers End Shift+Home ctrl+x Delete Down ctrl+v Return Up

2) Add the following lines to /root/.jwm/jwmrc-personal :

Code: Select all

<Key mask="Alt_R" keycode="111">exec:/root/stepup</Key>
<Key mask="Alt_R" keycode="116">exec:/root/stepdown</Key>

3) Issue the following command:
jwm -restart

After that I can open my todo.txt list (opens in Leafpad on my favourite Fossa 9.5 system), then step to the line that I wish to move, and hit Alt_R in combination with either the Up or Down Arrow - and the line will step up or down. (Alt_R is the right hand Alt key on my keyboard)

I decided to specifically define use of the "Righthand Alt" key as I felt it might be less likely to cause conflict with global shortcuts.

Things to note:
- The use of the "clearmodifiers" argument had a significant bearing on how reliably the scripts performed. Without out it I had to be careful how long I held down the Alt key. With the clearmodifiers argument in place I can now hold down the Alt key as long as needed - and just tap the up or down arrow as required. Much better behaviour.
- keycode 111 (up arrow) and 116 (down arrow) relate to my keyboard only. May be different on other machines or locales.
- The shortcuts work reliably at normal working speeds. If I bang away at the keyboard at ridiculous speeds then I sometimes see split lines of text and have to back that off using Ctrl+z. I am happy wth the way it is working but this just a caution for anyone testing the method.
- In the scripts I have used the "xset r off" method to minimise problems caused by key repeating. However - I have not switched xset r back on at any point. It could be added back into the script if needed - but for me it causes no issues.
- The jwmrc-personal file normally uses the letter "A" as the identifier of the "Alt" modifier key - but I wanted to trial using "Alt_R" in the key mask definition and it seems to work. This way the left hand Alt key is not impacted.

User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Methods to move entire text line in .txt file ?

Post by MochiMoppel »

greengeek wrote: Tue Feb 11, 2025 1:38 am

- In the scripts I have used the "xset r off" method to minimise problems caused by key repeating. However - I have not switched xset r back on at any point. It could be added back into the script if needed - but for me it causes no issues.

It's a global setting and affects other applications. Though it is not harmful to leave it off, you might be annoyed when realizing that you can't navigate in text files anymore by keeping the arrow keys pressed or delete a text portion by holding the Backspace key.

- The jwmrc-personal file normally uses the letter "A" as the identifier of the "Alt" modifier key - but I wanted to trial using "Alt_R" in the key mask definition and it seems to work. This way the left hand Alt key is not impacted.

Will not work as you might expect. JWM treats a "Alt_R" or "Alt_L" as "A". Makes no differences. If you have something like
<Key key="C" mask="Alt_L">exec:urxvt</Key>
<Key key="C" mask="Alt_R">exec:leafpad</Key>
JWM will open Leafpad if you push any of the Alt keys + C, never will open urxvt

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to move entire text line in .txt file ?

Post by greengeek »

MochiMoppel wrote: Tue Feb 11, 2025 2:57 am

JWM treats a "Alt_R" or "Alt_L" as "A". Makes no differences.

Well that's a bit annoying. Oh well - at least it seems to work the way I have set it for now, but I guess I can change to different shortcuts if problems arise.

There must be some unique shortcuts that have not been assigned yet...

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Methods to move entire text line in .txt file ?

Post by greengeek »

As well as the keyboard shortcut/xdotool method suggested by MochiMoppel (which I use for Leafpad), and the inbuilt Alt+PageUp shortcut functionality of Geany - I also have a third method to easily move whole lines up or down in a text file:

I have been experimenting with "mousepad" text editor and it's inbuilt Alt+Up / Alt+Down shortcuts work really well. In fact this is the fastest method of the three so far.

I made a "trimmed" .pet of mousepad so that it can be posted on the forum and although I intended it for use on a cutdown Foss64 9.5 it also works on Fossa9.6-CE4 and Bookworm.
(Although you may prefer to load it from PPM)

.pet here: https://www.forum.puppylinux.com/viewto ... 10#p142210

The interface is very clean so I prefer it to Geany.

Alt+Up arrow moves the whole line up
Alt+Down arrow moves the whole line down.

Post Reply

Return to “Programming”