[Vi/Vim] Using tab pages

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
Once Vim has been launched, there are many commands that directly create or close tabs:
:tabedit {file}   edit specified file in a new tab
:tabfind {file}   open a new tab with filename given, searching the 'path' to find it
:tabclose         close current tab
:tabclose {i}     close i-th tab
:tabonly          close all other tabs (show only the current tab)
The :tabfind 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=.,,**
Remember, as with any Vim commands, you only need type enough characters in the command for Vim to be able to unambiguously identify it. For example, you could use :tabe and :tabf instead of :tabedit and :tabfind.
In addition to these commands, because Vim already has a plethora of commands for working with split windows, Vim provides the :tab command-line modifier, to use a new tab instead of a new window for commands that would normally split a window. For example:
:tab ball         show each buffer in a tab (up to 'tabpagemax' tabs)
:tab help         open a new help window in its own tab page
:tab drop {file}  open {file} in a new tab, or jump to a window/tab containing the file if there is one
:tab split        copy the current window to a new tab of its own
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).
If the file you are editing contains the name of another file, you can put the cursor on the name and type gf to edit the file (goto file). If you type Ctrl-W gf the file is displayed in a new tab.
In gvim, you can right click the tab label bar for a popup menu with Close, New Tab, and Open Tab... items.

Navigation.

: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
Note that the gt command counts from one. That means 3gt will jump to the third tab. Also note is 0gt and 1gt mean the same thing: jumping to the first tab.
Using recent vim versions, 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.

http://vim.wikia.com/wiki/Searching

댓글

이 블로그의 인기 게시물

[Linux, AIX] 사용자 계정 생성 및 설정

[AIX] rpm 설치와 rpm 으로 패키지 설치 및 삭제

Ubuntu 에서 Fortran 시작하기