Vim Tips Wiki
(add notes on fixing the tab page tips)
Line 1: Line 1:
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=1347
 
|id=1347
Line 12: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
  +
This tip will be an introduction to using tab pages in Vim.
  +
  +
==Key mappings==
 
Add the following lines to your vimrc:
 
Add the following lines to your vimrc:
 
<pre>
 
<pre>
Line 46: Line 48:
 
</pre>
 
</pre>
   
  +
==Fixing tips on tab pages==
==Comments==
 
  +
:''This section is a temporary area to plan merging/fixing existing tips on tab pages.''
 
{{Todo}}
 
{{Todo}}
 
*No point having a tip change the default keybindings for <tt>:tabn</tt> and <tt>:tabp</tt>. Explain the defaults.
 
*No point having a tip change the default keybindings for <tt>:tabn</tt> and <tt>:tabp</tt>. Explain the defaults.
Line 52: Line 55:
 
*Perhaps rename to "Using tab pages" (a simpler title that attempts to avoid confusion with the tab key).
 
*Perhaps rename to "Using tab pages" (a simpler title that attempts to avoid confusion with the tab key).
   
  +
Relevant tips:
----
 
  +
*[[VimTip133|133 Windo and Bufdo]] tabdo and keep current tab
  +
*[[VimTip1233|1233 Move the current tabpage forward or backward]] move current tab page
  +
*[[VimTip1247|1247 Tabclose instead of quit-all]] something about closing tab pages
  +
*[[VimTip1295|1295 Select tab page with a key]] map keys to go to a tab page
  +
*[[VimTip1317|1317 Open every buffer in its own tabpage]] open each buffer in a tab page
  +
*[[VimTip1333|1333 Have focus on left tab after tabclose]] close tab and focus on previous tab
  +
*1347 Quick tab navigation and opening ''(this tip)''
  +
*[[VimTip1554|1554 Move current window between tabs]] move current window between tabs
  +
 
==Comments==
 
Does not work in [ax]term.
 
Does not work in [ax]term.
   

Revision as of 09:42, 28 November 2009

Tip 1347 Printable Monobook Previous Next

created September 29, 2006 · complexity basic · author mchenryk · version 7.0


This tip will be an introduction to using tab pages in Vim.

Key mappings

Add the following lines to your vimrc:

map <C-t> :tabnew<CR>
map <C-left> :tabp<CR>
map<C-right> :tabn<CR>

Then in gvim you have the following commands:

  • Ctrl-t – open a new tab
  • Ctrl-left arrow – move one tab to the left
  • Ctrl-right arrow – move one tab to the right

Basic Navigation

:tabs         list all tabs
:tabm 0       move the current tab first
:tabm {i}     move the current tab to the i+1 position
:tabn         move to (view) the next tab
:tabp         move to (view) the previous tab
:tabfirst     move to the first tab
:tabf {file}  open a new tab with the filename given, searching the 'path' to find it
:tabc         close the current tab
:tabc {i}     close the i-th tab
:tabo         close other tabs

For basic tab navigation, it is probably more convenient to use the built-in normal-mode commands:

gt            move to (view) the next tab
gT            move to (view) the previous tab
{i}gt         move to (view) the tab in the i-th position

Fixing tips on tab pages

This section is a temporary area to plan merging/fixing existing tips on tab pages.

 TO DO 

  • No point having a tip change the default keybindings for :tabn and :tabp. Explain the defaults.
  • Merge in any useful comments from below.
  • Perhaps rename to "Using tab pages" (a simpler title that attempts to avoid confusion with the tab key).

Relevant tips:

Comments

Does not work in [ax]term.


Or you could use gt and gT without having to move your hands across the keyboard. Also, gt can take the tab number to jump directly to a tab.


I use Vim in Windows, so remapping C-Left isn't great for me. These are the mappings I use:

" Tab mappings
map <S-Up> :tabclose<CR>
map <S-Down> :tabnew<CR>
map <S-Left> gT
map <S-Right> gt
map <S-PageUp> :tabfirst<CR>
map <S-PageDown> :tablast<CR>

I used down for a new tab because I'm used to that from Opera's mouse gestures.


I prefer gt and gT. In any case <C-PgUp> and <C-PgDn> are the defaults for the same operations.

Just opening a new tab is kind of useless. I find :tabe <filename> more useful.


Instead of :tabe filename, I like :tabf filename, because it walks the path to find the name, instead of relying on an required explicit path/filename.


If you are working with tags or cscope, <Ctrl-T> is for popping the stack.


I think this can be condensed to:

:tab sp<CR>

Alternative way to move current window to a new tab is: <Ctrl-w> T (capital).

Possibly useful information from tip 1313 (now removed)

:tabo         " only this tab (close other tabs)
:tab ball     " show each buffer in a tab

" Set tab label to show buffer number, filename, if modified.
:set guitablabel=%n/\ %t\ %M

When starting Vim, the -p option opens each file in a tab, for example:

gvim -p *.txt

From comment in tip 259 (now removed)

Press F8 to show all buffers in tabs, or to close all tabs (toggle).

let g:toggleTabs = 0
nnoremap <silent> <F8> :if g:toggleTabs<Bar>:tabo<Bar>:let g:toggleTabs = 0<Bar>:else<Bar>:tab ball<Bar>:let g:toggleTabs = 1<Bar>:endif<CR>

Whereas it's definitely useful to have a tip covering tab pages, I'd like to see a disclaimer explaining what tab pages are not, i.e. the same as tabs in a tabbed editor like Eclipse or Visual Studio. This (admittedly rather bold) text is what #vim uses to help "misguided" users realize what tab pages are not:

Tabs are not buffers, don't try to force them to act like buffers. Consider tabs like viewports, layouts or workspaces. Tabs is a terrible name. Trying to setup 1 tab == 1 buffer is an exercise in futility. Do :set hidden and get started. Get FuzzyFinder, LustyExplorer or BufExplorer to make getting around your buffers easier.

We also recommend that new users read godlygeek's introduction to buffers, windows and tab pages. That we have created these quick responses might give you a clue as to how many questions we get concerning the 1 tab == 1 buffer setup. :) (Spiiph 22:32, 8 August 2009 (UTC))

There is a small disclaimer in Category:Tabs. Feel free to make the wording stronger if you feel it needs it. --Fritzophrenic 00:28, 9 August 2009 (UTC)
Ah, that's fine. I didn't find it before, but maybe that's because I wasn't really looking. I wonder how many will find it there though. (Spiiph 11:09, 9 August 2009 (UTC))