Run external tools
You may need to run the external tools (ex : compiler, interpreter or web browser) from Notepad++ (via Run dialog) by passing the current edited document as argument. To do so, you have to use the environment variable.
The usage of environment variable is :
$( ENVIRONMENT_VARIABLE )
Say the current file you edit in Notepad++ is:
E:\my Web\main\welcome.html
The 5 environment variables contain:
| FULL_CURRENT_PATH |
: E:\my Web\main\welcome.html |
| CURRENT_DIRECTORY |
: E:\my Web\main\ |
| FILE_NAME |
: welcome.html |
| NAME_PART |
: welcome |
| EXT_PART |
: html |
Note that you should put the double quote around the path environment variables : “$(ENVIRONMENT_VARIABLE)” since they may contain the white space.
Here're 2 examples :
- firefox "$(FULL_CURRENT_PATH)"
- iexplore "$(FULL_CURRENT_PATH)"
These 2 user commands are also included in npp.3.0.installer.exe (or later version). You can launch them by Ctrl+Alt+Shift+X and Ctrl+Alt+Shift+I respectively.
There are 5 more variables (available from v3.7):
| NPP_DIRECTORY |
: the full path of directory which locates your notepad++.exe |
| CURRENT_WORD |
: it gives the word(s) you selected in Notepad++. |
| CURRENT_LINE |
: it gives the current line number where your cursor position is in Notepad++. |
| CURRENT_COLUMN |
: it gives the current column number where your cursor position is in Notepad++. |
| NPP_DIRECTORY |
: this variable contains the absolute path of Notepad++'s directory. |
Here're the examples :
- http://www.php.net/%20$(CURRENT_WORD)
- http://www.google.com/search?q=$(CURRENT_WORD)
- http://en.wikipedia.org/wiki/Special:Search?search=$(CURRENT_WORD)
- $(NPP_DIRECTORY)\notepad++.exe $(CURRENT_WORD)
For the examples 1 ~ 3, we pass the argument URL + the current selected word(s) to the default browser in order to perform the search on Internet.
Whereas for the 4th example, it'll be useful if you want to open a file from current document. Consider a php file which contains a line:
include("../myFuncs.php");
Selecting ../myFuncs.php then typing the hot key you assigne to this command will open myFuncs.php in Notepad++, of course the mentioned file should exist in the indcated path.
The variable CURRENT_WORD brings you a flexible solution to configuer your external commands.
|