You are not logged in.
Pages: 1
Hi,
Does MP have a keyboard shortcut for commenting lines (inserting # at the beginning)?.
~/.config/Mousepad/accels.scm didn't show anything relevant.
Thanks
Offline
No, you have to use search & replace, enable regular expressions, and replace (^.) with #\1.
Offline
Thanks. Is it possible to define this as a shortcut/macro?.
Offline
Unfortunately not, I thought several times to make macros like notepad++, but I never got to it
Offline
Thanks.
Offline
There is a workaround on Linux - make a shortcut in AutoKey (I would use AutoHotKey on Windows, the script would be different). I use 2 python scripts (AutoKey only):
# Write (add) BASH comment in front of every line
import time, os
# Backup previous value of clipboard
try:
oldClip = clipboard.get_clipboard()
time.sleep(0.3)
except:
oldClip = ""
keyboard.send_keys("<ctrl>+c")
time.sleep(0.2)
newClip = clipboard.get_clipboard()
# Use new filled clipboard
output = "#" + newClip.replace("\n","\n#")
clipboard.fill_clipboard(output)
time.sleep(0.3)
keyboard.send_keys("<ctrl>+v")
time.sleep(0.5)
# Revert clipboard
clipboard.fill_clipboard(oldClip)
del newClip, output, oldClip
# Remove BASH comment in front of every line
import time, os, re
# Backup previous value of clipboard
try:
oldClip = clipboard.get_clipboard()
time.sleep(0.2)
except:
oldClip = ""
keyboard.send_keys("<ctrl>+c")
time.sleep(0.2)
newClip = clipboard.get_clipboard()
# Use new filled clipboard
output = newClip.replace("\n#","\n")
output = re.sub("^#", "", output)
clipboard.fill_clipboard(output)
time.sleep(0.2)
keyboard.send_keys("<ctrl>+v")
time.sleep(0.5)
# Revert clipboard
clipboard.fill_clipboard(oldClip)
del newClip, output, oldClip
Notes:
AutoKey allows you to set your own shortcut.
Window filter in AutoKey is strongly reccomended (for example mousepad\.Mousepad)
I use the time.sleep() commands because AutoKey does not work very well on Xubuntu 20.04 or 22.04 - for example filling up clipboard this way takes some time, but AutoKey does not wait till the operation is finished. So I use a lot of sleep commands to be sure previous command is finished.
Offline
Pages: 1
[ Generated in 0.013 seconds, 10 queries executed - Memory usage: 533.2 KiB (Peak: 533.82 KiB) ]