blob: 8b18b939f1532d9fd8b89ca6da0a671e8ab13abe [file] [log] [blame]
Bram Moolenaare1438bb2006-03-01 22:01:55 +00001*tabpage.txt* For Vim version 7.0aa. Last change: 2006 Mar 01
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
Bram Moolenaar2a0449d2006-02-20 21:27:21 +00007Editing with windows in multiple tab pages. *tab-page* *tabpage*
Bram Moolenaar7e8fd632006-02-18 22:14:51 +00008
9The commands which have been added to use multiple tab pages are explained
10here. Additionally, there are explanations for commands that work differently
11when used in combination with more than one tab page.
12
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000131. Introduction |tab-page-intro|
142. Commands |tab-page-commands|
153. Other items |tab-page-other|
164. Setting 'tabline' |setting-tabline|
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000175. Setting 'guitablabel' |setting-guitablabel|
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000018
19{Vi does not have any of these commands}
20{not able to use multiple tab pages when the |+windows| feature was disabled
21at compile time}
22
23==============================================================================
241. Introduction *tab-page-intro*
25
26A tab page holds one or more windows. You can easily switch between tab
27pages, so that you have several collections of windows to work on different
28things.
29
30Usually you will see a list of labels at the top of the Vim window, one for
31each tab page. With the mouse you can click on the label to jump to that tab
32page. There are other ways to move between tab pages, see below.
33
34Most commands work only in the current tab page. That includes the |CTRL-W|
Bram Moolenaare1438bb2006-03-01 22:01:55 +000035commands, |:windo|, |:all| and |:ball| (when not using the |:tab| modifier).
36The commands that are aware of other tab pages than the current one are
37mentioned below.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000038
39Tabs are also a nice way to edit a buffer temporarily without changing the
40current window layout. Open a new tab page, do whatever you want to do and
41close the tab page.
42
43==============================================================================
442. Commands *tab-page-commands*
45
46OPENING A NEW TAB PAGE:
47
48When starting Vim "vim -p filename ..." opens each file argument in a separate
Bram Moolenaare1438bb2006-03-01 22:01:55 +000049tab page (up to 'tabpagemax'). |-p|
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000050
Bram Moolenaar80a94a52006-02-23 21:26:58 +000051A double click with the mouse in the tab pages line opens a new, empty tab
52page. It is placed left of the position of the click. The first click may
53select 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.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000058
59:tabe[dit] [++opt] [+cmd] {file}
Bram Moolenaar80a94a52006-02-23 21:26:58 +000060:tabnew [++opt] [+cmd] {file}
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000061 Open a new tab page and edit {file}, like with |:edit|.
62
Bram Moolenaar2a0449d2006-02-20 21:27:21 +000063:tabf[ind] [++opt] [+cmd] {file} *:tabf* *:tabfind*
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000064 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
Bram Moolenaar80a94a52006-02-23 21:26:58 +000069:[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
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000079
80CLOSING A TAB PAGE:
81
Bram Moolenaar80a94a52006-02-23 21:26:58 +000082Closing the last window of a tab page closes the tab page too, unless there is
83only one tab page.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000084
85Using the mouse: If the tab page line is displayed you can click in the "X" at
Bram Moolenaar80a94a52006-02-23 21:26:58 +000086the top right to close the current tab page. A custom |'tabline'| may show
87something else.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000088
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
113SWITCHING TO ANOTHER TAB PAGE:
114
115Using the mouse: If the tab page line is displayed you can click in a tab page
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000116label to switch to that tab page. Click where there is no label to go to the
117next tab page. |'tabline'|
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000118
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000119:tabn[ext] *:tabn* *:tabnext* *gt*
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000120gt Go to the next tab page. Wraps around from the last to the
121 first one.
122
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000123:tabn[ext] {count}
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000124{count}gt Go to tab page {count}. The first tab page has number one.
125
126
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000127:tabp[revious] *:tabp* *:tabprevious* *gT*
128:tabN[ext] *:tabN* *:tabNext*
129gT 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
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000137:tabr[ewind] *:tabfir* *:tabfirst* *:tabr* *:tabrewind*
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000138:tabfir[st] Go to the first tab page.
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000139
140 *:tabl* *:tablast*
141:tabl[ast] Go to the last tab page.
142
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000143
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000144Other commands:
145 *:tabs*
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000146: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
151REORDERING 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.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000157
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000158
159LOOPING 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
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000180==============================================================================
1813. Other items *tab-page-other*
182
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000183Diff mode works per tab page. You can see the diffs between several files
184within one tab page. Other tab pages can show differences between other
185files.
186
Bram Moolenaar2a0449d2006-02-20 21:27:21 +0000187The TabLeave and TabEnter autocommand events can be used to do something when
188switching from one tab page to another. The exact order depends on what you
189are doing. When creating a new tab page this works as if you create a new
190window on the same buffer and then edit another buffer. Thus ":tabnew"
191triggers:
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
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000199When switching to another tab page the order is:
Bram Moolenaar2a0449d2006-02-20 21:27:21 +0000200 BufLeave
201 WinLeave
202 TabLeave
203 TabEnter
204 WinEnter
205 BufEnter
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000206
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000207==============================================================================
2084. Setting 'tabline' *setting-tabline*
209
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000210The 'tabline' option specifies what the line with tab pages labels looks like.
211It is only used when there is no GUI tab line.
212
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000213You can use the 'showtabline' option to specify when you want the line with
214tab page labels to appear: never, when there is more than one tab page or
215always.
216
217The highlighting of the tab pages line is set with the groups TabLine
218TabLineSel and TabLineFill. |hl-TabLine| |hl-TabLineSel| |hl-TabLineFill|
219
220The 'tabline' option allows you to define your preferred way to tab pages
221labels. This isn't easy, thus an example will be given here.
222
223For 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
227Since the number of tab labels will vary, you need to use an expresion for the
228whole option. Something like: >
229 :set tabline=%!MyTabLine()
230
231Then define the MyTabLine() function to list all the tab pages labels. A
232convenient method is to split it in two parts: First go over all the tab
233pages 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('$'))
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000238 " select the highlighting
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000239 if i + 1 == tabpagenr()
240 let s .= '%#TabLineSel#'
241 else
242 let s .= '%#TabLine#'
243 endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000244
245 " set the tab page number (for mouse clicks)
246 let s .= '%' . (i + 1) . 'T'
247
248 " the label is made by MyTabLabel()
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000249 let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
250 endfor
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000251
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
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000260 return s
261 endfunction
262
263Now 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
271This is just a simplistic example that results in a tab pages line that
272resembles the default, but without adding a + for a modified buffer or
273trunctating the names. You will want to reduce the width of labels in a
274clever way when there is not enough room. Check the 'columns' option for the
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000275space available.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000276
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000277==============================================================================
2785. Setting 'guitablabel' *setting-guitablabel*
279
280When the GUI tab pages line is displayed, 'guitablabel' can be used to
281specify the label to display for each tab page. Unlike 'tabline', which
282specifies the whole tab pages line at once, 'guitablabel' is used for each
283label separately.
284
285See the 'statusline' option for the format of the value.
286
287The "%N" item can be used for the current tab page number. The |v:lnum|
Bram Moolenaara226a6d2006-02-26 23:59:20 +0000288variable is also set to this number when 'guitablabel' is evaluated.
289The items that use a file name refer to the current window of the tab page.
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000290
291Note that syntax highlighting is not used for 'guitablabel'. The %T and %X
Bram Moolenaara226a6d2006-02-26 23:59:20 +0000292items are also ignored.
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000293
Bram Moolenaara226a6d2006-02-26 23:59:20 +0000294A simple example that puts the tab page number and the buffer name in the
295label: >
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000296 :set guitablabel=%N\ %f
297
298An example that resembles the default: Show the number of windows in the tab
299page and a '+' if there is a modifed buffer: >
300
Bram Moolenaara226a6d2006-02-26 23:59:20 +0000301 function GuiTabLabel()
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000302 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
Bram Moolenaara226a6d2006-02-26 23:59:20 +0000325
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000326 set guitablabel=%{GuiTabLabel()}
Bram Moolenaara226a6d2006-02-26 23:59:20 +0000327
328Note that the function must be defined before setting the option, otherwise
329you get an error message for the function not being known.
330
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000331
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000332 vim:tw=78:ts=8:ft=help:norl: