data") file *shada* *shada-file*
If you exit Vim and later start it again, you would normally lose a lot of
information. The ShaDa file can be used to remember that information, which
enables you to continue where you left off. Its name is the abbreviation of
SHAred DAta because it is used for sharing data between Nvim sessions.
This is introduced in section |21.3| of the user manual.
The ShaDa file is used to store:
- The command line history.
- The search string history.
- The input-line history.
- Contents of non-empty registers.
- Marks for several files.
- File marks, pointing to locations in files.
- Last search/substitute pattern (for 'n' and '&').
- The buffer list.
- Global variables.
You could also use a Session file. The difference is that the ShaDa file
does not depend on what you are working on. There normally is only one
ShaDa file. Session files are used to save the state of a specific editing
Session. You could have several Session files, one for each project you are
working on. ShaDa and Session files together can be used to effectively
enter Vim and directly start working in your desired setup. |session-file|
*shada-read*
When Vim is started and the 'shada' option is non-empty, the contents of
the ShaDa file are read and the info can be used in the appropriate places.
The |v:oldfiles| variable is filled. The marks are not read in at startup
(but file marks are). See |initialization| for how to set the 'shada'
option upon startup.
*shada-write*
When Vim exits and 'shada' is non-empty, the info is stored in the ShaDa file
(it's actually merged with the existing one, if one exists |shada-merging|).
The 'shada' option is a string containing information about what info should
be stored, and contains limits on how much should be stored (see 'shada').
Notes for Unix:
- The file protection for the ShaDa file will be set to prevent other users
from being able to read it, because it may contain any text or commands that
you have worked with.
- If you want to share the ShaDa file with other users (e.g. when you "su"
to another user), you can make the file writable for the group or everybody.
Vim will preserve this when writing new ShaDa files. Be careful, don't
allow just anybody to read and write your ShaDa file!
- Vim will not overwrite a ShaDa file that is not writable by the current
"real" user. This helps for when you did "su" to become root, but your
$HOME is still set to a normal user's home directory. Otherwise, Vim would
create a ShaDa file owned by root that nobody else can read.
- The ShaDa file cannot be a symbolic link. This is to avoid security
issues.
Marks are stored for each file separately. When a file is read and 'shada'
is non-empty, the marks for that file are read from the ShaDa file. NOTE:
The marks are only written when exiting Vim, which is fine because marks are
remembered for all the files you have opened in the current editing session,
unless ":bdel" is used. If you want to save the marks for a file that you are
about to abandon with ":bdel", use ":wsh". The '[' and ']' marks are not
stored, but the '"' mark is. The '"' mark is very useful for jumping to the
cursor position when the file was last exited. No marks are saved for files
that start with any string given with the "r" flag in 'shada'. This can be
used to avoid saving marks for files on removable media (for MS-Windows you
would use "ra:,rb:").
The |v:oldfiles| variable is filled with the file names that the ShaDa file
has marks for.
*shada-file-marks*
Uppercase marks ('A to 'Z) are stored when writing the ShaDa file. The
numbered marks ('0 to '9) are a bit special. When the ShaDa file is written
(when exiting or with the |:wshada| command), '0 is set to the current cursor
position and file. The old '0 is moved to '1, '1 to '2, etc. This
resembles what happens with the "1 to "9 delete registers. If the current
cursor position is already present in '0 to '9, it