There are two ways (or forms) to get the text selected in Notepad++:
Then the selected text can be processed by some external tool as shown in [4.6.1].
There are two ways (or forms) to replace the selected text with the text you want:
NppExec allows you to use both ways to process the selected text with some external tool and then to replace the text with the tool's output. Several steps are required:
1) Pass the selected text to the external tool. The selected text is the external tool's input:
// input: command line, output: command line tool.exe <args> "$(CURRENT_WORD)"or
// input: command line, output: file cmd /c tool.exe <args> "$(CURRENT_WORD)" >$(SYS.TEMP)\out.txtor
// input: file, output: command line SEL_SAVETO $(SYS.TEMP)\npp_sel.txt tool.exe <args> $(SYS.TEMP)\npp_sel.txtor
// input: file, output: file SEL_SAVETO $(SYS.TEMP)\npp_sel.txt cmd /c tool.exe <args> C:\npp_sel.txt >$(SYS.TEMP)\out.txt
2) Replace the selected text with the tool's output:
// replace the selected text with the output file's content SEL_LOADFROM $(SYS.TEMP)\out.txtor
// replace the selected text with the command line's output: SEL_SETTEXT $(OUTPUT)
The very last approach needs several additional steps. The $(OUTPUT) variable stores the entire external tool's output while NPE_CONSOLE V+ has been set. Let's see an example of such approach.
Let's assume you select a word such as "copy", "dir", "cd" etc. and want to replace this word with its description from cmd's help. You can use $(CURRENT_WORD) variable to pass the selected word to cmd.exe. Also you want to replace the selected word with cmd's output. You can use $(OUTPUT) variable to do it. Here is the full NppExec's script which allows you to get the desired result:
// enable $(OUTPUT) variable within the current NppExec's script NPE_CONSOLE local v+ // run cmd.exe with the selected word as parameter cmd.exe /c $(CURRENT_WORD) /? // (optional) replace the selected text: previously selected word SEL_SETTEXT $(CURRENT_WORD) // (optional) replace the selected text: new line SEL_SETTEXT+ \n // replace the selected text: cmd's output SEL_SETTEXT $(OUTPUT)
That's all. Now try the following:
The $(OUTPUT) variable is disabled by default to minimize the memory usage as this variable stores the entire external process'es output when enabled.
You can clear this variable by assigning an empty value to it:
SET $(OUTPUT) =
To free the memory allocated for this variable, use the following:
UNSET $(OUTPUT)
See also: Applying external tool to selected text [4.6.1]; Modify selected text and save to file [4.6.17].