blob: 5f394b398fde54f7fe2c9515f8c180a5ebdfd25e [file] [log] [blame]
Bram Moolenaar80a94a52006-02-23 21:26:58 +00001*tabpage.txt* For Vim version 7.0aa. Last change: 2006 Feb 23
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
135
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000136Other commands:
137 *:tabs*
Bram Moolenaar80a94a52006-02-23 21:26:58 +0000138:tabs List the tab pages and the windows they contain.
139 Shows a ">" for the current window.
140 Shows a "+" for modified buffers.
141
142
143REORDERING TAB PAGES:
144
145 *:tabm* *:tabmove*
146:tabmove N Move the current tab page to after tab page N. Use zero to
147 make the current tab page the first one. Without N the tab
148 page is made the last one.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000149
150==============================================================================
1513. Other items *tab-page-other*
152
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000153Diff mode works per tab page. You can see the diffs between several files
154within one tab page. Other tab pages can show differences between other
155files.
156
Bram Moolenaar2a0449d2006-02-20 21:27:21 +0000157The TabLeave and TabEnter autocommand events can be used to do something when
158switching from one tab page to another. The exact order depends on what you
159are doing. When creating a new tab page this works as if you create a new
160window on the same buffer and then edit another buffer. Thus ":tabnew"
161triggers:
162 WinLeave leave current window
163 TabLeave leave current tab page
164 TabEnter enter new tab page
165 WinEnter enter window in new tab page
166 BufLeave leave current buffer
167 BufEnter enter new empty buffer
168
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000169When switching to another tab page the order is:
Bram Moolenaar2a0449d2006-02-20 21:27:21 +0000170 BufLeave
171 WinLeave
172 TabLeave
173 TabEnter
174 WinEnter
175 BufEnter
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000176
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000177==============================================================================
1784. Setting 'tabline' *setting-tabline*
179
180You can use the 'showtabline' option to specify when you want the line with
181tab page labels to appear: never, when there is more than one tab page or
182always.
183
184The highlighting of the tab pages line is set with the groups TabLine
185TabLineSel and TabLineFill. |hl-TabLine| |hl-TabLineSel| |hl-TabLineFill|
186
187The 'tabline' option allows you to define your preferred way to tab pages
188labels. This isn't easy, thus an example will be given here.
189
190For basics see the 'statusline' option. The same items can be used in the
191'tabline' option. Additionally, the |tabpagebuflist()|, |tabpagenr()| and
192|tabpagewinnr()| functions are useful.
193
194Since the number of tab labels will vary, you need to use an expresion for the
195whole option. Something like: >
196 :set tabline=%!MyTabLine()
197
198Then define the MyTabLine() function to list all the tab pages labels. A
199convenient method is to split it in two parts: First go over all the tab
200pages and define labels for them. Then get the label for each tab page. >
201
202 function MyTabLine()
203 let s = ''
204 for i in range(tabpagenr('$'))
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000205 " select the highlighting
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000206 if i + 1 == tabpagenr()
207 let s .= '%#TabLineSel#'
208 else
209 let s .= '%#TabLine#'
210 endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000211
212 " set the tab page number (for mouse clicks)
213 let s .= '%' . (i + 1) . 'T'
214
215 " the label is made by MyTabLabel()
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000216 let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
217 endfor
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000218
219 " after the last tab fill with TabLineFill and reset tab page nr
220 let s .= '%#TabLineFill#%T'
221
222 " right-align the label to close the current tab page
223 if tabpagenr('$') > 1
224 let s .= '%=%#TabLine#%999Xclose'
225 endif
226
Bram Moolenaar030f0df2006-02-21 22:02:53 +0000227 return s
228 endfunction
229
230Now the MyTabLabel() function is called for each tab page to get its label. >
231
232 function MyTabLabel(n)
233 let buflist = tabpagebuflist(a:n)
234 let winnr = tabpagewinnr(a:n)
235 return bufname(buflist[winnr - 1])
236 endfunction
237
238This is just a simplistic example that results in a tab pages line that
239resembles the default, but without adding a + for a modified buffer or
240trunctating the names. You will want to reduce the width of labels in a
241clever way when there is not enough room. Check the 'columns' option for the
Bram Moolenaard1f56e62006-02-22 21:25:37 +0000242space available.
Bram Moolenaar7e8fd632006-02-18 22:14:51 +0000243
244 vim:tw=78:ts=8:ft=help:norl: