annotate runtime/doc/usr_21.txt @ 17547:1b8463f97365 v8.1.1771

patch 8.1.1771: options test fails on MS-Windows commit https://github.com/vim/vim/commit/d4404b4391a0cd3ab197e09bee7828c88882f6b2 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 28 18:38:09 2019 +0200 patch 8.1.1771: options test fails on MS-Windows Problem: Options test fails on MS-Windows. Solution: Add correct and incorrect values for 'completeslash'.
author Bram Moolenaar <Bram@vim.org>
date Sun, 28 Jul 2019 18:45:04 +0200
parents 0e473e9e70c2
children af69c9335223
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16553
0e473e9e70c2 patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
1 *usr_21.txt* For Vim version 8.1. Last change: 2019 Apr 25
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 VIM USER MANUAL - by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 Go away and come back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 This chapter goes into mixing the use of other programs with Vim. Either by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 executing program from inside Vim or by leaving Vim and coming back later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 Furthermore, this is about the ways to remember the state of Vim and restore
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 it later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 |21.1| Suspend and resume
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 |21.2| Executing shell commands
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 |21.3| Remembering information; viminfo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 |21.4| Sessions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 |21.5| Views
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 |21.6| Modelines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 Next chapter: |usr_22.txt| Finding the file to edit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 Previous chapter: |usr_20.txt| Typing command-line commands quickly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 Table of contents: |usr_toc.txt|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 *21.1* Suspend and resume
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 Like most Unix programs Vim can be suspended by pressing CTRL-Z. This stops
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 Vim and takes you back to the shell it was started in. You can then do any
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 other commands until you are bored with them. Then bring back Vim with the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 "fg" command. >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 CTRL-Z
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 {any sequence of shell commands}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 fg
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 You are right back where you left Vim, nothing has changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 In case pressing CTRL-Z doesn't work, you can also use ":suspend".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 Don't forget to bring Vim back to the foreground, you would lose any changes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 that you made!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 Only Unix has support for this. On other systems Vim will start a shell for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 you. This also has the functionality of being able to execute shell commands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 But it's a new shell, not the one that you started Vim from.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 When you are running the GUI you can't go back to the shell where Vim was
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 started. CTRL-Z will minimize the Vim window instead.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 *21.2* Executing shell commands
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 To execute a single shell command from Vim use ":!{command}". For example, to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 see a directory listing: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 :!ls
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 :!dir
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 The first one is for Unix, the second one for MS-Windows.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 Vim will execute the program. When it ends you will get a prompt to hit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 <Enter>. This allows you to have a look at the output from the command before
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 returning to the text you were editing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 The "!" is also used in other places where a program is run. Let's take
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 a look at an overview:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 :!{program} execute {program}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 :r !{program} execute {program} and read its output
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 :w !{program} execute {program} and send text to its input
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 :[range]!{program} filter text through {program}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 9
diff changeset
68 Notice that the presence of a range before "!{program}" makes a big
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 difference. Without it executes the program normally, with the range a number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 of text lines is filtered through the program.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 Executing a whole row of programs this way is possible. But a shell is much
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 better at it. You can start a new shell this way: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 :shell
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 This is similar to using CTRL-Z to suspend Vim. The difference is that a new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 shell is started.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 When using the GUI the shell will be using the Vim window for its input and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 output. Since Vim is not a terminal emulator, this will not work perfectly.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 If you have trouble, try toggling the 'guipty' option. If this still doesn't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 work well enough, start a new terminal to run the shell in. For example with:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 :!xterm&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 *21.3* Remembering information; viminfo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 After editing for a while you will have text in registers, marks in various
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 files, a command line history filled with carefully crafted commands. When
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 you exit Vim all of this is lost. But you can get it back!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 The viminfo file is designed to store status information:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 Command-line and Search pattern history
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 Text in registers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 Marks for various files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 The buffer list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 Global variables
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 Each time you exit Vim it will store this information in a file, the viminfo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 file. When Vim starts again, the viminfo file is read and the information
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 restored.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 The 'viminfo' option is set by default to restore a limited number of items.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 You might want to set it to remember more information. This is done through
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 the following command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 :set viminfo=string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 The string specifies what to save. The syntax of this string is an option
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 character followed by an argument. The option/argument pairs are separated by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 commas.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 Take a look at how you can build up your own viminfo string. First, the '
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 option is used to specify how many files for which you save marks (a-z). Pick
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 a nice even number for this option (1000, for instance). Your command now
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 looks like this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 :set viminfo='1000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 The f option controls whether global marks (A-Z and 0-9) are stored. If this
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 29
diff changeset
123 option is 0, none are stored. If it is 1 or you do not specify an f option,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 the marks are stored. You want this feature, so now you have this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 :set viminfo='1000,f1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 The < option controls how many lines are saved for each of the registers. By
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 default, all the lines are saved. If 0, nothing is saved. To avoid adding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 thousands of lines to your viminfo file (which might never get used and makes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 starting Vim slower) you use a maximum of 500 lines: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 :set viminfo='1000,f1,<500
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 <
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 Other options you might want to use:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 : number of lines to save from the command line history
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 @ number of lines to save from the input line history
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 / number of lines to save from the search history
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 r removable media, for which no marks will be stored (can be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 used several times)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 ! global variables that start with an uppercase letter and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 don't contain lowercase letters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 h disable 'hlsearch' highlighting when starting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 % the buffer list (only restored when starting Vim without file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 arguments)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 c convert the text using 'encoding'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 n name used for the viminfo file (must be the last option)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 See the 'viminfo' option and |viminfo-file| for more information.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 When you run Vim multiple times, the last one exiting will store its
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 information. This may cause information that previously exiting Vims stored
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 to be lost. Each item can be remembered only once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155
1733
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
156 GETTING BACK TO WHERE YOU STOPPED VIM
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 You are halfway editing a file and it's time to leave for holidays. You exit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 Vim and go enjoy yourselves, forgetting all about your work. After a couple
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 of weeks you start Vim, and type:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 '0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 And you are right back where you left Vim. So you can get on with your work.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 Vim creates a mark each time you exit Vim. The last one is '0. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 position that '0 pointed to is made '1. And '1 is made to '2, and so forth.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 Mark '9 is lost.
843
9f279ebda751 updated for version 7.0f01
vimboss
parents: 842
diff changeset
168 The |:marks| command is useful to find out where '0 to '9 will take you.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170
1733
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
171 GETTING BACK TO SOME FILE
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
172
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
173 If you want to go back to a file that you edited recently, but not when
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
174 exiting Vim, there is a slightly more complicated way. You can see a list of
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
175 files by typing the command: >
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
176
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
177 :oldfiles
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
178 < 1: ~/.viminfo ~
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
179 2: ~/text/resume.txt ~
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
180 3: /tmp/draft ~
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
181
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
182 Now you would like to edit the second file, which is in the list preceded by
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
183 "2:". You type: >
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
184
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
185 :e #<2
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
186
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
187 Instead of ":e" you can use any command that has a file name argument, the
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
188 "#<2" item works in the same place as "%" (current file name) and "#"
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
189 (alternate file name). So you can also split the window to edit the third
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
190 file: >
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
191
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
192 :split #<3
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
193
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
194 That #<123 thing is a bit complicated when you just want to edit a file.
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
195 Fortunately there is a simpler way: >
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
196
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
197 :browse oldfiles
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
198 < 1: ~/.viminfo ~
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
199 2: ~/text/resume.txt ~
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
200 3: /tmp/draft ~
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
201 -- More --
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
202
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
203 You get the same list of files as with |:oldfiles|. If you want to edit
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
204 "resume.txt" first press "q" to stop the listing. You will get a prompt:
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
205
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
206 Type number and <Enter> (empty cancels): ~
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
207
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
208 Type "2" and press <Enter> to edit the second file.
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
209
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
210 More info at |:oldfiles|, |v:oldfiles| and |c_#<|.
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
211
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1702
diff changeset
212
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 MOVE INFO FROM ONE VIM TO ANOTHER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 You can use the ":wviminfo" and ":rviminfo" commands to save and restore the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 information while still running Vim. This is useful for exchanging register
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 contents between two instances of Vim, for example. In the first Vim do: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 :wviminfo! ~/tmp/viminfo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 And in the second Vim do: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 :rviminfo! ~/tmp/viminfo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 Obviously, the "w" stands for "write" and the "r" for "read".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 The ! character is used by ":wviminfo" to forcefully overwrite an existing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 file. When it is omitted, and the file exists, the information is merged into
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 The ! character used for ":rviminfo" means that all the information is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 used, this may overwrite existing information. Without the ! only information
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 that wasn't set is used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 These commands can also be used to store info and use it again later. You
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 could make a directory full of viminfo files, each containing info for a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 different purpose.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 *21.4* Sessions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 Suppose you are editing along, and it is the end of the day. You want to quit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 work and pick up where you left off the next day. You can do this by saving
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 your editing session and restoring it the next day.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 A Vim session contains all the information about what you are editing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 This includes things such as the file list, window layout, global variables,
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 29
diff changeset
244 options and other information. (Exactly what is remembered is controlled by
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 the 'sessionoptions' option, described below.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 The following command creates a session file: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 :mksession vimbook.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 Later if you want to restore this session, you can use this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 :source vimbook.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 If you want to start Vim and restore a specific session, you can use the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 following command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 vim -S vimbook.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 This tells Vim to read a specific file on startup. The 'S' stands for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 session (actually, you can source any Vim script with -S, thus it might as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 well stand for "source").
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 The windows that were open are restored, with the same position and size as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 before. Mappings and option values are like before.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 What exactly is restored depends on the 'sessionoptions' option. The
16553
0e473e9e70c2 patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
266 default value is:
0e473e9e70c2 patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
267 "blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 blank keep empty windows
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 buffers all buffers, not only the ones in a window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 curdir the current directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 folds folds, also manually created ones
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 help the help window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 options all options and mappings
16553
0e473e9e70c2 patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
275 tabpages all tab pages
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 winsize window sizes
16553
0e473e9e70c2 patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
277 terminal include terminal windows
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 Change this to your liking. To also restore the size of the Vim window, for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 example, use: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 :set sessionoptions+=resize
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 SESSION HERE, SESSION THERE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 The obvious way to use sessions is when working on different projects.
3920
c53344bacabf Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2577
diff changeset
288 Suppose you store your session files in the directory "~/.vim". You are
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 currently working on the "secret" project and have to switch to the "boring"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 project: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 :wall
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 :mksession! ~/.vim/secret.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 :source ~/.vim/boring.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 This first uses ":wall" to write all modified files. Then the current session
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 is saved, using ":mksession!". This overwrites the previous session. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 next time you load the secret session you can continue where you were at this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 point. And finally you load the new "boring" session.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300
3920
c53344bacabf Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2577
diff changeset
301 If you open help windows, split and close various windows, and generally mess
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 up the window layout, you can go back to the last saved session: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 :source ~/.vim/boring.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 Thus you have complete control over whether you want to continue next time
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 where you are now, by saving the current setup in a session, or keep the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 session file as a starting point.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 Another way of using sessions is to create a window layout that you like to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 use, and save this in a session. Then you can go back to this layout whenever
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 you want.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 For example, this is a nice layout to use:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 +----------------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 | VIM - main help file |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 |Move around: Use the cursor keys, or "h|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 |help.txt================================|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 |explorer | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 |dir |~ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 |dir |~ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 |file |~ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 |file |~ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 |file |~ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 |file |~ |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 |~/=========|[No File]===================|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 +----------------------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 This has a help window at the top, so that you can read this text. The narrow
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 vertical window on the left contains a file explorer. This is a Vim plugin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 that lists the contents of a directory. You can select files to edit there.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 More about this in the next chapter.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 Create this from a just started Vim with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 :help
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 CTRL-W w
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 :vertical split ~/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 You can resize the windows a bit to your liking. Then save the session with:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 :mksession ~/.vim/mine.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 Now you can start Vim with this layout: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 vim -S ~/.vim/mine.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 Hint: To open a file you see listed in the explorer window in the empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 window, move the cursor to the filename and press "O". Double clicking with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 the mouse will also do this.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 UNIX AND MS-WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 Some people have to do work on MS-Windows systems one day and on Unix another
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 day. If you are one of them, consider adding "slash" and "unix" to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 'sessionoptions'. The session files will then be written in a format that can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 be used on both systems. This is the command to put in your vimrc file: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 :set sessionoptions+=unix,slash
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 Vim will use the Unix format then, because the MS-Windows Vim can read and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 write Unix files, but Unix Vim can't read MS-Windows format session files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 Similarly, MS-Windows Vim understands file names with / to separate names, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 Unix Vim doesn't understand \.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 SESSIONS AND VIMINFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 Sessions store many things, but not the position of marks, contents of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 registers and the command line history. You need to use the viminfo feature
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 for these things.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 In most situations you will want to use sessions separately from viminfo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 This can be used to switch to another session, but keep the command line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 history. And yank text into registers in one session, and paste it back in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 another session.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 You might prefer to keep the info with the session. You will have to do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 this yourself then. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 :mksession! ~/.vim/secret.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 :wviminfo! ~/.vim/secret.viminfo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 And to restore this again: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 :source ~/.vim/secret.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 :rviminfo! ~/.vim/secret.viminfo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 *21.5* Views
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 A session stores the looks of the whole of Vim. When you want to store the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 properties for one window only, use a view.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 The use of a view is for when you want to edit a file in a specific way.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 For example, you have line numbers enabled with the 'number' option and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 defined a few folds. Just like with sessions, you can remember this view on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 the file and restore it later. Actually, when you store a session, it stores
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 the view of each window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 There are two basic ways to use views. The first is to let Vim pick a name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 for the view file. You can restore the view when you later edit the same
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 file. To store the view for the current window: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 :mkview
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 Vim will decide where to store the view. When you later edit the same file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 you get the view back with this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 :loadview
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 That's easy, isn't it?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 Now you want to view the file without the 'number' option on, or with all
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 folds open, you can set the options to make the window look that way. Then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 store this view with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 :mkview 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 Obviously, you can get this back with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 :loadview 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 Now you can switch between the two views on the file by using ":loadview" with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 and without the "1" argument.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 You can store up to ten views for the same file this way, one unnumbered
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 and nine numbered 1 to 9.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 A VIEW WITH A NAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 The second basic way to use views is by storing the view in a file with a name
3920
c53344bacabf Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2577
diff changeset
429 you choose. This view can be loaded while editing another file. Vim will
c53344bacabf Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2577
diff changeset
430 then switch to editing the file specified in the view. Thus you can use this
c53344bacabf Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2577
diff changeset
431 to quickly switch to editing another file, with all its options set as you
c53344bacabf Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2577
diff changeset
432 saved them.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 For example, to save the view of the current file: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 :mkview ~/.vim/main.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 You can restore it with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 :source ~/.vim/main.vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 *21.6* Modelines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 When editing a specific file, you might set options specifically for that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 file. Typing these commands each time is boring. Using a session or view for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 editing a file doesn't work when sharing the file between several people.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 The solution for this situation is adding a modeline to the file. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 a line of text that tells Vim the values of options, to be used in this file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 only.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 A typical example is a C program where you make indents by a multiple of 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 spaces. This requires setting the 'shiftwidth' option to 4. This modeline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 will do that:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 /* vim:set shiftwidth=4: */ ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 Put this line as one of the first or last five lines in the file. When
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 editing the file, you will notice that 'shiftwidth' will have been set to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 four. When editing another file, it's set back to the default value of eight.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 For some files the modeline fits well in the header, thus it can be put at
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 the top of the file. For text files and other files where the modeline gets
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 in the way of the normal contents, put it at the end of the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 The 'modelines' option specifies how many lines at the start and end of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 file are inspected for containing a modeline. To inspect ten lines: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 :set modelines=10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 The 'modeline' option can be used to switch this off. Do this when you are
1122
2ad54fcf37e3 updated for version 7.1a
vimboss
parents: 874
diff changeset
469 working as root on Unix or Administrator on MS-Windows, or when you don't
2ad54fcf37e3 updated for version 7.1a
vimboss
parents: 874
diff changeset
470 trust the files you are editing: >
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 :set nomodeline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 Use this format for the modeline:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 any-text vim:set {option}={value} ... : any-text ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 The "any-text" indicates that you can put any text before and after the part
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 that Vim will use. This allows making it look like a comment, like what was
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 done above with /* and */.
1122
2ad54fcf37e3 updated for version 7.1a
vimboss
parents: 874
diff changeset
481 The " vim:" part is what makes Vim recognize this line. There must be
2ad54fcf37e3 updated for version 7.1a
vimboss
parents: 874
diff changeset
482 white space before "vim", or "vim" must be at the start of the line. Thus
2ad54fcf37e3 updated for version 7.1a
vimboss
parents: 874
diff changeset
483 using something like "gvim:" will not work.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 The part between the colons is a ":set" command. It works the same way as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 typing the ":set" command, except that you need to insert a backslash before a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 colon (otherwise it would be seen as the end of the modeline).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 Another example:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 // vim:set textwidth=72 dir=c\:\tmp: use c:\tmp here ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 There is an extra backslash before the first colon, so that it's included in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 the ":set" command. The text after the second colon is ignored, thus a remark
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 can be placed there.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 For more details see |modeline|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 Next chapter: |usr_22.txt| Finding the file to edit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501
14519
5c5908e81e93 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 13963
diff changeset
502 Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: