Another Potential Solution
Okay, so it's been 12 years since this question was asked. I think that I've found a another acceptable solution, that is perhaps better for formatting files, using Prettier.
What is Prettier?
Prettier is described as: "an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary."
Prettier Supports the Following Languages
- HTML
- CSS, Less, and SCSS
- JavaScript
- TypeScript
- JSX, Angular, Vue
- JSON, Markdown, YAML
And a few others.
If You Want to Use Other Languages, You Can Either Use:
- Plugins made by the community to Prettier, which allow support for other formats such: Java, Rust, PHP, SQL, and others.
- Non-Prettier formatters supporting other languages such as clang-format (npm version) (C / C++ / Java / JavaScript / JSON / Objective-C / Protobuf / C#), or Black (Python).
How To Install
- You're going to need to install Node.js for this tutorial.
Note: There may be other work arounds for using the subsequent
mentioned software without using Node.js. But to keep this tutorial
simple and the fact that Node.js already carries widespread
familiarity among developers, I'm going to be using this software
without explaining how to install it.
- After installing Node.js, install prettier globally to your system, allowing yourself to run prettier anywhere from the command line.
# NPM is the package manager used by Node.js
# And --global allows you to use prettier anywhere on your local computer.
npm install --global prettier
# To install other plugins (example):
npm install --g prettier-plugin-rust prettier-plugin-java
# To Install clang-format using NPM
npm install -g clang-format
# Usage Examples
prettier --write jquery-min.js # Formatting a JavaScript file
clang-format -i Test.cpp # Formatting C++ file
- On Notepad++, install a plugin called NppExec from
Menu> Plugins Admin...> Available> NppExec
.
- You can now run NppExec by either pressing F6 or by clicking
Menu > Plugins > NppExec > Execute NppExec Script...
- Now you should have a window pop up, giving you the option of executing a command.
- You can either use prettier on a (1) specific file or (2) all files in a folder or (3) all files in a directory recursively.
- You can always reload a file after it's better overwritten by Prettier using
Ctrl+R
, and enabling the following setting: Menu > MISC. > Update silently
.
Commands and Screenshots of NppExec + Prettier.
REM Using Prettier on Current File (use cmd or powershell /c)
cmd /c prettier --write "$(FULL_CURRENT_PATH)"
REM Using Prettier on Current Folder (a single asterisk)
pwsh /c prettier --write "$(CURRENT_DIRECTORY)\*"
REM Using Prettier on Current Directory Recursively (double asterisk)
pwsh /c prettier --write "$(CURRENT_DIRECTORY)\**"
Install NppExec Plugin
Running NppExec Plugin
Executing Commands on NppExec
Plugin manger
, the point is as of Notepad++ version 7.5, plugin manager is no longer shipped with Notepad++ – Firdausi