Notepad++ Secrets: Sessions

© 2012, Martin Rinehart

Programmer's editor Notepad++ can open your previous "session" when launched (Settings / Preferences / MISC. / "Remember current session for next launch"). This is normally exactly what you want. Don't let it hide the fact that you have other options.

What Is a Session?

In Notepad++, a "session" is work on a given set of files. When you open a file it is opened at the top, without bookmarks. When your file is part of a session, it is opened, bookmarks are re-installed and it is positioned exactly as you left it.

If you will work tomorrow on the same files you are working on today, the default (reopen the previous session) will be perfect. But if another project intrudes in the middle of your work today, fear not. Save a session; do your other work and resume the saved session.

Session files are readable, editable XML.

Creating a Session

File/Save Session... is all you need. (A moment's initial thought is required. What folder do you want to use for session files? What file extension?)

Resuming a Session

File/Load Session... is all you need. The Session files are opened after any that you have open. Files already open are not changed.

There you have it. A Notepad++ feature that couldn't be simpler. If this is too simple, try the Project Panels for a rich set of IDE-like features.

Naming a Session

I'm working on Whatever. I'll have Whatever.HTML, Whatever.CSS, Whatever.js, ... All these are open in np++. I'll File/Save Session to Whatever.NPP. (You can use any name you like. Use your extension association to have np++ open *.npp, or whatever you like. Then forget about it.)

Editing a Session

These are XML and at least theoretically you can edit the XML. I never do. Just load a session, close a file, open another two files and save your session. From then on, you'll not have the file you closed but you'll have the two you opened.

Automating Sessions

If I'm working on three projects, This, That and TheOther, I create three batch files, This.bat, That.bat and TheOther.bat. I'll use three browsers (Opera, Chrome and Firefox, for examples) each browser set to open whatever tabs I had open last time.

Here's an example of a project for which I'm using Opera:

REM c:/bat/exquisitely-sexy.bat

rem opera syntax: start "file to launch" "path\Opera\launcher.exe"

start "" "C:\Program Files (x86)\Opera\launcher.exe"

start "C:\Program Files (x86)\LibreOffice 4.0\program\scalc.exe" "c:\Users\Rinehart\Google Drive\exquisitely\plot-timeline.ods"

rem start "C:\Program Files (x86)\LibreOffice 4.0\program\swriter.exe" "c:\Users\Rinehart\Google Drive\explicitly\source\explicitly-sexy.odt"

rem start "C:\Program Files (x86)\LibreOffice 4.0\program\swriter.exe" "c:\Users\Rinehart\Google Drive\exquisitely\exquisitely-library.odt"

rem start "C:\Program Files (x86)\Notepad++\notepad++.exe" "c:\Users\Rinehart\Google Drive\exquisitely\plot plan.txt"

start "C:\Program Files (x86)\Notepad++\notepad++.exe" c:\Users\Rinehart\"Google Drive"\exquisitely\exquisitely-sexy.npp

REM end expquisitely-sexy.bat

(Those ‘rem’ are typical. As I work on a project I add and delete stuff to keep my desktop focused on the problem du jour.)

The last non-rem opens my np++ session.

Feedback: MartinRinehart at gmail dot com.

# # #