How to Open File at a Specific Line Number in Notepad++
Notepad++ has a built-in feature where it remembers the last edited position in a document. This could be quite useful when one is working on a large file regularly. Each time you open Notepad++, you are directly brought to the line where you left off previously. For this functionality to work, you’ve to keep the document open in the editor. Depending on the file or environment, it may not be always possible to do that. An alternate way to open file at a specific line number in Notepad++ is to make use of a command line switch while opening the file. Here’s how to do it.
Open File at a Specific Line Number in Notepad++
We can control Notepad++ startup by passing the line number as an argument at launch time from the command line or via a shortcut. You can use the command-line option as following:
For example, to open a file directly at line 1500, we can pass it as
notepad++ filename -n1500.
To run this from command prompt, you can use this command:
start notepad++ "C:\Files\file.txt" -n1500
Open Multiple File at a Specific Line Number
In the same way, you can open multiple files at a specific line number like this:
start notepad++ -multiInst "C:\Files\file1.txt" -n1500 start notepad++ -multiInst "C:\Files\file2.txt" -n1000
By default Notepad++ runs in a single instance. -multiInst enables opening of multiple instances.
Create Desktop Shortcut to Open File at Specific Line
We can also create a desktop shortcut to the file by editing the target path as below. The target field should read something like:
"C:\Program Files (x86)\Notepad++\notepad++.exe" "C:\Files\file.txt" -n1500
Open Text File at a Specific Line Number with AutoHotkey
If you use AutoHotkey, we can create a shortcut to launch file at a specific line:
^!1:: Run, "C:\Program Files (x86)\Notepad++\notepad++.exe" "C:\Files\file.txt" -n99 Return
Similarly, we can set up hotkeys for multiple files and line numbers.
Notepad++ supports a lot of command line switches. These can be used to manipulate how a file opens:
-alwaysOnTop: Opens file as topmost window
-c<column number>: Scroll to particular
<column number>in file
-l<language>: Applies specified
-multiInst: Launch multiple instances of Notepad++
-n<line number>: Go to particular
<line number>after opening
-noPlugins: Disable all plugins for the specified file
-nosession: Launch file in a blank session
-notabbar: Disable tab interface
-x<x-coordinate>: Position text file at a specific horizontal position on screen
-y<y-coordinate>: Position file at a specific vertical position on screen