@Gideon-Addai said in Keep hidden lines hidden:
I have a long script file which I edit from time to time, and its annoying to use the search function every time to go to a certain line. It would be nice to keep hidden lines hidden, any ideas?
I get around that issue by taking advantage of that Notepad++ already has the -n command line option to open a file at a specific line number or to jump to that line if it’s already open. Notepad++ does not have a similar command line option to go to a specific line based on a search of the text in the file I want to open. To get around this I first figure out the line number and then use Notepad++'s -n command line option when opening the file.
Here is a trimmed down batch file script:
set XFILE=c:\path to the text file
set "XTAG=The tag or anchor within the text file I want to go to"
findstr /n /c:"%XTAG%" "%XFILE%" >"%TEMP%\~nptag1.txt"
if errorlevel 1 goto :tag_not_found
sed -r -n -e "s~^([0-9]+):.+~set XLINE=\1~p" "%TEMP%\~nptag1.txt" >"%TEMP%\~nptag2.bat"
if errorlevel 1 goto :sed_failed
set XLINE=1
call "%TEMP%\~nptag2.bat"
"%ProgramFiles%\Notepad++\Notepad++.exe" -n%XLINE% "%XFILE%"
The script first uses findstr to return a list of lines with their line numbers that match XTAG. If desired, I could use findstr’s /r option for the crude regular expressions that findstr supports.
The script then uses GNU sed to extract the line number(s) from the findstr results and to convert those into a .bat file line that sets the XLINE variable for each line found. If more than one line matches XTAG then there will be more then one line in the temporary batch file meaning we will jump to the last XTAG found. If that bothers you then you can add logic to deal with this.
The script then calls the temporary batch file to set the XLINE environment variable.
Last is the line that runs Notepad++ and opens the text file at the desired line number. If you are using a 32-bit installation of Notepad++ on a 64-bit machine then use %ProgramFiles(x86)% instead of %ProgramFiles% in the last line or replace it with the path to your copy of Notepad++ (The full path is in Notepad++'s ? / Debug info... results in the Path: line.)