Page 1 of 1

Select a specific number of characters

Posted: Sun Mar 30, 2025 6:48 am
by random6_2020
Is there a way, maybe a plugin, to select a certain number of bytes/characters forward or backward from the cursor, preferably stopping at word boundaries :?:

Re: Select a specific number of characters

Posted: Tue Apr 01, 2025 2:07 am
by ewild
random6_2020

As an example:
At first, the script will select 12 chars before the cursor position and then 12 chars after it.

Code: Select all

// https://akelpad.sourceforge.net/forum/viewtopic.php?p=36773#p36773
// selectNcharsRelativetoCursor.js
// select a specified number of chars relative to cursor
// 2025-04-01 ewild

// select from the cursor position backward/up/toward the beginning
AkelPad.TextFind(0,".{12}",0x001C0000);

WScript.Echo('hit ok to continue');

// select from the cursor position forward/down/toward the end
AkelPad.TextFind(0,".{12}",0x000C0001); 

// Scripts-Eng.txt
// AkelPad.TextFind
// 0x00040000 dot symbol '.' in regular expressions specifies any character except new line
// 0x00080000 search with regular expressions
// 0x00100000 find up
// 0x001C0000 = sum of above
Basically, all you need is to make a regex that fits your needs.
As you can see, in the given example, I used ".{12}" regex query (so, any 12 chars) within AkelPad.TextFind() (backward and then forward).