5 ms·
I feel silly for only recently discovering tabs in vim. :tabnew file Opens up a new tab, :tabn Goes to the next tab, and :tabp Goes to the previous
by scott_s 17y ago
I feel silly for only recently discovering tabs in vim.
:tabnew file
Opens up a new tab,
:tabn
Goes to the next tab, and
:tabp
Goes to the previous tab. Works great in both gui and non-gui mode.
- DannoHung 17y agogt and gT in command mode also do next tab and previous tab
- solutionyogi 17y agoAwesome, I didn't know this shortcut before! Much better than using :tabn :tabp !
- deleted 17y ago[deleted]
- bockris 17y agoalso #gt will go that tab number. I've changed my tab text to show the number in parenthesis before the name.
- solutionyogi 17y agoThat's a neat idea. How do you change it to show tab number in the tab header?
- graysnorf 17y agoFor those who prefer alt navigation, you can add to your gvimrc " tab navigation map <A-1> 1gt map <A-2> 2gt map <A-3> 3gt map <A-4> 4gt map <A-5> 5gt map <A-6> 6gt map <A-7> 7gt map <A-8> 8gt map <A-9> 9gt map <A-0> 10gt
- apotheon 17y agoWhat is that heretical "g" doing in front of "vimrc"?
- apotheon 17y agoThis also works with Vimperator. I'm now thinking about installing that Firefox extension that gives all the tabs numbers, for ease of reference. Alas, I don't remember what it was called -- but I'm sure I'll find it again.
- apotheon 17y agoI never bothered to learn that stuff before I started using Vimperator. I tend to prefer buffers over tabs for dealing with multiple files in a single Vim instance, so I never had much use for tab-related keybindings until I started using a vi-like interface for a tabbed browser. Maybe that's just me, though.
- cturner 17y agoSimilar to this, you can open up multiple files at the same time without saving. set bufhidden nmap <C-h> :bp nmap <C-l> :bn If you put this in your .vimrc file, you'll need to put a '^M' at the end of the nmap lines. You do this by doing <C-v><C-m> and it puts in a special character that means newline. Then you can switch between open buffers with ctrl+l and ctrl+h even if you have unsaved changes. it will end up looking like this: set bufhidden nmap <C-h> :bp^M nmap <C-l> :bn^M Unfortunately if you have many files open and don't touch them all it prevents you from quitting with a message 'E173: 17 more files to edit'. I haven't worked out how to obliterate this without damaging features I want (e.g. not quitting when there's unsaved data in those other files). The default vim that ships with linux distributions is often a pile of junk that has been hacked by the distribution, is missing features like these. You want to get vim-extended under redhat-like distributions (they've significantly improved the quality if their junk vim in recent releases), and vim-nox or vim-full in debian-like distributions.
- graywh 17y agoInstead of a literal ^M in the file, just use <CR>. And I think you mean "set hidden". And regarding E173: You can :qa, which won't lose any unsaved changes. And the proper vim package for Debian or Ubuntu is "vim". "vim-full" is the old name and it just installs "vim".
- Prolitheus 17y agoI rely on buffers rather than tabs, too, and find minibufexplorer.vim to be a great addition: http://www.vim.org/scripts/script.php?script_id=159 http://www.vim.org/scripts/script.php?script_id=159
- EAMiller 17y agoI never got the hang of tabs. I got comfortable with buffers before tabs were out, and I didn't see anything that tabs could offer that buffers don't. I probably have my screen split between two buffers 60% of the time. Once in a while I have my screen split with screen AND with vim :D
- apinstein 17y agotabs are pretty cool, but I like split and a set of macros I use for easily switching. The main reason I prefer split screen to tabs is that I often want to see code in the other buffer while I work. Open up a file, :split a new one, and then try these: map <C-j> <C-w>j80<C-w>+ " up one window, maximized map <C-k> <C-w>k80<C-w>+ " down one window, maximized map <C-h> 80<C-w>+ " maximize current window map <C-i> <C-w>= " all windows equal height
- apinstein 17y agotabs are pretty cool, but I like split and a set of macros I use for easily switching. The main reason I prefer split screen to tabs is that I often want to see code in the other buffer while I work. Open up a file, :split a new one, and then try these: map <C-j> <C-w>j80<C-w>+ " up one window, maximized map <C-k> <C-w>k80<C-w>+ " down one window, maximized map <C-h> 80<C-w>+ " maximize current window map <C-i> <C-w>= " all windows equal height
- wooby 17y agoYou can always open files as tabs at startup too with -p, like this: vim -p foo.c foo.h
- scott_s 17y agoThanks, I've made frequent use of doing that with -o (horizontal split) and -O (vertical split).