How to configure what Neovim saves between sessions using the ShaDa file?
Answer
:set shada
Explanation
Neovim's ShaDa (Shared Data) file replaces Vim's viminfo and persists session state across restarts — marks, registers, command history, search history, jump lists, and buffer lists. The shada option controls exactly what gets saved and in what quantity, letting you tune session persistence to your workflow.
How it works
The shada option accepts a comma-separated string of flags. Each flag is a single character optionally followed by a number:
| Flag | Meaning |
|---|---|
'N |
Remember marks for the last N files (default: 100) |
<N |
Maximum lines saved per register (default: 50) |
:N |
Number of command-line history entries to save (default: 100) |
/N |
Number of search history entries to save |
% |
Save and restore the buffer list |
h |
Disable search highlight restoration on startup |
s/N |
Discard registers larger than N kilobytes |
n/path |
Override the location of the ShaDa file |
Example
A power-user config that remembers more history and restores the buffer list:
set shada='200,<1000,:1000,/200,%,h
This saves marks for 200 files, up to 1000 register lines, 1000 command-line entries, 200 search patterns, restores the buffer list, and suppresses hlsearch restoration.
Tips
:wshada!forces an immediate write of the current session state to disk — useful before killing a frozen session:rshada!re-reads the ShaDa file, merging any state written by other Neovim instances (Neovim can safely share a ShaDa file across concurrent sessions)- In Lua config:
vim.opt.shada = "'200,<1000,:1000,/200,%,h" - The default ShaDa file location is
~/.local/share/nvim/shada/main.shada— override withnpathif you want to store it in a cloud-synced folder