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