blob: 85fc1d7d0245b6f418c8a0e12a3abf976a5b8f6b [file] [log] [blame]
Bram Moolenaarba6c0522006-02-25 21:45:02 +00001*tabpage.txt* For Vim version 7.0aa. Last change: 2006 Feb 25
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|
35commands, |:windo|, |:all| and |:ball|. The commands that are aware of
36other tab pages than the current one are mentioned below.
37
38Tabs are also a nice way to edit a buffer temporarily without changing the
39current window layout. Open a new tab page, do whatever you want to do and
40close the tab page.
41
42==============================================================================
432. Commands *tab-page-commands*
44
45OPENING A NEW TAB PAGE:
46
47When starting Vim "vim -p filename ..." opens each file argument in a separate
48tab page (up to 10). |-p|
49
Bram Moolenaar80a94a52006-02-23 21:26:58 +000050A double click with the mouse in the tab pages line opens a new, empty tab
51page. It is placed left of the position of the click. The first click may
52select 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.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000057
58:tabe[dit] [++opt] [+cmd] {file}
Bram Moolenaar80a94a52006-02-23 21:26:58 +000059:tabnew [++opt] [+cmd] {file}
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000060 Open a new tab page and edit {file}, like with |:edit|.
61
Bram Moolenaar2a0449d2006-02-20 21:27:21 +000062:tabf[ind] [++opt] [+cmd] {file} *:tabf* *:tabfind*
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000063 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
Bram Moolenaar80a94a52006-02-23 21:26:58 +000068:[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
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000078
79CLOSING A TAB PAGE:
80
Bram Moolenaar80a94a52006-02-23 21:26:58 +000081Closing the last window of a tab page closes the tab page too, unless there is
82only one tab page.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000083
84Using the mouse: If the tab page line is displayed you can click in the "X" at
Bram Moolenaar80a94a52006-02-23 21:26:58 +000085the top right to close the current tab page. A custom |'tabline'| may show
86something else.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000087
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
112SWITCHING TO ANOTHER TAB PAGE:
113
114Using the mouse: If the tab page line is displayed you can click in a tab page
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000115label to switch to that tab page. Click where there is no label to go to the
116next tab page. |'tabline'|
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000117
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000118:tabn[ext] *:tabn* *:tabnext* *gt*
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000119gt Go to the next tab page. Wraps around from the last to the
120 first one.
121
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000122:tabn[ext] {count}
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000123{count}gt Go to tab page {count}. The first tab page has number one.
124
125
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000126:tabp[revious] *:tabp* *:tabprevious* *gT*
127:tabN[ext] *:tabN* *:tabNext*
128gT 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
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000136:tabr[ewind] *:tabfir* *:tabfirst* *:tabr* *:tabrewind*
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000137:tabfir[st] Go to the first tab page.
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000138
139 *:tabl* *:tablast*
140:tabl[ast] Go to the last tab page.
141
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000142
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000143Other commands:
144 *:tabs*
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000145: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
150REORDERING 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.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000156
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000157
158LOOPING 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
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000179==============================================================================
1803. Other items *tab-page-other*
181
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000182Diff mode works per tab page. You can see the diffs between several files
183within one tab page. Other tab pages can show differences between other
184files.
185
Bram Moolenaar2a0449d2006-02-20 21:27:21 +0000186The TabLeave and TabEnter autocommand events can be used to do something when
187switching from one tab page to another. The exact order depends on what you
188are doing. When creating a new tab page this works as if you create a new
189window on the same buffer and then edit another buffer. Thus ":tabnew"
190triggers:
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
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000198When switching to another tab page the order is:
Bram Moolenaar2a0449d2006-02-20 21:27:21 +0000199 BufLeave
200 WinLeave
201 TabLeave
202 TabEnter
203 WinEnter
204 BufEnter
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000205
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000206==============================================================================
2074. Setting 'tabline' *setting-tabline*
208
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000209The 'tabline' option specifies what the line with tab pages labels looks like.
210It is only used when there is no GUI tab line.
211
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000212You can use the 'showtabline' option to specify when you want the line with
213tab page labels to appear: never, when there is more than one tab page or
214always.
215
216The highlighting of the tab pages line is set with the groups TabLine
217TabLineSel and TabLineFill. |hl-TabLine| |hl-TabLineSel| |hl-TabLineFill|
218
219The 'tabline' option allows you to define your preferred way to tab pages
220labels. This isn't easy, thus an example will be given here.
221
222For 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
226Since the number of tab labels will vary, you need to use an expresion for the
227whole option. Something like: >
228 :set tabline=%!MyTabLine()
229
230Then define the MyTabLine() function to list all the tab pages labels. A
231convenient method is to split it in two parts: First go over all the tab
232pages 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('$'))
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000237 " select the highlighting
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000238 if i + 1 == tabpagenr()
239 let s .= '%#TabLineSel#'
240 else
241 let s .= '%#TabLine#'
242 endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000243
244 " set the tab page number (for mouse clicks)
245 let s .= '%' . (i + 1) . 'T'
246
247 " the label is made by MyTabLabel()
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000248 let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
249 endfor
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000250
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
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000259 return s
260 endfunction
261
262Now 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
270This is just a simplistic example that results in a tab pages line that
271resembles the default, but without adding a + for a modified buffer or
272trunctating the names. You will want to reduce the width of labels in a
273clever way when there is not enough room. Check the 'columns' option for the
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000274space available.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000275
Bram Moolenaarba6c0522006-02-25 21:45:02 +0000276==============================================================================
2775. Setting 'guitablabel' *setting-guitablabel*
278
279When the GUI tab pages line is displayed, 'guitablabel' can be used to
280specify the label to display for each tab page. Unlike 'tabline', which
281specifies the whole tab pages line at once, 'guitablabel' is used for each
282label separately.
283
284See the 'statusline' option for the format of the value.
285
286The "%N" item can be used for the current tab page number. The |v:lnum|
287variable is also set to this number.
288
289Note that syntax highlighting is not used for 'guitablabel'. The %T and %X
290are also ignored.
291
292A simple example that puts the tab page number and the buffer name in the label: >
293
294 :set guitablabel=%N\ %f
295
296An example that resembles the default: Show the number of windows in the tab
297page and a '+' if there is a modifed buffer: >
298
299 function! GuiTabLabel()
300 let label = ''
301 let bufnrlist = tabpagebuflist(v:lnum)
302
303 " Add '+' if one of the buffers in the tab page is modified
304 for bufnr in bufnrlist
305 if getbufvar(bufnr, "&modified")
306 let label = '+'
307 break
308 endif
309 endfor
310
311 " Append the number of windows in the tab page if more than one
312 let wincount = tabpagewinnr(v:lnum, '$')
313 if wincount > 1
314 let label .= wincount
315 endif
316 if label != ''
317 let label .= ' '
318 endif
319
320 " Append the buffer name
321 return label . bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
322 endfunction
323 set guitablabel=%{GuiTabLabel()}
324<
325
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000326 vim:tw=78:ts=8:ft=help:norl: