FANDOM


(rough merge in from 1313 by jul)
(clean merged in info from 1313)
Line 91: Line 91:
 
Alternative way to move current window to a new tab is: <Ctrl-w> T (capital).
 
Alternative way to move current window to a new tab is: <Ctrl-w> T (capital).
   
----
+
===Possibly useful information from tip 1313 (now removed)===
When you use <tt>:tab ball</tt> - it makes out of all buffers a tab.
 
 
----
 
==Rough merge in from tip 1313 (now removed)==
 
 
<pre>
 
<pre>
"show tabs/ hide tabs / naviguate through tabs
+
:tabo " only this tab (close other tabs)
"tab labels show the filename without path(tail)
+
:tab ball " show each buffer in a tab
:set guitablabel=%t
 
   
"variable
+
" Set tab label to show buffer number, filename, if modified.
:let g:toggleTabs = 0
+
:set guitablabel=%N/\ %t\ %M
 
"when pressing F3, open all buffer in tabs / close all tabs
 
map <silent><F3> :if g:toggleTabs == 1<CR>:tabo<CR>:set lines+=3<CR>:let g:toggleTabs = 0<CR>:else<CR>:set lines-=3<CR>:tab ball<CR>:let g:toggleTabs = 1<CR>:endif<CR>
 
 
" tab navigation (next tab or next buffer) (firefox style)
 
map <silent><C-tab> :if g:toggleTabs == 1<CR>:tabnext<CR>:else<CR>:bn<CR>:endif<CR>
 
map <silent><C-S-tab> :if g:toggleTabs == 1<CR>:tabprevious<CR>:else<CR>:bp<CR>:endif<CR>
 
 
"Show tabs by pressing alt down, hide tabs by pressing alt up
 
map <A-Up> :tabo<CR>:set lines+=3<CR>:let g:toggleTabs = 0<CR>
 
map <A-Down> :set lines-=3<CR>:tab ball<CR>:let g:toggleTabs = 1<CR>
 
 
" tab navigation (next tab or next buffer) with alt left / alt right
 
map <silent><A-Right> :if g:toggleTabs == 1<CR>:tabnext<CR>:else<CR>:bn<CR>:endif<CR>
 
map <silent><A-Left> :if g:toggleTabs == 1<CR>:tabprevious<CR>:else<CR>:bp<CR>:endif<CR>
 
 
</pre>
 
</pre>
   
;Comments
+
When starting Vim, the <tt>-p</tt> option opens each file in a tab, for example:
This is a little better for the tab label:
 
 
<pre>
 
<pre>
:set guitablabel=%N/\ %t\ %M
+
gvim -p *.txt
 
</pre>
 
</pre>
 
It will show the buffer number, the filename, and if the file as been modified.
 
 
----
 
Use the <tt>:tab ball</tt> command to display one tab per buffer.
 
 
Or start gvim with the <tt>-p</tt> option, for example: <tt>gvim -p *.txt</tt>
 
 
The +3 -3 in the tip is from [[VimTip259]] (pretty cool tip btw) but I am not sure it is useful.
 
 
----
 

Revision as of 08:04, July 2, 2009

Tip 1347 Printable Monobook Previous Next

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


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

Comments

 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).

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
Community content is available under CC-BY-SA unless otherwise noted.