Home Explore Blog CI



neovim

2nd chunk of `runtime/doc/usr_21.txt`
cf77698a7819f0808867d28470f64be1f97bdd215b76386d0000000100000fa0
 marks in various
files, a command line history filled with carefully crafted commands.  When
you exit Vim all of this is lost.  But you can get it back!

The ShaDa (abbreviation of SHAred DAta) file is designed to store status
information:

	Command-line and Search pattern history
	Text in registers
	Marks for various files
	The buffer list
	Global variables

Each time you exit Vim it will store this information in a file, the ShaDa
file.  When Vim starts again, the ShaDa file is read and the information
restored.

The 'shada' option is set by default to restore a limited number of items.
You might want to set it to remember more information.  This is done through
the following command: >

	:set shada=string

The string specifies what to save.  The syntax of this string is an option
character followed by an argument.  The option/argument pairs are separated by
commas.
   Take a look at how you can build up your own shada string.  First, the '
option is used to specify how many files for which you save marks (a-z).  Pick
a nice even number for this option (1000, for instance).  Your command now
looks like this: >

	:set shada='1000

The f option controls whether global marks (A-Z and 0-9) are stored.  If this
option is 0, none are stored.  If it is 1 or you do not specify an f option,
the marks are stored.  You want this feature, so now you have this: >

	:set shada='1000,f1

The < option controls how many lines are saved for each of the registers.  By
default, all the lines are saved.  If 0, nothing is saved.  To avoid adding
thousands of lines to your ShaDa file (which might never get used and makes
starting Vim slower) you use a maximum of 500 lines: >

	:set shada='1000,f1,<500
<
Other options you might want to use:
	:	number of lines to save from the command line history
	@	number of lines to save from the input line history
	/	number of lines to save from the search history
	r	removable media, for which no marks will be stored (can be
		used several times)
	!	global variables that start with an uppercase letter and
		don't contain lowercase letters
	h	disable 'hlsearch' highlighting when starting
	%	the buffer list (only restored when starting Vim without file
		arguments)
	c	convert the text using 'encoding'
	n	name used for the ShaDa file (must be the last option)

See the 'shada' option and |shada-file| for more information.

When you run Vim multiple times, the last one exiting will store its
information.  This may cause information that previously exiting Vims stored
to be lost.  Each item can be remembered only once.


GETTING BACK TO WHERE YOU STOPPED VIM

You are halfway through editing a file and it's time to leave for holidays.
You exit Vim and go enjoy yourselves, forgetting all about your work.  After a
couple of weeks you start Vim, and type:
>
	'0

And you are right back where you left Vim.  So you can get on with your work.
   Vim creates a mark each time you exit Vim.  The last one is '0.  The
position that '0 pointed to is made '1.  And '1 is made to '2, and so forth.
Mark '9 is lost.
   The |:marks| command is useful to find out where '0 to '9 will take you.


GETTING BACK TO SOME FILE

If you want to go back to a file that you edited recently, but not when
exiting Vim, there is a slightly more complicated way.  You can see a list of
files by typing the command: >

	:oldfiles
<	1: ~/.config/nvim/init.vim ~
	2: ~/text/resume.txt ~
	3: /tmp/draft ~

Now you would like to edit the second file, which is in the list preceded by
"2:".  You type: >

	:e #<2

Instead of ":e" you can use any command that has a file name argument, the
"#<2" item works in the same place as "%" (current file name) and "#"
(alternate file name).  So you can also split the window to edit the third
file: >

	:split #<3

That #<123 thing is a bit complicated when you just want to edit a file.
Fortunately there is a simpler way: >

	:browse oldfiles
<	1: ~/.config/nvim/init.vim ~
	2: ~/text/resume.txt ~
	3: /tmp/draft ~
	-- More --

You

Title: ShaDa File Configuration and Restoring Vim State
Summary
This section explains how to configure the ShaDa file to store and restore Vim's state, including command-line history, registers, marks, buffer list, and global variables. It describes the 'shada' option and its various parameters for specifying what to save, such as the number of files for marks, global marks, and lines saved for registers. It also covers how to use marks '0 to '9 to return to previous editing positions and how to use the `:oldfiles` command to revisit recently edited files.