0

Creating a new file in npp is easy. Just run notepad++.exe filename.extension, and if the file does not exist you will be prompted: "Would you like to create this file?" I'd like to bypass that dialog because it forces the dialog box into focus and can create issues for accessibility users.

Essentially seeking the command-line method to launch a new instance while creating a new file, the equivalent of ALT+F6 except creates a new file, which opens a second instance if you are in Notepad-Plus-Plus.

Is it possible to use the command line to run notepad++ with new, blank file, as if ctrl+n were pressed inside notepad++?

I understand that you can add some commands like makefile or notepad++ filename.txt and then click "make the file" when it says "file does not exist. But I would prefer to effectively hit Ctrl+N via a command at the Windows Command Line Interface (CLI).

Wolfpack'08
  • 1,364

2 Answers2

2

As other users have stated, this is not possible directly.

Luckily, there are a few solutions, all a bit hacky, but any of them will accomplish your goal. Please note that they only work if Notepad++ is not already running.

Option 1: Launch a new session

Notepad++.exe -nosession

The downside of this command is that you will not be able to access any files you previously left open (normally visible as tabs under the Notepad++ toolbar). No data will be lost, though. You will just need to relaunch Notepad++ normally again to see them.

Option 2: Create a new file tab every time Notepad++ launches

  1. On the Notepad++ toolbar, click "Settings"
  2. Click "Preferences..."
  3. On the sidebar, click "New Document"
  4. Check the box for "Always open a new document at startup"

(The obvious downside here is that you may not want this to happen on every launch!)

Option 3: Launch with alternate settings

Save the following codeblock as a batch file and run it. Explanation of how it works at the end.

@ECHO OFF
SETLOCAL EnableDelayedExpansion

ECHO You can manually edit the variable "settingsDir" in this batch file to avoid errors with nonstandard install paths SET settingsDir=%APPDATA%\Notepad++

CALL :test_path %SettingsDir% dirpath CALL :test_path %CD%\config.xml dirpath MKDIR Newtab CP config.xml .\Newtab
FOR %%f in () DO ( MKLINK /H ".\Newtab%%f" "%%d" ) FOR /D %%d in () DO ( MKLINK /J ".\Newtab%%d" "%%d" )

SET settingsDir=%CD% SET newconfig=%CD%\Newtab\config.xml CALL :test_path %CD%\Notepad++.exe ECHO. ECHO You must now manually edit %newconfig% ECHO. ECHO Search for the string: addNewDocumentOnStartup="no" ECHO Replace it with: addNewDocumentOnStartup="yes" and save the file. .\Notepad++.exe %newconfig% ECHO. PAUSE

ECHO. ECHO Assuming you made the XML edit described above, your command is now configured! ECHO It will be saved as a one-line batch file on your desktop. ECHO (You may wish to copy the command elsewhere, such as into the target of a Shortcut file or into the Registry!) %CD%\Notepad++.exe -settingsDir="%SettingsDir%\NewTab">%USERPROFILE%\Desktop\NewTxtNP++.cmd

EXIT

:test_path IF EXIST %1 ( CD %1 :EOF /b ) ELSE ( IF %3==err ( ECHO The specified path does not exist! ) IF %2==dirpath ( ECHO Enter the full path of your Notepad++ settings directory, with quotation marks, e.g. "C:\Users\YourName\Appdata\Roaming\Notepad++" ECHO (The directory should contain "config.xml" among other files.) ) IF %2==exepath ( ECHO Enter the parent directory of your Notepad++.exe file, with quotation marks, e.g. "C:\Program Files\Notepad++" ) SET /P pathvar=Directory path: CALL :test_path !pathvar! %2 err :EOF /b )

ENDLOCAL

Basically:

  1. You can specify a non-default settings directory when launching Notepad++ with the -settingsDir= parameter.
  2. This batch file clones your Notepad++ settings directory, then instructs you to edit the cloned config.xml file to enable "Always open a new document at startup"
  3. It makes all other files in the cloned directory into symbolic links, so all your session files stay up-to-date. (If you change any other settings in the app's Preferences dialog, you may want to re-run this batch script, though, since the contents of config.xml won't be automatically updated)
  4. Lastly, it saves the command string to your desktop. (Assuming you have a completely standard Notepad++ installation, this command would be: %ProgramFiles%\Notepad++\Notepad++.exe -settingsDir=%AppData%\Notepad++\Newtab )
ETL
  • 579
  • 10
  • 28
1

Simiar question.

Okay, it looks like researching this question I missed this 12-year-old question: Open two instances of Notepad++.... Very similar, a bit different.

Quick-and-Skinny Answer:

From cmd we use

echo . > filename.extension && "notepad++.exe" -multiInst -nosession filename.extension Important note: do not execute without -nosession or you could create problems, if you are using -multiInst.

!Warning!: do not run -multiInst WITHOUT -nosession. This really bungled things up for me! Notepad++ became extremely slow and clunky, crashed constantly, I tried re-installing and rebooting (did not help), eventually found "C:\Users%username%\AppData\Roaming\Notepad++\session.xml" (length ~500 lines) and decided it would be better to spend hours saving all my unsaved files and just deleting session.xml.... Notepad++ seems to be working fine, but I do not feel confident that I really fixed things!

case-sensitive, quote are important but not imperative in all settings. This should prompt you and ask you if you want to create the file if the file does not already exist.

Without echo . > filename.extension, we do not bypass the dialog asking "File does not exist. Create new?"

echo . > filename.extension && "notepad++.exe" -multiInst -nosession

creates the file first by chaining commands.

Powershell would use "./notepad++.exe", assuming your path is set correctly and you have created a new instance of cmd since updating your path.

In a running instance of NPP we can use Alt + F6 as stated in the question.

Prerequisites:

  • You need Notepad++ installed.
  • Add the Notepad++ directory to path. Default directory is C:\Program Files\Notepad++.
  • Run a fresh/new instance of cmd so that the path can take effect.
Wolfpack'08
  • 1,364