*usr_21.txt* Nvim
VIM USER MANUAL - by Bram Moolenaar
Go away and come back
This chapter goes into mixing the use of other programs with Vim. Either by
executing program from inside Vim or by leaving Vim and coming back later.
Furthermore, this is about the ways to remember the state of Vim and restore
it later.
|21.1| Suspend and resume
|21.2| Executing shell commands
|21.3| Remembering information; ShaDa
|21.4| Sessions
|21.5| Views
|21.6| Modelines
Next chapter: |usr_22.txt| Finding the file to edit
Previous chapter: |usr_20.txt| Typing command-line commands quickly
Table of contents: |usr_toc.txt|
==============================================================================
*21.1* Suspend and resume
Like most Unix programs Vim can be suspended by pressing CTRL-Z. This stops
Vim and takes you back to the shell it was started in. You can then do any
other commands until you are bored with them. Then bring back Vim with the
"fg" command. >
CTRL-Z
{any sequence of shell commands}
fg
You are right back where you left Vim, nothing has changed.
In case pressing CTRL-Z doesn't work, you can also use ":suspend".
Don't forget to bring Vim back to the foreground, you would lose any changes
that you made!
Only Unix has support for this. On other systems Vim will start a shell for
you. This also has the functionality of being able to execute shell commands.
But it's a new shell, not the one that you started Vim from.
When you are running the GUI you can't go back to the shell where Vim was
started. CTRL-Z will minimize the Vim window instead.
==============================================================================
*21.2* Executing shell commands
To execute a single shell command from Vim use ":!{command}". For example, to
see a directory listing: >
:!ls
:!dir
The first one is for Unix, the second one for MS-Windows.
Vim will execute the program. When it ends you will get a prompt to hit
<Enter>. This allows you to have a look at the output from the command before
returning to the text you were editing.
The "!" is also used in other places where a program is run. Let's take
a look at an overview:
:!{program} execute {program}
:r !{program} execute {program} and read its output
:w !{program} execute {program} and send text to its input
:[range]!{program} filter text through {program}
Notice that the presence of a range before "!{program}" makes a big
difference. Without it executes the program normally, with the range a number
of text lines is filtered through the program.
Executing a whole row of programs this way is possible. But a shell is much
better at it. You can start a new shell with |:terminal|.
This is similar to using CTRL-Z to suspend Vim. The difference is that a new
shell is started.
==============================================================================
*21.3* Remembering information; ShaDa
After editing for a while you will have text in registers, 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