With Notepad++ it is possible to jump into a source file at a certain line number using the option "-n" together with the target filename. Now, I'd like to start Notepad++ from the command line and directly jump to a certain function definition block, e.g. by specifying a certain text string on the command line. Thus realizing direct links to a block of soure code whose starting line number might change frequently. Would this be possible somehow?
2 Answers
Try to find out the line number first, and passing that as an argument to Notepad++.
set results=find /n "string we are looking for" C:\path-to-file.txt
/n adds the line number at the beginning in your results
findstr may be helpful to extract the line number after you used find: echo %results%|findstr /R some_pattern
See also:
The best way is to create a small script (Batch, Perl, whatever) that retrieve the line number and run Notepad++.
Here is an example with windows batch; to run it, you just need to do
Notepad_jumpline.bat <filename> <section>
@REM --Notepad_jumpline.bat--
@echo off
for /f "tokens=1" %%i in ('findstr /n %2 %1') do (
set n_lines=%%i
goto _Run_Notepad_
)
:_Run_Notepad_
set n_lines=%n_lines::=%
"C:\Program Files (x86)\Notepad++\notepad++.exe" %1 -n%n_lines%