Command history in zsh

Currently I have zsh set up in such a way that command history is shared between all sessions immediately.

Say I have a terminal emulator open with two tabs, each with a zsh session, A1 and A2. If I enter ls -la in A1, and then go to A2 and press up arrow key, I will see ls -la in the command prompt.

I would like to change it so sessions don't share the command history with each other although when you start new session it gets all the previous history from all sessions before it.


Solution 1:

Check out the available options to control history. I think you want

setopt append_history no_inc_append_history no_share_history

This is the default zsh setup, by the way.

You can save the history explicitly at any point with fc -AI and merge it back in with fc -RI.