blob: 7469869d8098623df9a360745cd4423d509eb8cf [file] [log] [blame]
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001*tabpage.txt* For Vim version 7.0aa. Last change: 2006 Feb 24
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 Moolenaar7e8fd632006-02-18 22:14:51 +000017
18{Vi does not have any of these commands}
19{not able to use multiple tab pages when the |+windows| feature was disabled
20at compile time}
21
22==============================================================================
231. Introduction *tab-page-intro*
24
25A tab page holds one or more windows. You can easily switch between tab
26pages, so that you have several collections of windows to work on different
27things.
28
29Usually you will see a list of labels at the top of the Vim window, one for
30each tab page. With the mouse you can click on the label to jump to that tab
31page. There are other ways to move between tab pages, see below.
32
33Most commands work only in the current tab page. That includes the |CTRL-W|
34commands, |:windo|, |:all| and |:ball|. The commands that are aware of
35other tab pages than the current one are mentioned below.
36
37Tabs are also a nice way to edit a buffer temporarily without changing the
38current window layout. Open a new tab page, do whatever you want to do and
39close the tab page.
40
41==============================================================================
422. Commands *tab-page-commands*
43
44OPENING A NEW TAB PAGE:
45
46When starting Vim "vim -p filename ..." opens each file argument in a separate
47tab page (up to 10). |-p|
48
Bram Moolenaar80a94a52006-02-23 21:26:58 +000049A double click with the mouse in the tab pages line opens a new, empty tab
50page. It is placed left of the position of the click. The first click may
51select another tab page first, causing an extra screen update.
52
53:tabe[dit] *:tabe* *:tabedit* *:tabnew*
54:tabnew Open a new tab page with an empty window, after the current
55 tab page.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000056
57:tabe[dit] [++opt] [+cmd] {file}
Bram Moolenaar80a94a52006-02-23 21:26:58 +000058:tabnew [++opt] [+cmd] {file}
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000059 Open a new tab page and edit {file}, like with |:edit|.
60
Bram Moolenaar2a0449d2006-02-20 21:27:21 +000061:tabf[ind] [++opt] [+cmd] {file} *:tabf* *:tabfind*
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000062 Open a new tab page and edit {file} in 'path', like with
63 |:find|.
64 {not available when the |+file_in_path| feature was disabled
65 at compile time}
66
Bram Moolenaar80a94a52006-02-23 21:26:58 +000067:[count]tab {cmd} *:tab*
68 Execute {cmd} and when it opens a new window open a new tab
69 page instead. Doesn't work for |:diffsplit| or |:diffpatch|.
70 When [count] is omitted the tab page appears after the current
71 one. When [count] is specified the new tab page comes after
72 tab page [count]. Use ":0tab cmd" to get the new tab page as
73 the first one. Examples: >
74 :tab split " opens current buffer in new tab page
75 :tab help gt " opens tab page with help for "gt"
76
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000077
78CLOSING A TAB PAGE:
79
Bram Moolenaar80a94a52006-02-23 21:26:58 +000080Closing the last window of a tab page closes the tab page too, unless there is
81only one tab page.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000082
83Using the mouse: If the tab page line is displayed you can click in the "X" at
Bram Moolenaar80a94a52006-02-23 21:26:58 +000084the top right to close the current tab page. A custom |'tabline'| may show
85something else.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +000086
87 *:tabc* *:tabclose*
88:tabc[lose][!] Close current tab page.
89 This command fails when:
90 - There is only one tab page on the screen. *E784*
91 - When 'hidden' is not set, [!] is not used, a buffer has
92 changes, and there is no other window on this buffer.
93 Changes to the buffer are not written and won't get lost, so
94 this is a "safe" command.
95
96:tabc[lose][!] {count}
97 Close tab page {count}. Fails in the same way as ':tabclose"
98 above.
99
100 *:tabo* *:tabonly*
101:tabo[nly][!] Close all other tab pages.
102 When the 'hidden' option is set, all buffers in closed windows
103 become hidden.
104 When 'hidden' is not set, and the 'autowrite' option is set,
105 modified buffers are written. Otherwise, windows that have
106 buffers that are modified are not removed, unless the [!] is
107 given, then they become hidden. But modified buffers are
108 never abandoned, so changes cannot get lost.
109
110
111SWITCHING TO ANOTHER TAB PAGE:
112
113Using the mouse: If the tab page line is displayed you can click in a tab page
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000114label to switch to that tab page. Click where there is no label to go to the
115next tab page. |'tabline'|
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000116
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000117:tabn[ext] *:tabn* *:tabnext* *gt*
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000118gt Go to the next tab page. Wraps around from the last to the
119 first one.
120
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000121:tabn[ext] {count}
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000122{count}gt Go to tab page {count}. The first tab page has number one.
123
124
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000125:tabp[revious] *:tabp* *:tabprevious* *gT*
126:tabN[ext] *:tabN* *:tabNext*
127gT Go to the previous tab page. Wraps around from the first one
128 to the last one.
129
130:tabp[revious] {count}
131:tabN[ext] {count}
132{count}gT Go {count} tab pages back. Wraps around from the first one
133 to the last one.
134
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000135:tabr[ewind] *:tabfir* *:tabfirst* *:tabr* *:tabrewind*
136:tabl[ast] Go to the first tab page.
137
138 *:tabl* *:tablast*
139:tabl[ast] Go to the last tab page.
140
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000141
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000142Other commands:
143 *:tabs*
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000144:tabs List the tab pages and the windows they contain.
145 Shows a ">" for the current window.
146 Shows a "+" for modified buffers.
147
148
149REORDERING TAB PAGES:
150
151 *:tabm* *:tabmove*
152:tabmove N Move the current tab page to after tab page N. Use zero to
153 make the current tab page the first one. Without N the tab
154 page is made the last one.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000155
Bram Moolenaar32466aa2006-02-24 23:53:04 +0000156
157LOOPING OVER TAB PAGES:
158
159 *:tabd* *:tabdo*
160:tabd[o] {cmd} Execute {cmd} in each tab page.
161 It works like doing this: >
162 :tabfirst
163 :{cmd}
164 :tabnext
165 :{cmd}
166 etc.
167< This only operates in the current window of each tab page.
168 When an error is detected on one tab page, further tab pages
169 will not be visited.
170 The last tab page (or where an error occurred) becomes the
171 current tab page.
172 {cmd} can contain '|' to concatenate several commands.
173 {cmd} must not open or close tab pages or reorder them.
174 {not in Vi} {not available when compiled without the
175 |+listcmds| feature}
176 Also see |:windo|, |:argdo| and |:bufdo|.
177
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000178==============================================================================
1793. Other items *tab-page-other*
180
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000181Diff mode works per tab page. You can see the diffs between several files
182within one tab page. Other tab pages can show differences between other
183files.
184
Bram Moolenaar2a0449d2006-02-20 21:27:21 +0000185The TabLeave and TabEnter autocommand events can be used to do something when
186switching from one tab page to another. The exact order depends on what you
187are doing. When creating a new tab page this works as if you create a new
188window on the same buffer and then edit another buffer. Thus ":tabnew"
189triggers:
190 WinLeave leave current window
191 TabLeave leave current tab page
192 TabEnter enter new tab page
193 WinEnter enter window in new tab page
194 BufLeave leave current buffer
195 BufEnter enter new empty buffer
196
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000197When switching to another tab page the order is:
Bram Moolenaar2a0449d2006-02-20 21:27:21 +0000198 BufLeave
199 WinLeave
200 TabLeave
201 TabEnter
202 WinEnter
203 BufEnter
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000204
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000205==============================================================================
2064. Setting 'tabline' *setting-tabline*
207
208You can use the 'showtabline' option to specify when you want the line with
209tab page labels to appear: never, when there is more than one tab page or
210always.
211
212The highlighting of the tab pages line is set with the groups TabLine
213TabLineSel and TabLineFill. |hl-TabLine| |hl-TabLineSel| |hl-TabLineFill|
214
215The 'tabline' option allows you to define your preferred way to tab pages
216labels. This isn't easy, thus an example will be given here.
217
218For basics see the 'statusline' option. The same items can be used in the
219'tabline' option. Additionally, the |tabpagebuflist()|, |tabpagenr()| and
220|tabpagewinnr()| functions are useful.
221
222Since the number of tab labels will vary, you need to use an expresion for the
223whole option. Something like: >
224 :set tabline=%!MyTabLine()
225
226Then define the MyTabLine() function to list all the tab pages labels. A
227convenient method is to split it in two parts: First go over all the tab
228pages and define labels for them. Then get the label for each tab page. >
229
230 function MyTabLine()
231 let s = ''
232 for i in range(tabpagenr('$'))
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000233 " select the highlighting
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000234 if i + 1 == tabpagenr()
235 let s .= '%#TabLineSel#'
236 else
237 let s .= '%#TabLine#'
238 endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000239
240 " set the tab page number (for mouse clicks)
241 let s .= '%' . (i + 1) . 'T'
242
243 " the label is made by MyTabLabel()
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000244 let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
245 endfor
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000246
247 " after the last tab fill with TabLineFill and reset tab page nr
248 let s .= '%#TabLineFill#%T'
249
250 " right-align the label to close the current tab page
251 if tabpagenr('$') > 1
252 let s .= '%=%#TabLine#%999Xclose'
253 endif
254
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000255 return s
256 endfunction
257
258Now the MyTabLabel() function is called for each tab page to get its label. >
259
260 function MyTabLabel(n)
261 let buflist = tabpagebuflist(a:n)
262 let winnr = tabpagewinnr(a:n)
263 return bufname(buflist[winnr - 1])
264 endfunction
265
266This is just a simplistic example that results in a tab pages line that
267resembles the default, but without adding a + for a modified buffer or
268trunctating the names. You will want to reduce the width of labels in a
269clever way when there is not enough room. Check the 'columns' option for the
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000270space available.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000271
272 vim:tw=78:ts=8:ft=help:norl: