Bram Moolenaar | ba6c052 | 2006-02-25 21:45:02 +0000 | [diff] [blame] | 1 | *tabpage.txt* For Vim version 7.0aa. Last change: 2006 Feb 25 |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2 | |
| 3 | |
| 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
| 5 | |
| 6 | |
Bram Moolenaar | 2a0449d | 2006-02-20 21:27:21 +0000 | [diff] [blame] | 7 | Editing with windows in multiple tab pages. *tab-page* *tabpage* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 030f0df | 2006-02-21 22:02:53 +0000 | [diff] [blame] | 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| |
Bram Moolenaar | ba6c052 | 2006-02-25 21:45:02 +0000 | [diff] [blame] | 17 | 5. Setting 'guitablabel' |setting-guitablabel| |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 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| |
| 35 | commands, |:windo|, |:all| and |:ball|. The commands that are aware of |
| 36 | other tab pages than the current one are mentioned below. |
| 37 | |
| 38 | Tabs are also a nice way to edit a buffer temporarily without changing the |
| 39 | current window layout. Open a new tab page, do whatever you want to do and |
| 40 | close the tab page. |
| 41 | |
| 42 | ============================================================================== |
| 43 | 2. Commands *tab-page-commands* |
| 44 | |
| 45 | OPENING A NEW TAB PAGE: |
| 46 | |
| 47 | When starting Vim "vim -p filename ..." opens each file argument in a separate |
| 48 | tab page (up to 10). |-p| |
| 49 | |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 50 | A double click with the mouse in the tab pages line opens a new, empty tab |
| 51 | page. It is placed left of the position of the click. The first click may |
| 52 | select 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 Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 57 | |
| 58 | :tabe[dit] [++opt] [+cmd] {file} |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 59 | :tabnew [++opt] [+cmd] {file} |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 60 | Open a new tab page and edit {file}, like with |:edit|. |
| 61 | |
Bram Moolenaar | 2a0449d | 2006-02-20 21:27:21 +0000 | [diff] [blame] | 62 | :tabf[ind] [++opt] [+cmd] {file} *:tabf* *:tabfind* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 63 | 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 Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 68 | :[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 Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 78 | |
| 79 | CLOSING A TAB PAGE: |
| 80 | |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 81 | Closing the last window of a tab page closes the tab page too, unless there is |
| 82 | only one tab page. |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 83 | |
| 84 | Using the mouse: If the tab page line is displayed you can click in the "X" at |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 85 | the top right to close the current tab page. A custom |'tabline'| may show |
| 86 | something else. |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 87 | |
| 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 | |
| 112 | SWITCHING TO ANOTHER TAB PAGE: |
| 113 | |
| 114 | Using the mouse: If the tab page line is displayed you can click in a tab page |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 115 | label to switch to that tab page. Click where there is no label to go to the |
| 116 | next tab page. |'tabline'| |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 117 | |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 118 | :tabn[ext] *:tabn* *:tabnext* *gt* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 119 | gt Go to the next tab page. Wraps around from the last to the |
| 120 | first one. |
| 121 | |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 122 | :tabn[ext] {count} |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 123 | {count}gt Go to tab page {count}. The first tab page has number one. |
| 124 | |
| 125 | |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 126 | :tabp[revious] *:tabp* *:tabprevious* *gT* |
| 127 | :tabN[ext] *:tabN* *:tabNext* |
| 128 | gT 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 Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 136 | :tabr[ewind] *:tabfir* *:tabfirst* *:tabr* *:tabrewind* |
Bram Moolenaar | ba6c052 | 2006-02-25 21:45:02 +0000 | [diff] [blame] | 137 | :tabfir[st] Go to the first tab page. |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 138 | |
| 139 | *:tabl* *:tablast* |
| 140 | :tabl[ast] Go to the last tab page. |
| 141 | |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 142 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 143 | Other commands: |
| 144 | *:tabs* |
Bram Moolenaar | 80a94a5 | 2006-02-23 21:26:58 +0000 | [diff] [blame] | 145 | :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 | |
| 150 | REORDERING 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 Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 156 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 157 | |
| 158 | LOOPING 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 Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 179 | ============================================================================== |
| 180 | 3. Other items *tab-page-other* |
| 181 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 182 | Diff mode works per tab page. You can see the diffs between several files |
| 183 | within one tab page. Other tab pages can show differences between other |
| 184 | files. |
| 185 | |
Bram Moolenaar | 2a0449d | 2006-02-20 21:27:21 +0000 | [diff] [blame] | 186 | The TabLeave and TabEnter autocommand events can be used to do something when |
| 187 | switching from one tab page to another. The exact order depends on what you |
| 188 | are doing. When creating a new tab page this works as if you create a new |
| 189 | window on the same buffer and then edit another buffer. Thus ":tabnew" |
| 190 | triggers: |
| 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 Moolenaar | 030f0df | 2006-02-21 22:02:53 +0000 | [diff] [blame] | 198 | When switching to another tab page the order is: |
Bram Moolenaar | 2a0449d | 2006-02-20 21:27:21 +0000 | [diff] [blame] | 199 | BufLeave |
| 200 | WinLeave |
| 201 | TabLeave |
| 202 | TabEnter |
| 203 | WinEnter |
| 204 | BufEnter |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 205 | |
Bram Moolenaar | 030f0df | 2006-02-21 22:02:53 +0000 | [diff] [blame] | 206 | ============================================================================== |
| 207 | 4. Setting 'tabline' *setting-tabline* |
| 208 | |
Bram Moolenaar | ba6c052 | 2006-02-25 21:45:02 +0000 | [diff] [blame] | 209 | The 'tabline' option specifies what the line with tab pages labels looks like. |
| 210 | It is only used when there is no GUI tab line. |
| 211 | |
Bram Moolenaar | 030f0df | 2006-02-21 22:02:53 +0000 | [diff] [blame] | 212 | You can use the 'showtabline' option to specify when you want the line with |
| 213 | tab page labels to appear: never, when there is more than one tab page or |
| 214 | always. |
| 215 | |
| 216 | The highlighting of the tab pages line is set with the groups TabLine |
| 217 | TabLineSel and TabLineFill. |hl-TabLine| |hl-TabLineSel| |hl-TabLineFill| |
| 218 | |
| 219 | The 'tabline' option allows you to define your preferred way to tab pages |
| 220 | labels. This isn't easy, thus an example will be given here. |
| 221 | |
| 222 | For 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 | |
| 226 | Since the number of tab labels will vary, you need to use an expresion for the |
| 227 | whole option. Something like: > |
| 228 | :set tabline=%!MyTabLine() |
| 229 | |
| 230 | Then define the MyTabLine() function to list all the tab pages labels. A |
| 231 | convenient method is to split it in two parts: First go over all the tab |
| 232 | pages 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 Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 237 | " select the highlighting |
Bram Moolenaar | 030f0df | 2006-02-21 22:02:53 +0000 | [diff] [blame] | 238 | if i + 1 == tabpagenr() |
| 239 | let s .= '%#TabLineSel#' |
| 240 | else |
| 241 | let s .= '%#TabLine#' |
| 242 | endif |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 243 | |
| 244 | " set the tab page number (for mouse clicks) |
| 245 | let s .= '%' . (i + 1) . 'T' |
| 246 | |
| 247 | " the label is made by MyTabLabel() |
Bram Moolenaar | 030f0df | 2006-02-21 22:02:53 +0000 | [diff] [blame] | 248 | let s .= ' %{MyTabLabel(' . (i + 1) . ')} ' |
| 249 | endfor |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 250 | |
| 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 Moolenaar | 030f0df | 2006-02-21 22:02:53 +0000 | [diff] [blame] | 259 | return s |
| 260 | endfunction |
| 261 | |
| 262 | Now 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 | |
| 270 | This is just a simplistic example that results in a tab pages line that |
| 271 | resembles the default, but without adding a + for a modified buffer or |
| 272 | trunctating the names. You will want to reduce the width of labels in a |
| 273 | clever way when there is not enough room. Check the 'columns' option for the |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 274 | space available. |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 275 | |
Bram Moolenaar | ba6c052 | 2006-02-25 21:45:02 +0000 | [diff] [blame] | 276 | ============================================================================== |
| 277 | 5. Setting 'guitablabel' *setting-guitablabel* |
| 278 | |
| 279 | When the GUI tab pages line is displayed, 'guitablabel' can be used to |
| 280 | specify the label to display for each tab page. Unlike 'tabline', which |
| 281 | specifies the whole tab pages line at once, 'guitablabel' is used for each |
| 282 | label separately. |
| 283 | |
| 284 | See the 'statusline' option for the format of the value. |
| 285 | |
| 286 | The "%N" item can be used for the current tab page number. The |v:lnum| |
| 287 | variable is also set to this number. |
| 288 | |
| 289 | Note that syntax highlighting is not used for 'guitablabel'. The %T and %X |
| 290 | are also ignored. |
| 291 | |
| 292 | A simple example that puts the tab page number and the buffer name in the label: > |
| 293 | |
| 294 | :set guitablabel=%N\ %f |
| 295 | |
| 296 | An example that resembles the default: Show the number of windows in the tab |
| 297 | page 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 Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 326 | vim:tw=78:ts=8:ft=help:norl: |