JohnBeckett (talk | contribs) (more tweaking) |
JohnBeckett (talk | contribs) (merge in 201002 from Read (but not write) file in new tab) |
||
Line 71: | Line 71: | ||
Jumping to a specific tab with <tt>{i}gt</tt> is easier if you set up your tabline to [[Show tab number in your tab line|show the tab number]]. |
Jumping to a specific tab with <tt>{i}gt</tt> is easier if you set up your tabline to [[Show tab number in your tab line|show the tab number]]. |
||
+ | |||
+ | ==Shortcuts== |
||
+ | Here are some ideas for entries you may want to add to your [[vimrc]]. |
||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
+ | The following command abbreviation allows typing <tt>:tabv myfile.txt</tt> to view the specified file in a new tab; the buffer is read-only and nomodifiable so you cannot accidentally change it. |
||
+ | <pre> |
||
+ | cabbrev tabv tabnew\|setlocal nomodifiable\|view |
||
+ | </pre> |
||
==Fixing tips on tab pages== |
==Fixing tips on tab pages== |
||
Line 100: | Line 114: | ||
==Comments== |
==Comments== |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | ---- |
Revision as of 08:18, 19 May 2010
This tip provides an introduction to opening, navigating, and working with tab pages. In Vim, each file is loaded into a buffer, which can be displayed in any number of windows, in any number of tabs. The easiest way to think about tab pages in Vim is to consider them to be viewports, layouts, or workspaces.
In many editors (not Vim), each file is opened in a new tab, and one tab can show only one file, and one file cannot appear in more than one tab. Vim's tab pages do not have these limitations, and tabs are a convenient way to organize your work. See Quick tips for using tab pages for examples of how tabs can be used to their full potential.
Trying to configure Vim to always have one file per tab will not be successful, and would remove much of the power of Vim. However, when you want to edit a file, it is easy to use :tabe instead of :e so that usually there is one file per tab. You can also launch files in new tabs under Windows and Unix.
An alternative to one file per tab is to learn to use the 'hidden' option combined with efficient use of the buffer list via a plugin such as FuzzyFinder, LustyExplorer or BufExplorer.
Opening and closing tabs
When starting Vim, the -p option opens each specified file in a separate tab (up to the value of the 'tabpagemax' option). Examples:
vim -p first.txt second.txt gvim -p *.txt
:tabe {file} edit specified file in a new tab :tabf {file} open a new tab with filename given, searching the 'path' to find it :tabc close current tab :tabc {i} close i-th tab :tabo show only this tab (close other tabs) :tab ball show each buffer in a tab
The :tabf command uses Vim's 'path' option to determine which directories should be searched when opening the specified file. For example, the following tells Vim to look in the directory containing the current file (.), then the current directory (empty text between two commas), then each directory under the current directory ('**').
:set path=.,,**
A command like :sp myfile.txt creates a new window in the current tab editing the specified file. That window can be moved to a new tab by pressing Ctrl-W T, and can be copied to a new tab with the command :tab sp (split the current window, but open the split in a new tab).
You can type Ctrl-W c to close the current window. If that window is the last window visible in a tab, the tab is also closed (if another tab page is currently open).
:tabs list all tabs including their displayed windows :tabm 0 move current tab to first :tabm move current tab to last :tabm {i} move current tab to position i+1 :tabn go to next tab :tabp go to previous tab :tabfirst go to first tab :tablast go to last tab
In normal mode, you can type:
gt go to next tab gT go to previous tab {i}gt go to tab in position i
In normal mode and in insert mode, you can type:
Ctrl-PgDn go to next tab Ctrl-PgUp go to previous tab
Jumping to a specific tab with {i}gt is easier if you set up your tabline to show the tab number.
Shortcuts
Here are some ideas for entries you may want to add to your vimrc.
With the following, you can press F8 to show all buffers in tabs, or to close all tabs (toggle: it alternately executes :tab ball and :tabo).
let notabs = 1 nnoremap <silent> <F8> :let notabs=!notabs<Bar>:if notabs<Bar>:tabo<Bar>:else<Bar>:tab ball<Bar>:tabn<Bar>:endif<CR>
The following command abbreviation allows typing :tabv myfile.txt to view the specified file in a new tab; the buffer is read-only and nomodifiable so you cannot accidentally change it.
cabbrev tabv tabnew\|setlocal nomodifiable\|view
Fixing tips on tab pages
- This section is a temporary area to plan merging/fixing existing tips on tab pages.
TO DO
- Perhaps merge in some information from tips listed below (or add as 'see also').
- Perhaps rename to "Using tab pages"?
- Relevant tips
- 95 Capture ex command output redirect output to a new tab
- 133 Windo and Bufdo tabdo and keep current tab
- 1221 Alternative tab navigation mappings to jump to a tab
- 1233 Move the current tabpage forward or backward move current tab page
- 1242 Move through the buffer list without wrecking your window/tab layout set switchbuf=usetab
- 1247 Tabclose instead of quit-all something about closing tab pages
- 1295 Select tab page with a key tab navigation mappings
- 1309 Safari style keybindings for tab navigation more tab navigation mappings
- 1317 Open every buffer in its own tabpage open each buffer in a tab page
- 1333 Have focus on left tab after tabclose close tab and focus on previous tab
- 1347 Quick tab navigation and opening (this tip)
- 1491 Call TortoiseSVN commands from within Vim
- 1554 Move current window between tabs move current window between tabs
- Open files in tabs
- 1225 Open files in multiple tabs using the Windows Context Menu
- 1314 Add open-in-tabs context menu for Windows
- 1440 Launch files in new tabs under Windows (mentioned in intro)
- 1552 Launch files in new tabs under Unix (mentioned in intro)