How to recover a Notepad++ lost session
Unless you have saved your session in the cloud, like the previous answer, you can't restore your whole session. You can, however, restore your unsaved (new) notes. They are stored at:
%APPDATA%\Notepad++\backup
You may either open all those files directly in Notepad++, or you can remake the session file in:
%APPDATA%\Notepad++\session.xml
so that the <mainView>
section will include all of them.
Here's a Python script to make it easier to redo the session file. Just paste the output between the <mainView>
and the </mainView>
tags:
import os
import os.path as osp
npp_path = osp.join(osp.expandvars('%APPDATA%'), 'Notepad++', 'backup')
for fn in sorted(os.listdir(npp_path), key=lambda fn: fn.split('@')[1]):
name = fn.split('@')[0]
print('<File firstVisibleLine="0" xOffset="0" scrollWidth="64" '
'startPos="8" endPos="8" selMode="0" lang="Normal Text" '
'encoding="-1" userReadOnly="no" filename="{name}" '
'backupFilePath="{npp_path}\{fn}" originalFileLastModifTimestamp="0"'
'originalFileLastModifTimestampHigh="0" '
'mapFirstVisibleDisplayLine="-1" mapFirstVisibleDocLine="-1" '
'mapLastVisibleDocLine="-1" mapNbLine="-1" mapHigherPos="-1" '
'mapWidth="-1" mapHeight="-1" mapKByteInDoc="0" '
'mapWrapIndentMode="-1" mapIsWrap="no" />'.format(
name=name, npp_path=npp_path, fn=fn))
You cannot, but you can secure against happening this again.
This is possible if you have your cloud path set in Preferences:
After the breakdown, immediately turn off syncing with the cloud and restore the original file from there. If your cloud has file versioning, then it is simpler: just retrieve the older version of the sessions.xml
.
This also works for all other setting files, see the link above for details.
Also be sure that you updated to at least Notepad++ 7.5.9.
In its list of fixed bugs, there is
- Fix possible file corruption during backup or power loss or other abnormal N++ termination.
So yes, this has been addressed in October 2018.
Thanks to Joe Pineda for his comment on the backup folder. After losing my crashed session, I saw that in this folder there were many files - both unsaved notes and opened existing files. They were of non-zero size in bytes but neither the ordinary Notepad, nor Notepad++ itself displayed anything. However, you can read them in Linux.
Remember to make a copy of your backup directory in case something unexpectedly goes wrong.
I recovered my unsaved notes by making a list of the file names and removing the "new" from the filename (Windows just loves spaces in file names).
for note in $(ls new*); do echo $note | grep -v new; done
This list of names can be saved in a variable and then the files can be copied to e.g .txt:
filenames=$(for note in $(ls new*); do echo $note | grep -v new; done)
for f in $filenames ; do cp 'new '$f 'new '$f.txt; done