Luc Hermitte (talk | contribs) m (Added to Tabs category + minor reformattings) |
JohnBeckett (talk | contribs) No edit summary Tag: sourceedit |
||
(14 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{TipImported |
||
− | {{review}} |
||
− | {{Tip |
||
|id=1221 |
|id=1221 |
||
+ | |previous=1220 |
||
− | |title=Alternative tab navigation |
||
+ | |next=1224 |
||
− | |created=May 8, 2006 5:59 |
||
+ | |created=2006 |
||
|complexity=basic |
|complexity=basic |
||
− | |author=Kim Schulz aka KimuSan |
+ | |author=Kim Schulz aka KimuSan |
− | |version= |
+ | |version=7.0 |
|rating=459/143 |
|rating=459/143 |
||
+ | |category1=Tabs |
||
− | |text= |
||
+ | |category2= |
||
− | Here is an alternative way to open and navigate tabs in vim7. |
||
− | |||
− | add the following to your .vimrc: |
||
− | <pre> |
||
− | " tab navigation like firefox |
||
− | :nmap <C-S-tab> :tabprevious<cr> |
||
− | :nmap <C-tab> :tabnext<cr> |
||
− | :map <C-S-tab> :tabprevious<cr> |
||
− | :map <C-tab> :tabnext<cr> |
||
− | :imap <C-S-tab> <ESC>:tabprevious<cr>i |
||
− | :imap <C-tab> <ESC>:tabnext<cr>i |
||
− | :nmap <C-t> :tabnew<cr> |
||
− | :imap <C-t> <ESC>:tabnew<cr> |
||
− | </pre> |
||
− | |||
− | bacically you can open a new tab with ctrl-t, go forward through the tabs with ctrl-tab and backwards with ctrl-shift-tab |
||
− | |||
− | This way of navigating resembles the way it is done in e.g., Mozilla Firefox. |
||
}} |
}} |
||
+ | Vim 7 introduced {{help|id=new-tab-pages|prefix=no|label=tab pages}} with functions to navigate to different tabs (see [[using tab pages]] or {{help|gt}} or {{help|:tab}}). You might however want to map some of those functions to separate keys. To do so, add the desired snippet to your vimrc. |
||
− | == Comments == |
||
− | i've had fun with the key binding just like yours. ^^ |
||
− | probably it'll be awfully convenient for users familiar with firefox. |
||
− | but please be careful, CTRL-T is "tag-pop shortcut key". |
||
− | to override or not to override, that is totally up to you! |
||
+ | Some of the mappings used here interfere with Vim's normal procedures. For example: |
||
− | elien122--AT--netian.com |
||
+ | * {{help|prefix=no|Ctrl-T}} is used for jumping to previous tags |
||
− | , May 8, 2006 7:42 |
||
+ | * Ctrl+W is used as a prefix for the {{help|id=CTRL-W|prefix=no|label=window commands}} |
||
− | ---- |
||
+ | * Ctrl+Tab is captured by KDE to switch workspaces. |
||
− | I ended up with: |
||
+ | Some mappings might not work in terminal versions of Vim (especially mappings, that use the Alt key or a combination of Ctrl and Shift). |
||
− | <pre> |
||
− | map th :tabnext<CR> |
||
− | map tl :tabprev<CR> |
||
− | map tn :tabnew<CR> |
||
− | map td :tabclose<CR> |
||
− | </pre> |
||
+ | ==Firefox like navigation== |
||
− | '''Anonymous''' |
||
− | , May 8, 2006 8:34 |
||
− | ---- |
||
− | <C-tab> don't work on Eterm, aterm, xterm :). |
||
− | |||
− | If I find resolution I post here. |
||
− | |||
− | chronos--AT--gentoobr.org |
||
− | , May 8, 2006 10:27 |
||
− | ---- |
||
<pre> |
<pre> |
||
+ | " Tab navigation like Firefox. |
||
− | :nmap <C-S-t> :tabnew<cr> |
||
+ | nnoremap <C-S-tab> :tabprevious<CR> |
||
− | :imap <C-S-t> <ESC>:tabnew<cr> |
||
+ | nnoremap <C-tab> :tabnext<CR> |
||
− | :imap <C-S-w> <ESC>:tabclose<cr> |
||
+ | nnoremap <C-t> :tabnew<CR> |
||
+ | inoremap <C-S-tab> <Esc>:tabprevious<CR>i |
||
+ | inoremap <C-tab> <Esc>:tabnext<CR>i |
||
+ | inoremap <C-t> <Esc>:tabnew<CR> |
||
</pre> |
</pre> |
||
− | And you'll get something like gnome-terminal tab-related key shortcuts |
||
+ | You can open a new tab with Ctrl-T, go forward through the tabs with Ctrl-Tab and backwards with Ctrl-Shift-Tab. You can also use Ctrl-PageDown and Ctrl-PageUp to cycle through tabs which works by default in gvim and Firefox. |
||
− | '''Anonymous''' |
||
− | , May 8, 2006 14:07 |
||
− | ---- |
||
− | Didn't exactly worked in windows' gVim. Had to put it into _gvimrc, like this: |
||
− | <pre> |
||
− | :map <C-S-tab> :tabprevious<cr> |
||
− | :map <C-tab> :tabnext<cr> |
||
− | :map <C-t> :tabnew<cr> |
||
− | </pre> |
||
− | alex--AT--onehalf.net |
||
− | , May 8, 2006 15:21 |
||
− | ---- |
||
− | Also, why not add Ctrl-w to close tabs? |
||
− | <pre> |
||
− | :map <C-w> :tabclose<cr> |
||
− | </pre> |
||
− | alex--AT--onehalf.net |
||
− | , May 8, 2006 18:05 |
||
− | ---- |
||
− | I just use the way that vim provides and it work well :) |
||
− | * gt for tabnext |
||
− | * gT for tabprevious |
||
− | |||
− | |||
− | linsong dot qizi AT gmail dot com |
||
− | , May 8, 2006 19:50 |
||
− | ---- |
||
− | Is there any way to map all the open buffers into tabs? |
||
− | i.e., |
||
− | I normally open multiple files at a time , they all go into buffers by default. |
||
− | Is there any way to send them into tabs in vim7? |
||
− | |||
− | -Ravi |
||
− | |||
− | ravi_jammula--AT--yahoo.com |
||
− | , May 9, 2006 3:06 |
||
− | ---- |
||
− | ravi, look at -p |
||
− | -p[N] Open N tab pages (default: one for each file) |
||
− | |||
− | '''Anonymous''' |
||
− | , May 9, 2006 6:07 |
||
− | ---- |
||
− | Great, so now how do I add that to the Windows shell when I right-click? |
||
− | |||
− | hopeseekr--AT--xmule.ws |
||
− | , May 9, 2006 10:40 |
||
− | ---- |
||
− | OMG how do i get my email address off this list??? I don't want the spambots to go crazy on me again :( |
||
− | |||
− | hopeseekr |
||
− | , May 9, 2006 10:41 |
||
− | ---- |
||
− | Great, so now how do I add that to the Windows shell when I right-click? |
||
− | Yes, who know?????????thanks |
||
− | |||
− | stoning--AT--gmail.com |
||
− | , May 10, 2006 0:24 |
||
− | ---- |
||
− | hopeseekr & stoning: I've added [[VimTip1225]] to explain how to update the Windows shell to support multiple tabs. |
||
− | |||
− | K Winter |
||
− | , May 10, 2006 3:24 |
||
− | ---- |
||
− | Great, This is exactly what i am looking for. |
||
− | Thanks |
||
− | Ravi |
||
+ | For opening and closing tabs, you can also add Ctrl-Insert and Ctrl-Delete mappings like this: |
||
− | ravi_jammula--AT--yahoo.com |
||
− | , May 10, 2006 11:45 |
||
− | ---- |
||
− | try |
||
<pre> |
<pre> |
||
+ | nnoremap <C-Insert> :tabnew<CR> |
||
− | :map <S-h> gT |
||
+ | nnoremap <C-Delete> :tabclose<CR> |
||
− | :map <S-l> gt |
||
</pre> |
</pre> |
||
+ | Note, that those keys are only mapped in normal mode, because in insert and visual mode they already have a function. |
||
− | that way you can hold down the shift key while you scroll left and right through the tabs with 'h' and 'l' |
||
+ | ==Vim navigation== |
||
− | samuel hughes |
||
− | , May 16, 2006 0:27 |
||
− | ---- |
||
− | " <C-tab> , <C-S-tab> don't work on Eterm, aterm, xterm " <br/> |
||
− | we can use <C-PageDown> and <C-PageUp> instead of <C-tab> and <C-S-tab> |
||
− | This's the default way in vim7. |
||
− | By the way, this also work on firefox. |
||
− | |||
− | |||
− | keepwatch--AT--gmail.com |
||
− | , May 18, 2006 9:33 |
||
− | ---- |
||
− | This tip is really good. But the key sequences used for switching/creating the tabs is clashing with other features of vim. for example: |
||
− | * CTRL+T is used for jumping to previous tags [exuberant ctags]. |
||
− | * CTRL+W is used for jumping to next split window in multiple windows |
||
− | *CTRL+TAB is captured by KDE itself to switch workspaces. |
||
− | Can you give a nice key combinations which will work with all these features ?. I know tabs is a new feature of vim7. But this script can become awsome if worked properly on. |
||
− | |||
− | msrinirao[at]gmail[dot]com |
||
− | , May 24, 2006 2:13 |
||
− | ---- |
||
− | vim7 already has <C-PageUp> and <C-PageDown> to cycle through tabs. To open and close them I added |
||
<pre> |
<pre> |
||
+ | nnoremap th :tabfirst<CR> |
||
− | nmap <C-Insert> :tabnew<CR> |
||
+ | nnoremap tj :tabnext<CR> |
||
− | nmap <C-Delete> :tabclose<CR> |
||
+ | nnoremap tk :tabprev<CR> |
||
+ | nnoremap tl :tablast<CR> |
||
+ | nnoremap tt :tabedit<Space> |
||
+ | nnoremap tn :tabnext<Space> |
||
+ | nnoremap tm :tabm<Space> |
||
+ | nnoremap td :tabclose<CR> |
||
+ | " Alternatively use |
||
+ | "nnoremap th :tabnext<CR> |
||
+ | "nnoremap tl :tabprev<CR> |
||
+ | "nnoremap tn :tabnew<CR> |
||
</pre> |
</pre> |
||
+ | Those mappings use the easily-reached '''t''' key in combination with the well known {{help|prefix=no|h}}{{help|prefix=no|j}}{{help|prefix=no|k}}{{help|prefix=no|l}} navigation keys in normal mode that move the cursor left, down, up or right. '''tj''' moves to the next tab, '''tk''' moves to the previous tabpage while '''th''' and '''tl''' move to the leftmost/rightmost tabpage. |
||
− | (not for insert or visual mode because they do something else then) |
||
+ | ==Gnome-terminal navigation== |
||
− | |||
+ | For something like gnome-terminal tab-related key shortcuts: |
||
− | szbeam at NOSPAM gmail com |
||
− | , June 21, 2006 7:51 |
||
− | ---- |
||
− | I'm having some marked trouble getting this to work on OSX Tiger. I've gotten <C-t> set to :tabnew just fine, but for some reason the <C-Tab> options aren't working. Any suggestions? |
||
− | |||
− | adam dot shamblin at gmail dot com |
||
− | , June 23, 2006 8:21 |
||
− | ---- |
||
− | I know that Z and X both perform functions in normal mode, but I never use them, so I just mapped: |
||
<pre> |
<pre> |
||
+ | :nnoremap <C-S-t> :tabnew<CR> |
||
− | :nmap Z :tabprev<cr> |
||
+ | :inoremap <C-S-t> <Esc>:tabnew<CR> |
||
− | :nmap X :tabnext<cr> |
||
+ | :inoremap <C-S-w> <Esc>:tabclose<CR> |
||
</pre> |
</pre> |
||
− | That way shift-z and shift-x takes me forward and backward. It's a lazy, ergonimic one hand solution. |
||
+ | ==Open files always in new tabs== |
||
− | zwelld, hosted on lawrence dot edu |
||
+ | If you like to open all command line arguments in a new tabpage, use this snippet (but remember, that the {{help|prefix=no|'tabpagemax'}} setting still applies). |
||
− | , June 24, 2006 23:26 |
||
− | ---- |
||
− | Does anyone know how to fix CTRL+] that jumps to tag under the cursor, so it opens file with tag but in new tab? |
||
− | By default, all files I jump to by find-a-tag opens in buffers but I'd like to get them on new tab too. |
||
− | Similarly to :tabedit |
||
− | |||
− | Thanks in advance |
||
− | |||
− | mateusz (at) loskot (dot) net |
||
− | , August 12, 2006 20:14 |
||
− | ---- |
||
− | mateusz, try this: |
||
<pre> |
<pre> |
||
+ | autocmd VimEnter * tab all |
||
− | map <C-W>] <C-W>]:tab split<CR>gT:q<CR>gt |
||
+ | autocmd BufAdd * exe 'tablast | tabe "' . expand( "<afile") .'"' |
||
</pre> |
</pre> |
||
+ | The second autocommand creates a new last tabpage for any buffer that is created (e.g. when using <tt>:e foobar</tt>, the current buffer will remain visible in the current tabpage and the file foobar will be opened in a new tabpage and Vim goes to that tabpage.) |
||
− | I have not found a way to do it that is already built into vim. If anyone does, please let me know. |
||
+ | ==Use <A-Fn> to go to the nth tabpage== |
||
− | |||
+ | You can use ngt to move to the nth tabpage. A handy alternative is to map the first 10 numbers to the Alt-F keys: |
||
− | naveedm9 attt gmail dottt com |
||
− | , September 7, 2006 12:47 |
||
− | ---- |
||
− | How do I undo close tab? |
||
− | |||
− | vi-sit-or |
||
− | , September 17, 2006 7:55 |
||
− | ---- |
||
− | How to make files open in tab of an existing Vim window by just clicking the file in windows file explorer ? (not right-click, just double clicking a file should open the file in a new tab of an existing vim window. currently, this action creates new vim windows everytime. it's annoying.). |
||
− | |||
− | Also, when i drag drop a file, i want it to open it in a new tab. |
||
− | |||
− | (i just want one vim window with all tabs in it and the above are the popular ways i add files into my editor.) |
||
− | |||
− | |||
− | |||
− | vimuser |
||
− | , September 29, 2006 2:01 |
||
− | ---- |
||
− | vimuser: |
||
− | |||
− | [http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:--remote-tab}} :help --remote-tab] |
||
− | |||
− | vi.sit.or |
||
− | , September 29, 2006 7:25 |
||
− | ---- |
||
− | vi.sit.or: |
||
− | |||
− | That isn't partciularly helpful. I am in the same boat as vimuser, and I've already tried passing that parameter..it does nothing on it's own. How can I get all files which get opened by vim to open in a new tab by default? Some clear instructions are desperately needed... |
||
− | |||
− | THANKS! |
||
− | |||
− | vimuser |
||
− | , October 27, 2006 8:56 |
||
− | ---- |
||
− | I found this tip |
||
<pre> |
<pre> |
||
+ | nnoremap <A-F1> 1gt |
||
− | autocmd VimEnter * tab all |
||
+ | nnoremap <A-F2> 2gt |
||
− | autocmd BufAdd * exe 'tablast | tabe "' . expand( "<afile") .'"' |
||
+ | nnoremap <A-F3> 3gt |
||
+ | nnoremap <A-F4> 4gt |
||
+ | nnoremap <A-F5> 5gt |
||
+ | nnoremap <A-F6> 6gt |
||
+ | nnoremap <A-F7> 7gt |
||
+ | nnoremap <A-F8> 8gt |
||
+ | nnoremap <A-F9> 9gt |
||
+ | nnoremap <A-F0> 10gt |
||
</pre> |
</pre> |
||
− | on http://www.nabble.com/tablines-on-Windows-t1365085.html |
||
+ | ==Other customization== |
||
− | vim--AT--xenoc.demon.co.uk |
||
+ | Use H and L to move to the previous/next tabpage. |
||
− | , October 30, 2006 1:34 |
||
− | ---- |
||
− | Key combination to switch to tab number 1, 2 ,3 etc? can't find an appropriate command, and that's the only tabswitch command i need |
||
− | |||
− | mach3k |
||
− | , November 2, 2006 9:51 |
||
− | ---- |
||
− | i neglected to rtfm, the key combination is <tab number>gt, |
||
− | here's a handy alternative to switch to tab-N by pressing Alt-FN |
||
<pre> |
<pre> |
||
+ | nnoremap H gT |
||
− | map <A-F1> 1gt |
||
+ | nnoremap L gt |
||
− | map <A-F2> 2gt |
||
− | map <A-F3> 3gt |
||
− | map <A-F4> 4gt |
||
− | map <A-F5> 5gt |
||
− | map <A-F6> 6gt |
||
− | map <A-F7> 7gt |
||
− | map <A-F8> 8gt |
||
− | map <A-F9> 9gt |
||
− | map <A-F0> 10g |
||
</pre> |
</pre> |
||
− | mach3k |
||
− | , November 2, 2006 10:37 |
||
− | ---- |
||
− | Is there any way we can add a binding to go to the `last-used' tab? That is much more intuitive I believe ... |
||
− | |||
− | sandesh247DeleteThis--AT--gmail.com |
||
− | , January 17, 2007 6:54 |
||
− | ---- |
||
− | <!-- parsed by vimtips.py in 0.536083 seconds--> |
||
+ | That way you can hold down the Shift key while you scroll left and right through the tabs with '''h''' and '''l'''. |
||
+ | ==Comments== |
||
− | [[Category:Tabs]] |
Revision as of 04:07, 18 September 2015
created 2006 · complexity basic · author Kim Schulz aka KimuSan · version 7.0
Vim 7 introduced tab pages with functions to navigate to different tabs (see using tab pages or :help gt or :help :tab). You might however want to map some of those functions to separate keys. To do so, add the desired snippet to your vimrc.
Some of the mappings used here interfere with Vim's normal procedures. For example:
- Ctrl-T is used for jumping to previous tags
- Ctrl+W is used as a prefix for the window commands
- Ctrl+Tab is captured by KDE to switch workspaces.
Some mappings might not work in terminal versions of Vim (especially mappings, that use the Alt key or a combination of Ctrl and Shift).
" Tab navigation like Firefox. nnoremap <C-S-tab> :tabprevious<CR> nnoremap <C-tab> :tabnext<CR> nnoremap <C-t> :tabnew<CR> inoremap <C-S-tab> <Esc>:tabprevious<CR>i inoremap <C-tab> <Esc>:tabnext<CR>i inoremap <C-t> <Esc>:tabnew<CR>
You can open a new tab with Ctrl-T, go forward through the tabs with Ctrl-Tab and backwards with Ctrl-Shift-Tab. You can also use Ctrl-PageDown and Ctrl-PageUp to cycle through tabs which works by default in gvim and Firefox.
For opening and closing tabs, you can also add Ctrl-Insert and Ctrl-Delete mappings like this:
nnoremap <C-Insert> :tabnew<CR> nnoremap <C-Delete> :tabclose<CR>
Note, that those keys are only mapped in normal mode, because in insert and visual mode they already have a function.
nnoremap th :tabfirst<CR> nnoremap tj :tabnext<CR> nnoremap tk :tabprev<CR> nnoremap tl :tablast<CR> nnoremap tt :tabedit<Space> nnoremap tn :tabnext<Space> nnoremap tm :tabm<Space> nnoremap td :tabclose<CR> " Alternatively use "nnoremap th :tabnext<CR> "nnoremap tl :tabprev<CR> "nnoremap tn :tabnew<CR>
Those mappings use the easily-reached t key in combination with the well known hjkl navigation keys in normal mode that move the cursor left, down, up or right. tj moves to the next tab, tk moves to the previous tabpage while th and tl move to the leftmost/rightmost tabpage.
For something like gnome-terminal tab-related key shortcuts:
:nnoremap <C-S-t> :tabnew<CR> :inoremap <C-S-t> <Esc>:tabnew<CR> :inoremap <C-S-w> <Esc>:tabclose<CR>
Open files always in new tabs
If you like to open all command line arguments in a new tabpage, use this snippet (but remember, that the 'tabpagemax' setting still applies).
autocmd VimEnter * tab all autocmd BufAdd * exe 'tablast | tabe "' . expand( "<afile") .'"'
The second autocommand creates a new last tabpage for any buffer that is created (e.g. when using :e foobar, the current buffer will remain visible in the current tabpage and the file foobar will be opened in a new tabpage and Vim goes to that tabpage.)
Use <A-Fn> to go to the nth tabpage
You can use ngt to move to the nth tabpage. A handy alternative is to map the first 10 numbers to the Alt-F keys:
nnoremap <A-F1> 1gt nnoremap <A-F2> 2gt nnoremap <A-F3> 3gt nnoremap <A-F4> 4gt nnoremap <A-F5> 5gt nnoremap <A-F6> 6gt nnoremap <A-F7> 7gt nnoremap <A-F8> 8gt nnoremap <A-F9> 9gt nnoremap <A-F0> 10gt
Other customization
Use H and L to move to the previous/next tabpage.
nnoremap H gT nnoremap L gt
That way you can hold down the Shift key while you scroll left and right through the tabs with h and l.