18
votes
TIL that in vim, you can press <C-Tab> (or g<Tab>) to jump to the last accessed tab page
Previously I used to have this in my .vimrc:
if !exists('g:lasttab')
let g:lasttab = 1
endif
nmap <C-Tab> :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
Courtesy of: https://stackoverflow.com/a/2120168
But while going through the help docs today, I stumbled across this mapping and am glad to find that this now exists by default. When it got added, however, I don't know.
I’m curious what other vim users’ relationships are with the concept of tabs. Personally I don’t use vim’s native tabs at all. Instead I use my terminal emulator’s tabs to open distinct instances of vim. Beyond that I know people who use a terminal multiplexer (e.g. tmux) or even window manager tabs (e.g. i3wm’s tabbed mode) for multiple vim instances. Anyone here have a strong preference for a tabbed workflow with respect to vim?
I use buffers, which are more or less invisible tabs. But I access them through lustyjuggler which exposes them as temporarily visible tabs, but in a most recently accessed list.
But I’ll usually have several vim instances open as well, spread through various tmux windows.
For normal develoent I don't use vim tabs or buffers, tmux, or terminal tabs. My workflow is to open separate terminal emulator windows, each with a single tab and their own vim instance. Two monitors, each with a terminal taking up half the screen, so I can see four open code files at a time. Then I have openbox configured with a dozen or more workspaces. This allows me to easily flip between a whole workspace worth of open terminals with one keystroke. Then I have a Windows PC connected via synergy, those two screens are mostly for the web browser and documentation. It could be better optimized in some ways but it gets the job done.
This setup was inspired by an experimental WM or DE I saw a video of, perhaps a decade ago, where instead of workspaces or tabs or any of that you had an endless desktop, and would open new windows as you drilled down into code, moving organically across the desktop plane. Wish I could remember what it was called.
I am on swaywm (i3 alternative that supports wayland) and actively use vim's tabs as well. I mostly write backend code using the Django Framework and using the same vim instance but with multiple tabs allows me to maintain the same project's overall context but also have divisions based on the program logic.
Note that Django allows for multiple apps running in the same project (more about that at the bottom). So down the years, this is how I have now come to use Vim's tabs:
Since they are all of the same project, but varying logic and even language, I do find vim's tabs very useful. Having said that, I do use my WM's windowing to manage other vim instances that are used for other, separate. editing tasks.
More on "apps" and "project" in the Django Framework:
A project is the whole webapp/website basically. This project can have smaller functional parts, like a live chat service; a payment gateway; user profiles, etc. These can be separate "apps" of the same project in Django speak.