How can I configure the NppExec plugin for Notepad++?
I would like NppExec to compile my C files, run them, and show their output, all within Notepad++.
I recommend my solution. My situation: g++(cygwin) on win10
My solution: Write a .bat batch file and execute compiler in that batch. compileCpp.bat
@echo off
set PATH=%PATH%;C:\cygwin64\bin\
rm %~n1.exe
c++.exe -g %~dpnx1 -o %~dpn1.exe
%~n1.exe
Console:
NPP_EXEC: "runCpp"
NPP_SAVE: E:\hw.cpp
CD: E:\
Current directory: E:\
cmd /c C:\cygwin64\bin\compileCpp.bat "hw.cpp"
Process started >>>
Hello World<<< Process finished. (Exit code 0)
================ READY ================
I personally use the following batch script that can be used on many types of files (C, makefile, Perl scripts, shell scripts, batch, ...).
How to use it:
"$(SYS.APPDATA)\Notepad++\runNcompile.bat" "$(FULL_CURRENT_PATH)"
(optionally, you can put npp_save
on the first line to save the file before running it)This page explains quite clearly the global flow: https://www.thecrazyprogrammer.com/2015/08/configure-notepad-to-run-c-cpp-and-java-programs.html
Hope it can help
@echo off
REM ----------------------
REM ----- ARGUMENTS ------
REM ----------------------
set FPATH=%~1
set FILE=%~n1
set DIR=%~dp1
set EXTENSION=%~x1
REM ----------------------
REM ----------------------
REM ------- CONFIG -------
REM ----------------------
REM C Compiler (gcc.exe or cl.exe) + options + object extension
set CL_compilo=gcc.exe
set CFLAGS=-c "%FPATH%"
set OBJ_Ext=o
REM GNU make
set GNU_make=make.exe
REM ----------------------
IF /I "%FILE%"==Makefile GOTO _MAKEFILE
IF /I %EXTENSION%==.bat GOTO _BAT
IF /I %EXTENSION%==.sh GOTO _SH
IF /I %EXTENSION%==.pl GOTO _PL
IF /I %EXTENSION%==.tcl GOTO _TCL
IF /I %EXTENSION%==.c GOTO _C
IF /I %EXTENSION%==.mak GOTO _MAKEFILE
IF /I %EXTENSION%==.mk GOTO _MAKEFILE
IF /I %EXTENSION%==.html GOTO _HTML
echo Format of argument (%FPATH%) not supported!
GOTO END
REM Batch shell files (bat)
:_BAT
call "%FPATH%"
goto END
REM Linux shell scripts (sh)
:_SH
call sh.exe "%FPATH%"
goto END
REM Perl Script files (pl)
:_PL
call perl.exe "%FPATH%"
goto END
REM Tcl Script files (tcl)
:_TCL
call tclsh.exe "%FPATH%"
goto END
REM Compile C Source files (C)
:_C
REM MAKEFILES...
IF EXIST "%DIR%Makefile" ( cd "%DIR%" )
IF EXIST "%DIR%../Makefile" ( cd "%DIR%/.." )
IF EXIST "%DIR%../../Makefile" ( cd "%DIR%/../.." )
IF EXIST "Makefile" (
call %GNU_make% all
goto END
)
REM COMPIL...
echo -%CL_compilo% %CFLAGS%-
call %CL_compilo% %CFLAGS%
IF %ERRORLEVEL% EQU 0 (
echo -%CL_compilo% -o"%DIR%%FILE%.exe" "%DIR%%FILE%.%OBJ_Ext%"-
call %CL_compilo% -o"%DIR%%FILE%.exe" "%DIR%%FILE%.%OBJ_Ext%"
)
IF %ERRORLEVEL% EQU 0 (del "%DIR%%FILE%.%OBJ_Ext%")
goto END
REM Open HTML files in web browser (html and htm)
:_HTML
start /max /wait %FPATH%
goto END
REM ... END ...
:END
echo.
IF /I "%2" == "-pause" pause
I've written just this to execute compiling and run the file after, plus fileinputname = fileoutputname on windowsmashines, if your compilerpath is registred in the windows PATH-var:
NPP_SAVE
cd "$(CURRENT_DIRECTORY)"
set LEN~ strrfind $(FILE_NAME) .
set EXENAME ~ substr 0 $(LEN) $(FILE_NAME)
set $(EXENAME) = $(EXENAME).exe
c++.exe "$(FILE_NAME)" -o "$(EXENAME)"
"$(EXENAME)"
should work for any compiler if you change c++.exe to what you want
For perl,
To run perl script use this procedure
Requirement: You need to setup classpath variable.
Go to plugins->NppExec->Execute
In command section, type this
cmd /c cd "$(CURRENT_DIRECTORY)"&&"$(FULL_CURRENT_PATH)"
Save it and give name to it.(I give Perl).
Press OK. If editor wants to restart, do it first.
Now press F6 and you will find your Perl script output on below side.
Note: Not required seperate config for seperate files.
For java,
Requirement: You need to setup JAVA_HOME
and classpath
variable.
Go to plugins->NppExec->Execute
In command section, type this
cmd /c cd "$(CURRENT_DIRECTORY)"&&"%JAVA_HOME%\bin\javac""$(FULL_CURRENT_PATH)"
your *.class
will generate on location of current folder; despite of programming error.
For Python,
Use this Plugin Python Plugin
Go to plugins->NppExec-> Run file in Python intercative
By using this you can run scripts within Notepad++.
For PHP,
No need for different configuration just download this plugin.
PHP Plugin and done.
For C language,
Requirement: You need to setup classpath variable.
I am using MinGW compiler.
Go to plugins->NppExec->Execute
paste this into there
NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW32\bin\gcc.exe -g "$(FILE_NAME)"
a
(Remember to give above four lines separate lines.)
Now, give name, save and ok.
Restart Npp.
Go to plugins->NppExec->Advanced options.
Menu Item->Item Name (I have C compiler)
Associated Script-> from combo box select the above name of script.
Click on Add/modify and Ok.
Now assign shortcut key as given in first answer.
Press F6 and select script or just press shortcut(I assigned Ctrl+2).
For C++,
Only change g++ instead of gcc
and *.cpp
instead on *.c
That's it!!
In windows if you are using a portable version of MinGW you must set path variable or you have error libintl-8.dll not found. My path is C:\Program Files (x86)\CodeBlocks\MinGW\bin
Here's a procedure for Perl, just adapt it for C. Hope it helps.
npp_save
<-- Saves the current documentCD $(CURRENT_DIRECTORY)
<-- Moves to the current directoryperl.exe -c -w "$(FILE_NAME)"
<-- executes the command perl.exe -c -w , example: perl.exe -c -w test.pl
(-c = compile -w = warnings)