690
|
1 *tabpage.txt* For Vim version 7.0aa. Last change: 2006 Feb 26
|
674
|
2
|
|
3
|
|
4 VIM REFERENCE MANUAL by Bram Moolenaar
|
|
5
|
|
6
|
675
|
7 Editing with windows in multiple tab pages. *tab-page* *tabpage*
|
674
|
8
|
|
9 The commands which have been added to use multiple tab pages are explained
|
|
10 here. Additionally, there are explanations for commands that work differently
|
|
11 when used in combination with more than one tab page.
|
|
12
|
678
|
13 1. Introduction |tab-page-intro|
|
|
14 2. Commands |tab-page-commands|
|
|
15 3. Other items |tab-page-other|
|
|
16 4. Setting 'tabline' |setting-tabline|
|
686
|
17 5. Setting 'guitablabel' |setting-guitablabel|
|
674
|
18
|
|
19 {Vi does not have any of these commands}
|
|
20 {not able to use multiple tab pages when the |+windows| feature was disabled
|
|
21 at compile time}
|
|
22
|
|
23 ==============================================================================
|
|
24 1. Introduction *tab-page-intro*
|
|
25
|
|
26 A tab page holds one or more windows. You can easily switch between tab
|
|
27 pages, so that you have several collections of windows to work on different
|
|
28 things.
|
|
29
|
|
30 Usually you will see a list of labels at the top of the Vim window, one for
|
|
31 each tab page. With the mouse you can click on the label to jump to that tab
|
|
32 page. There are other ways to move between tab pages, see below.
|
|
33
|
|
34 Most commands work only in the current tab page. That includes the |CTRL-W|
|
|
35 commands, |:windo|, |:all| and |:ball|. The commands that are aware of
|
|
36 other tab pages than the current one are mentioned below.
|
|
37
|
|
38 Tabs are also a nice way to edit a buffer temporarily without changing the
|
|
39 current window layout. Open a new tab page, do whatever you want to do and
|
|
40 close the tab page.
|
|
41
|
|
42 ==============================================================================
|
|
43 2. Commands *tab-page-commands*
|
|
44
|
|
45 OPENING A NEW TAB PAGE:
|
|
46
|
|
47 When starting Vim "vim -p filename ..." opens each file argument in a separate
|
|
48 tab page (up to 10). |-p|
|
|
49
|
682
|
50 A double click with the mouse in the tab pages line opens a new, empty tab
|
|
51 page. It is placed left of the position of the click. The first click may
|
|
52 select another tab page first, causing an extra screen update.
|
|
53
|
|
54 :tabe[dit] *:tabe* *:tabedit* *:tabnew*
|
|
55 :tabnew Open a new tab page with an empty window, after the current
|
|
56 tab page.
|
674
|
57
|
|
58 :tabe[dit] [++opt] [+cmd] {file}
|
682
|
59 :tabnew [++opt] [+cmd] {file}
|
674
|
60 Open a new tab page and edit {file}, like with |:edit|.
|
|
61
|
675
|
62 :tabf[ind] [++opt] [+cmd] {file} *:tabf* *:tabfind*
|
674
|
63 Open a new tab page and edit {file} in 'path', like with
|
|
64 |:find|.
|
|
65 {not available when the |+file_in_path| feature was disabled
|
|
66 at compile time}
|
|
67
|
682
|
68 :[count]tab {cmd} *:tab*
|
|
69 Execute {cmd} and when it opens a new window open a new tab
|
|
70 page instead. Doesn't work for |:diffsplit| or |:diffpatch|.
|
|
71 When [count] is omitted the tab page appears after the current
|
|
72 one. When [count] is specified the new tab page comes after
|
|
73 tab page [count]. Use ":0tab cmd" to get the new tab page as
|
|
74 the first one. Examples: >
|
|
75 :tab split " opens current buffer in new tab page
|
|
76 :tab help gt " opens tab page with help for "gt"
|
|
77
|
674
|
78
|
|
79 CLOSING A TAB PAGE:
|
|
80
|
682
|
81 Closing the last window of a tab page closes the tab page too, unless there is
|
|
82 only one tab page.
|
674
|
83
|
|
84 Using the mouse: If the tab page line is displayed you can click in the "X" at
|
682
|
85 the top right to close the current tab page. A custom |'tabline'| may show
|
|
86 something else.
|
674
|
87
|
|
88 *:tabc* *:tabclose*
|
|
89 :tabc[lose][!] Close current tab page.
|
|
90 This command fails when:
|
|
91 - There is only one tab page on the screen. *E784*
|
|
92 - When 'hidden' is not set, [!] is not used, a buffer has
|
|
93 changes, and there is no other window on this buffer.
|
|
94 Changes to the buffer are not written and won't get lost, so
|
|
95 this is a "safe" command.
|
|
96
|
|
97 :tabc[lose][!] {count}
|
|
98 Close tab page {count}. Fails in the same way as ':tabclose"
|
|
99 above.
|
|
100
|
|
101 *:tabo* *:tabonly*
|
|
102 :tabo[nly][!] Close all other tab pages.
|
|
103 When the 'hidden' option is set, all buffers in closed windows
|
|
104 become hidden.
|
|
105 When 'hidden' is not set, and the 'autowrite' option is set,
|
|
106 modified buffers are written. Otherwise, windows that have
|
|
107 buffers that are modified are not removed, unless the [!] is
|
|
108 given, then they become hidden. But modified buffers are
|
|
109 never abandoned, so changes cannot get lost.
|
|
110
|
|
111
|
|
112 SWITCHING TO ANOTHER TAB PAGE:
|
|
113
|
|
114 Using the mouse: If the tab page line is displayed you can click in a tab page
|
682
|
115 label to switch to that tab page. Click where there is no label to go to the
|
|
116 next tab page. |'tabline'|
|
674
|
117
|
682
|
118 :tabn[ext] *:tabn* *:tabnext* *gt*
|
674
|
119 gt Go to the next tab page. Wraps around from the last to the
|
|
120 first one.
|
|
121
|
682
|
122 :tabn[ext] {count}
|
674
|
123 {count}gt Go to tab page {count}. The first tab page has number one.
|
|
124
|
|
125
|
682
|
126 :tabp[revious] *:tabp* *:tabprevious* *gT*
|
|
127 :tabN[ext] *:tabN* *:tabNext*
|
|
128 gT Go to the previous tab page. Wraps around from the first one
|
|
129 to the last one.
|
|
130
|
|
131 :tabp[revious] {count}
|
|
132 :tabN[ext] {count}
|
|
133 {count}gT Go {count} tab pages back. Wraps around from the first one
|
|
134 to the last one.
|
|
135
|
685
|
136 :tabr[ewind] *:tabfir* *:tabfirst* *:tabr* *:tabrewind*
|
686
|
137 :tabfir[st] Go to the first tab page.
|
685
|
138
|
|
139 *:tabl* *:tablast*
|
|
140 :tabl[ast] Go to the last tab page.
|
|
141
|
682
|
142
|
674
|
143 Other commands:
|
|
144 *:tabs*
|
682
|
145 :tabs List the tab pages and the windows they contain.
|
|
146 Shows a ">" for the current window.
|
|
147 Shows a "+" for modified buffers.
|
|
148
|
|
149
|
|
150 REORDERING TAB PAGES:
|
|
151
|
|
152 *:tabm* *:tabmove*
|
|
153 :tabmove N Move the current tab page to after tab page N. Use zero to
|
|
154 make the current tab page the first one. Without N the tab
|
|
155 page is made the last one.
|
674
|
156
|
685
|
157
|
|
158 LOOPING OVER TAB PAGES:
|
|
159
|
|
160 *:tabd* *:tabdo*
|
|
161 :tabd[o] {cmd} Execute {cmd} in each tab page.
|
|
162 It works like doing this: >
|
|
163 :tabfirst
|
|
164 :{cmd}
|
|
165 :tabnext
|
|
166 :{cmd}
|
|
167 etc.
|
|
168 < This only operates in the current window of each tab page.
|
|
169 When an error is detected on one tab page, further tab pages
|
|
170 will not be visited.
|
|
171 The last tab page (or where an error occurred) becomes the
|
|
172 current tab page.
|
|
173 {cmd} can contain '|' to concatenate several commands.
|
|
174 {cmd} must not open or close tab pages or reorder them.
|
|
175 {not in Vi} {not available when compiled without the
|
|
176 |+listcmds| feature}
|
|
177 Also see |:windo|, |:argdo| and |:bufdo|.
|
|
178
|
674
|
179 ==============================================================================
|
|
180 3. Other items *tab-page-other*
|
|
181
|
|
182 Diff mode works per tab page. You can see the diffs between several files
|
|
183 within one tab page. Other tab pages can show differences between other
|
|
184 files.
|
|
185
|
675
|
186 The TabLeave and TabEnter autocommand events can be used to do something when
|
|
187 switching from one tab page to another. The exact order depends on what you
|
|
188 are doing. When creating a new tab page this works as if you create a new
|
|
189 window on the same buffer and then edit another buffer. Thus ":tabnew"
|
|
190 triggers:
|
|
191 WinLeave leave current window
|
|
192 TabLeave leave current tab page
|
|
193 TabEnter enter new tab page
|
|
194 WinEnter enter window in new tab page
|
|
195 BufLeave leave current buffer
|
|
196 BufEnter enter new empty buffer
|
|
197
|
678
|
198 When switching to another tab page the order is:
|
675
|
199 BufLeave
|
|
200 WinLeave
|
|
201 TabLeave
|
|
202 TabEnter
|
|
203 WinEnter
|
|
204 BufEnter
|
674
|
205
|
678
|
206 ==============================================================================
|
|
207 4. Setting 'tabline' *setting-tabline*
|
|
208
|
686
|
209 The 'tabline' option specifies what the line with tab pages labels looks like.
|
|
210 It is only used when there is no GUI tab line.
|
|
211
|
678
|
212 You can use the 'showtabline' option to specify when you want the line with
|
|
213 tab page labels to appear: never, when there is more than one tab page or
|
|
214 always.
|
|
215
|
|
216 The highlighting of the tab pages line is set with the groups TabLine
|
|
217 TabLineSel and TabLineFill. |hl-TabLine| |hl-TabLineSel| |hl-TabLineFill|
|
|
218
|
|
219 The 'tabline' option allows you to define your preferred way to tab pages
|
|
220 labels. This isn't easy, thus an example will be given here.
|
|
221
|
|
222 For basics see the 'statusline' option. The same items can be used in the
|
|
223 'tabline' option. Additionally, the |tabpagebuflist()|, |tabpagenr()| and
|
|
224 |tabpagewinnr()| functions are useful.
|
|
225
|
|
226 Since the number of tab labels will vary, you need to use an expresion for the
|
|
227 whole option. Something like: >
|
|
228 :set tabline=%!MyTabLine()
|
|
229
|
|
230 Then define the MyTabLine() function to list all the tab pages labels. A
|
|
231 convenient method is to split it in two parts: First go over all the tab
|
|
232 pages and define labels for them. Then get the label for each tab page. >
|
|
233
|
|
234 function MyTabLine()
|
|
235 let s = ''
|
|
236 for i in range(tabpagenr('$'))
|
681
|
237 " select the highlighting
|
678
|
238 if i + 1 == tabpagenr()
|
|
239 let s .= '%#TabLineSel#'
|
|
240 else
|
|
241 let s .= '%#TabLine#'
|
|
242 endif
|
681
|
243
|
|
244 " set the tab page number (for mouse clicks)
|
|
245 let s .= '%' . (i + 1) . 'T'
|
|
246
|
|
247 " the label is made by MyTabLabel()
|
678
|
248 let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
|
|
249 endfor
|
681
|
250
|
|
251 " after the last tab fill with TabLineFill and reset tab page nr
|
|
252 let s .= '%#TabLineFill#%T'
|
|
253
|
|
254 " right-align the label to close the current tab page
|
|
255 if tabpagenr('$') > 1
|
|
256 let s .= '%=%#TabLine#%999Xclose'
|
|
257 endif
|
|
258
|
678
|
259 return s
|
|
260 endfunction
|
|
261
|
|
262 Now the MyTabLabel() function is called for each tab page to get its label. >
|
|
263
|
|
264 function MyTabLabel(n)
|
|
265 let buflist = tabpagebuflist(a:n)
|
|
266 let winnr = tabpagewinnr(a:n)
|
|
267 return bufname(buflist[winnr - 1])
|
|
268 endfunction
|
|
269
|
|
270 This is just a simplistic example that results in a tab pages line that
|
|
271 resembles the default, but without adding a + for a modified buffer or
|
|
272 trunctating the names. You will want to reduce the width of labels in a
|
|
273 clever way when there is not enough room. Check the 'columns' option for the
|
681
|
274 space available.
|
674
|
275
|
686
|
276 ==============================================================================
|
|
277 5. Setting 'guitablabel' *setting-guitablabel*
|
|
278
|
|
279 When the GUI tab pages line is displayed, 'guitablabel' can be used to
|
|
280 specify the label to display for each tab page. Unlike 'tabline', which
|
|
281 specifies the whole tab pages line at once, 'guitablabel' is used for each
|
|
282 label separately.
|
|
283
|
|
284 See the 'statusline' option for the format of the value.
|
|
285
|
|
286 The "%N" item can be used for the current tab page number. The |v:lnum|
|
690
|
287 variable is also set to this number when 'guitablabel' is evaluated.
|
|
288 The items that use a file name refer to the current window of the tab page.
|
686
|
289
|
|
290 Note that syntax highlighting is not used for 'guitablabel'. The %T and %X
|
690
|
291 items are also ignored.
|
686
|
292
|
690
|
293 A simple example that puts the tab page number and the buffer name in the
|
|
294 label: >
|
686
|
295 :set guitablabel=%N\ %f
|
|
296
|
|
297 An example that resembles the default: Show the number of windows in the tab
|
|
298 page and a '+' if there is a modifed buffer: >
|
|
299
|
690
|
300 function GuiTabLabel()
|
686
|
301 let label = ''
|
|
302 let bufnrlist = tabpagebuflist(v:lnum)
|
|
303
|
|
304 " Add '+' if one of the buffers in the tab page is modified
|
|
305 for bufnr in bufnrlist
|
|
306 if getbufvar(bufnr, "&modified")
|
|
307 let label = '+'
|
|
308 break
|
|
309 endif
|
|
310 endfor
|
|
311
|
|
312 " Append the number of windows in the tab page if more than one
|
|
313 let wincount = tabpagewinnr(v:lnum, '$')
|
|
314 if wincount > 1
|
|
315 let label .= wincount
|
|
316 endif
|
|
317 if label != ''
|
|
318 let label .= ' '
|
|
319 endif
|
|
320
|
|
321 " Append the buffer name
|
|
322 return label . bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
|
|
323 endfunction
|
690
|
324
|
686
|
325 set guitablabel=%{GuiTabLabel()}
|
690
|
326
|
|
327 Note that the function must be defined before setting the option, otherwise
|
|
328 you get an error message for the function not being known.
|
|
329
|
686
|
330
|
674
|
331 vim:tw=78:ts=8:ft=help:norl:
|