Skip to main content
Share Your Experience: Take the 2024 Developer Survey
19 votes

What is the difference between a tab, viewport, window, split and buffer?

A buffer is the in-memory text of a file. It may differ from the saved version of the file. A window is a view of a buffer. You can have two (or more) windows editing different parts of the same ...
Tom Hale's user avatar
  • 2,711
14 votes
Accepted

Duplicate buffer into new tab instead of moving it

I'm not sure but you could try :tab split (or the shorter version :tab sp). The :split command should duplicate the viewport displaying a.txt, while the :tab modifier should move this viewport into a ...
user9433424's user avatar
  • 6,148
13 votes

Open multiple files in tabs from Explore mode

From :h netrw-t: BROWSING WITH A NEW TAB netrw-t Normally one enters a file or directory using the <cr>. The "t" map allows one to open a new window holding the new directory ...
statox's user avatar
  • 50.1k
12 votes
Accepted

Reopen the most recently closed buffer

I played around with this a bit and the following seems to work for the cases I tested, including closing a window split and a tab with one window using :q. augroup bufclosetrack au! autocmd ...
John O'M.'s user avatar
  • 8,582
12 votes

Reopen the most recently closed buffer

You can try CTRL-O, this will go to last cursor posision in jump list, even for closed buffers. This will even work from fresh vim instance, so you can open last file with that.
grodzik's user avatar
  • 4,638
11 votes
Accepted

Is it possible to open a tab in a window and not a window in a tab?

From :h tab-page-intro: A tab page holds one or more windows. You can easily switch between tab pages, so that you have several collections of windows to work on different things. Usually ...
statox's user avatar
  • 50.1k
8 votes
Accepted

Spread already open files into split view

Here are a bunch of helpful commands for you: To open every buffer in a horizontal split: :sball To open every buffer in a vertical split: :vert sball You can do the same thing with tabs, e.g, to ...
DJMcMayhem's user avatar
  • 17.7k
7 votes

Is it possible to open a tab in a window and not a window in a tab?

No you can't, here's why: Vim use multiple concepts to handle text files: Buffer: An in-memory version of a file. Editing a file will in fact edit the buffer before writing (i.e. saving) anything to ...
nobe4's user avatar
  • 16.1k
7 votes
Accepted

Is there a way to move n tabs forward?

As far as I'm aware, there is no default way to do this. I looked into the ex command tabnext, which accepts a count, but functions exactly the same as gt (that is, it moves to tab page {count}, not {...
DJMcMayhem's user avatar
  • 17.7k
7 votes
Accepted

How can I make sure all buffers end up as tab or force remaining buffers into tabs?

The documentation for this feature can be found at :help -p: Open N tab pages. If [N] is not given, one tab page is opened for every file given as argument. The maximum is set with 'tabpagemax' ...
Rich's user avatar
  • 32.1k
6 votes
Accepted

How to open a list of files into tabs with Tab-top-bar?

If you want to open the file under your cursor in a new tab your mapping would be: nnoremap <leader>gf :silent! execute "tabe " . expand('<cfile>') <bar> redraw!<CR> Your ...
statox's user avatar
  • 50.1k
6 votes
Accepted

Open a filename given by an external command

From :help backtick-expansion: *backtick-expansion* *`-expansion* On Unix and a few other systems you can also use backticks for the file name argument, for example: > :...
user9433424's user avatar
  • 6,148
6 votes

Limit buffer list to current tab

The following code will give you the file names for the current tab (if the buffer in a window is connected to a file): " Get the buffer numbers of all windows on the current tab let buffers = ...
Jürgen Krämer's user avatar
6 votes
Accepted

How to create a new tab or window from a buffer?

Create a new window from a buffer: :sb<N>(horizontally) or :vert sb<N>(vertically). Create a new tab from a buffer: :tab sb<N> or create a new window and then press <C-W&...
sdp's user avatar
  • 491
6 votes
Accepted

Cannot switch tabs when in terminal tab

(This answer pertains to neovim specifically. If you find anything conflicting with vim, let me know and I'll edit the answer.) :h term operates in a separate mode: the terminal model. It's somewhat ...
3N4N's user avatar
  • 5,764
5 votes

Move existing window to existing tab

The two commands defined below move all buffers from the right hand tab to the current tab and then close the right hand tab. Mtabsp moves them by splitting horizontally and Mtabvsp splits vertically. ...
evpo's user avatar
  • 151
5 votes
Accepted

How to not close MacVim after the last tab is closed?

You seem to be looking for MacVim Preferences, and they are under the MenuBar entitled "MacVim". MacVim -> Preferences -> General There you'll find settings for what to do on startup, and after the ...
jubilatious1's user avatar
5 votes

Navigate to tag in a new tab if not already opened, like `tab drop`?

Put this in your vimrc: map <C-]> :TabExpand 1<CR> command -nargs=1 TabExpand call HandleTabTagExpand( <f-args> ) let s:commentchar = """ function HandleTabTagExpand(tagnumber) ...
Tim's user avatar
  • 426
5 votes

Retitling tab labels

You can use the 'tabline' setting for this. Here's an example adapted from :help setting-tabline: set tabline=%!MyTabLine() " Set the entire tabline function! MyTabLine() let s = '' for i in ...
Martin Tournoij's user avatar
5 votes

How to change color of tabs in the tab-bar in gvim?

You can remove the e flag from the 'guioptions' option, this way the tab line matches the general colorscheme. set guioptions-=e Then use the :highlight command's GUI options, e.g.: hi TabLine guifg=#...
Alvaro9366's user avatar
5 votes

How to create a new tab or window from a buffer?

While editing command line a "special" #n (see :h cmdline-special) is replaced with the n-th buffer name. Hence, all of the following work in Vim (:h 42): :edit #42 :split #42 :tabedit #42 And so on....
Matt's user avatar
  • 20.8k
5 votes

How to return from tab page mode to the normal one?

You can use the :tabonly command, to close all other tabpages at once. Note: technically you will still have a single tabpage open, even if the tablabel does not show up.
Christian Brabandt's user avatar
4 votes
Accepted

Rather than tabnext and tabprevious can I get a list of tabs and select the one to switch to?

To expand on @Tumbler41's comment about :tabs, it shows you a list of tabs like :ls shows you buffers. But, there isn't a command to go directly to a tab from this list like using :b after :ls. You ...
Tommy A's user avatar
  • 6,790
4 votes
Accepted

Open multiple files in tabs from Explore mode

Let's Vim do it for you. You can put the following code at the end of your vimrc file: function! NetrwOpenMultiTab(current_line,...) range " Get the number of lines. let n_lines = a:lastline -...
Jair López's user avatar
  • 1,854
4 votes
Accepted

`gt` is not consistent with `gT` (and many other commands) when `{count}` is prepended

I can't really explain why it works like this, my best guess is that you more often need to go a tab by its index rather than going 3 tabs forwards. However, if you really don't like how Vim works and ...
statox's user avatar
  • 50.1k
4 votes
Accepted

Why are split and tab navigations distinct?

Tab navigation is one dimensional, so it has commands which mirror similar commands, :bn, :cp, etc. Window navigation is two dimensional, so it has commands that align with the two dimensional normal ...
Rich's user avatar
  • 32.1k
4 votes
Accepted

What is the X that appears on the top right corner when multiple tabs are open?

Allows you to close a tab with a mouse. (You'll probably need to enable mouse support enabled)
110100100's user avatar
3 votes
Accepted

Empty first tab lost when using sessions

This is indeed a bug in Vim. I filed a GitHub issue, and someone on the vim-dev mailing list addressed it. Here's a patch that fixes it in Vim 8.0.52: diff --git a/src/ex_docmd.c b/src/ex_docmd.c ...
Jim Stewart's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible