You are here: PSPad forum > English discussion forum > Create a shortcut to insert a text

Create a shortcut to insert a text

Goto Page: 1 2 Next

#1 Create a shortcut to insert a text

Posted by: RANZI | Date: 2020-07-01 13:19 | IP: IP Logged

Hi,
I want to define a shortcut to insert a custom string from (text) cursor.

Because, my text editor is configured to replace "real tab" with "2 spaces" and this shortcut will be associated to one real tab.

It is possible ?

Thank's.

Options: Reply | Quote | Up ^


#2 Re: Create a shortcut to insert a text

Posted by: pspad | Date: 2020-07-01 13:29 | IP: IP Logged

I don't know if I understand well.
You have cursor anywhere in text and do you want to insert what? Text under cursor or text from clipboard or any specific text or?

Options: Reply | Quote | Up ^


#3 Re: Create a shortcut to insert a text

Posted by: vbr | Date: 2020-07-01 16:45 | IP: IP Logged

RANZI:
Hi,
I want to define a shortcut to insert a custom string from (text) cursor.

Because, my text editor is configured to replace "real tab" with "2 spaces" and this shortcut will be associated to one real tab.

It is possible ?

Thank's.

Hi,
I usually use a dummy regex replacement, when a real tab is needed in such setting (convert to spaces...);
e.g. write T, select it, call search and replace dialog and replace
T
with
\t
(regular expressions, selected text only)

Of course, it is not practical for regular, repeated usage.

It can be achieved with a simple script, e.g.

Quote:
/////////// save e.g. under ...\PSPad\Script\JScript\insert_tab.js ////////

var module_name = "insert_tab";
var module_ver = "1";

function insert_real_tab(){
if (editorsCount()<1){return;}
var actEd = newEditor();
actEd.assignActiveEditor();
actEd.selText("\t"); // insert real tab
}

function Init(){
addMenuItem("insert real tab", "", "insert_real_tab","Shift+Alt+T"); // adapt shortcut
}

It behaves like the key press - the tab is inserted at the cursor position, if a selection is present, it is replaced with the inserted character.

(I initially thought, it might be possible to insert tab etc. from Tools - ASCII table, but apparently it isn't supported.)

hth,
vbr

Options: Reply | Quote | Up ^


#4 Re: Create a shortcut to insert a text

Posted by: RANZI | Date: 2020-07-02 07:17 | IP: IP Logged

pspad:
I don't know if I understand well.
You have cursor anywhere in text and do you want to insert what? Text under cursor or text from clipboard or any specific text or?

I use PSPad to edit files some of which use "2 spaces" when I tape "TAB" in the keyboard and other use "a real tab" when I tape "TAB" in the keyboard.

However, after associate TAB to "2 spaces" in the setting of PSPad, I can not tape a real tab anymore.

My most common use is insert "2 spaces" when I tape on TAB key.

Options: Reply | Quote | Up ^


#5 Re: Create a shortcut to insert a text

Posted by: RANZI | Date: 2020-07-02 07:20 | IP: IP Logged

vbr:
Hi,
I usually use a dummy regex replacement, when a real tab is needed in such setting (convert to spaces...);
e.g. write T, select it, call search and replace dialog and replace
T
with
\t
(regular expressions, selected text only)

Of course, it is not practical for regular, repeated usage.

It can be achieved with a simple script, e.g.

Quote:
/////////// save e.g. under ...\PSPad\Script\JScript\insert_tab.js ////////

var module_name = "insert_tab";
var module_ver = "1";

function insert_real_tab(){
if (editorsCount()<1){return;}
var actEd = newEditor();
actEd.assignActiveEditor();
actEd.selText("\t"); // insert real tab
}

function Init(){
addMenuItem("insert real tab", "", "insert_real_tab","Shift+Alt+T"); // adapt shortcut
}

It behaves like the key press - the tab is inserted at the cursor position, if a selection is present, it is replaced with the inserted character.

(I initially thought, it might be possible to insert tab etc. from Tools - ASCII table, but apparently it isn't supported.)

hth,
vbr

I create and paste the JS file in PSPad folder, but I don't know how to use/activate a JS script. How to activate them?

Thank's

Options: Reply | Quote | Up ^


#6 Re: Create a shortcut to insert a text

Posted by: vbr | Date: 2020-07-02 07:56 | IP: IP Logged

Hi,
the script should be placed in the appropriate subfolder
...PSPad_folder\Script\JScript\insert_tab.js

It must be a user-writable folder - depending on the multi-user setting, it might be in the user profile of PSPad, or for a portable setting it is directly under the program folder.

If the scripting support isn't activated yet, you can check this in the
Settings :: System Integration: [x] Integrated scripting support (WSH)
(it currently works in 32bit version of PSPad)

Possibly after a new start of the program you should get a menu entry Scripts, with the submenus as defined in the current scripts (Init ... )
For the above script, the menu would contain:
insert real tab Shift+Alt+T

it can be called from the script menu or directly with the keyboard shortcut - it an be changed in the script file to match your preferences; there only must not be any collision with the same shortcut for other functions (windows-wide, program funtions, code templates or other spripts). - It might be tricky to find out - however, if a script works from the menu and doesn't work via shortcut, it is usually caused by such collision.

hth,
vbr

Edited 1 time(s). Last edit at 2020-07-02 08:01 by vbr.

Options: Reply | Quote | Up ^


#7 Re: Create a shortcut to insert a text

Posted by: pspad | Date: 2020-07-02 08:38 | IP: IP Logged

Hello

What is your real tab dependency?
If you need real tab e.g. in PHP files and spaces in TXT (or other) files, it is possible to set.
If you need to use real TAB and spaces in one file type, then is necessary to solve e.g. by scripting.

Options: Reply | Quote | Up ^


#8 Re: Create a shortcut to insert a text

Posted by: RANZI | Date: 2020-07-02 09:49 | IP: IP Logged

vbr:
Hi,
the script should be placed in the appropriate subfolder
...PSPad_folder\Script\JScript\insert_tab.js

...

hth,
vbr

Excellent and very effective grinning smiley

Thank you vbr

Options: Reply | Quote | Up ^


#9 Re: Create a shortcut to insert a text

Posted by: RANZI | Date: 2020-07-02 10:07 | IP: IP Logged

pspad:
Hello

What is your real tab dependency?
If you need real tab e.g. in PHP files and spaces in TXT (or other) files, it is possible to set.
If you need to use real TAB and spaces in one file type, then is necessary to solve e.g. by scripting.

Indeed, I would like to keep reals tabs by default and use spaces for a lot of format like : .h, .c, .cc, .cpp, .klx(custom extension)

Options: Reply | Quote | Up ^


#10 Re: Create a shortcut to insert a text

Posted by: pspad | Date: 2020-07-02 10:55 | IP: IP Logged

RANZI:
Indeed, I would like to keep reals tabs by default and use spaces for a lot of format like : .h, .c, .cc, .cpp, .klx(custom extension)

Set spaces as default inte program settings / Editor
Individual real tabs base on the highlighter (file type) are in
Program settings / Highlighter settings / Specification tab for C++ highlighter
The check box has 3 states - Checked - ON, Unchecked OFF, square - set as Program settings.

If you hjave individual extension, add it into existing highlighter, for this case I guess it will be new extension for C++ highlighter. Again on the same place into file masks

Options: Reply | Quote | Up ^


Goto Page: 1 2 Next





Editor PSPad - freeware editor, © 2001 - 2020 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR