Indication of current tab in Vim - vim

Disclaimer: I am new to Vim.
Is there a way to get better visual indication of current tab in Vim? Right now it looks like this for me:

This is set by your colorscheme via TabLineSel. See :h TabLineSel and :h setting-tabline. Try
:hi TabLineSel ctermbg=131 guibg=#bd5353
to confirm.
Also, welcome to vim. Enjoy your stay. Tabs are useful for certain tasks, but many people forego them. You can change between various buffers without having them actively loaded in a window. For instance, if I type
vim 1.txt 2.txt 3.txt
It will load up and display 1.txt, but 2.txt and 3.txt are also loaded (they just aren't visible). You can see this with the :ls command. You can load up the other files using :b. For instance, :b2 if I want to edit the second one. There are numerous plugins that also aid in improving this functionality. For instance, vim-buffalo allows you to start typing the partial name of a buffer. Various other file loading plugins allow this as well (e.g. Ctrl-p, FuzzyFinder, etc.)

There are 3 highligh groups for tabline highlighting.
TabLine tab pages line, not active tab page label
TabLineFill tab pages line, where there are no labels
TabLineSel tab pages line, active tab page label
with setting colors (or link other group) on the above groups, you can customize your tabline highlighting. Usually a colorscheme will predefine those groups for you.
E.g https://github.com/sk1418/last256
has predefined:

Related

Show vim tab line even if only one file is open

I would like for vim to show the tab header (tab line) even if only one file is open.
For example, I open a file using vim. Then, I use :tabnew to open another file in a vim tab. Vim then displays a nice tab header at the top of the file. I would like this tab header to always be displayed (i.e. even if only one file is open in vim).
Also, not really a fan of the airline plugins, so not really looking for those kinds of answers.
Yes sorry about that. I was doing :help tabline and didn't see anything. You just need to put set showtabline=2 in your vimrc

bottom custom oh-my-zsh like statusbars for vim

I saw this picture in one of the CodeSchool's Screencast. #GreggPollack has customised his vim to look like one in the bottom picture.
I really like this bottom strip and that syntax highlighting for insert and other stuff on bottom command strip. I have the same strips for $prompts for my terminal with oh-my-zsh agnoster theme. How would I do that for vim?
The "bottom strip" is called statusline and its customization options are described in the following help page :help 'statusline'.
But most people prefer to use plugins for this purpose, which already include extensions that automatically fill in the statusline with extra information related with the currently opened file. The information displayed typically depend on the plugins under use.
The two most famous plugins for statusline configuration are:
Powerline
Airline

How to have different title and tab title in vim

As of now I have put the following in my .vimrc file in order to display the name of the currently open file in the screen title of my Terminal:
autocmd BufEnter * let &titlestring = expand("%:#")
set title
Is it possible to also set a specific tab title? That is, when I have a number of vim tabs open in Terminal on my Mac I would Terminal to display the directory path in the Terminal header when I have selected the tab related to the file and I would like to display only the name of the file in the header of the tab.
Some comments to your goal
Personally I hardly use tabs in vim. What you want to have can be achieved by setting some options. Before I talk about the options, I would say that what you want to do could be inconvenient. Because in vim, tab is a collection of windows, which means, it can have splitted windows, and in a tab page, you can show more than one buffers. That is, in a tab page, it is not always showing one file. As you are switching from split to split in a tab page, both your terminal title and the tab label could be changing.
For example, you have 3 dirs, /one /two and /three and two tab pages in your vim.
Now you have:
tab1:
/one/file1
tab2 (in split-windows):
/one/file1
/two/file1
/three/file1
When you are in tab1, your terminal title would be /one, tab1-label would be file1, fine. But when you are in tab2, your terminal title will change as you are switching from split to split. In this example, the tab-label would be same file1, so you have to check terminal window and the tab label to know which buffer/file you are currently editing. I don't think this is convenient.
Answer to your question
Okay, if you want that to happen, :h setting-tabline and check the example in the help text, it shows how to set the label of tabs. This should achieve your goal for vim in Terminal.
FYI, to get only parent dir name you can use %:p:h. to get only filename, you can use %:p:t.
Plus, some other things you may want to check:
There is another autocommand event: TabEnter .
:h setting-tabline if you want your tabline to show some complex text or other highlighting
if you want to play with filename/dirname further, you can check :h expand() and :h filename-modifiers

Vim has pre-installed tabs: How do I remove them?

Check the following screenshot:
I checked all my plugins/bundles, I use Vundle not Pathogen. Here's my list of bundles:
" This one is required baby!
Bundle 'gmarik/vundle'
" All of my Vundle bundles
Bundle 'scrooloose/nerdcommenter'
Bundle 'scrooloose/nerdtree'
Bundle 'mattn/zencoding-vim'
Bundle 'tpope/vim-fugitive'
Bundle 'tpope/vim-markdown'
Bundle 'tpope/vim-repeat'
Bundle 'tpope/vim-surround'
Bundle 'spf13/PIV'
Bundle 'vim-scripts/YankRing.vim'
Bundle 'jeffkreeftmeijer/vim-numbertoggle'
Bundle 'PotHix/Vimpress'
" Color schemes
Bundle 'altercation/vim-colors-solarized'
I just yanked my vimrc file in case you didn't notice. I am not aware that any of these change the buffer behavior, but I might be mistaken.
How can I remove this tab-like functionality? To reproduce it, simply open a file, and then grab other files, and drag them on top of the Vim window (not icon, window).
Vim can do tabs but it doesn't show a tabline by default: the tabline is created only if you create a tab and Vim won't create tabs if you don't tell it to do so.
If you don't want tabs don't use them. It's that simple.
From your comments, it looks like your are confusing Vim's tabs with the tabs you may be accustomed to in other editors. They might "look" the same at first sight but their purpose and implementation are very different.
In Vim, tabs are a way to organise workspaces: they don't and can't represent a single buffer. That's very important to understand if you want to use tabs in Vim. You need a lot of self discipline to actually be able to use Vim tabs as TextMate/Sublime tabs. You should only use tabs if you understand them.
The right way to work with multiple files in Vim is to use buffers and windows and the right commands. But here are a couple of tips if you really want to work with tabs:
Start by adding this line to your ~/.vimrc:
set switchbuf=useopen,usetab
With this setting, many operations (in the quickfix, notably) will jump you to the buffer where it is (in another window or another tab) instead of loading the buffer right here.
Then you should use the right commands:
:sb[uffer]
:sbn[ext]
:sbN[ext]
:sbl[ast]
:sbf[irst]
:sbr[ewind]
All these commands jump to the buffer where it is if it's displayed somewhere or open it in a split.
From there you are now able to do:
:e file_a
(editing file_a)
:tabe file_b
(editing file_b in tab 2)
:sbN
(editing file_a in tab 1)
:sbn
(editing file_b in tab 2)
…
without ending up with the same buffer in multiple tabs.
Tab-related movements like gt, :tabl or :tabn2 should be used only if you understand the real nature of tabs as workspaces, not as a way to switch to another file.
Edit Found a much more effective setting:
set tabpagemax=1 showtabline=0
inside your $MYVIMRC
Docs:
*'showtabline'* *'stal'*
'showtabline' 'stal' number (default 1)
global
{not in Vi}
{not available when compiled without the |+windows|
feature}
The value of this option specifies when the line with tab page labels
will be displayed:
0: never
1: only if there are at least two tab pages
2: always
This is both for the GUI and non-GUI implementation of the tab pages
line.
And
*'tabpagemax'* *'tpm'*
'tabpagemax' 'tpm' number (default 10)
global
{not in Vi}
{not available when compiled without the |+windows|
feature}
Maximum number of tab pages to be opened by the |-p| command line
argument or the ":tab all" command. |tabpage|

Using Vim's tabs like buffers

I have looked at the ability to use tabs in Vim (with :tabe, :tabnew, etc.) as a replacement for my current practice of having many files open in the same window in hidden buffers.
I would like every distinct file that I have open to always be in its own tab. However, there are some things that get in the way of this. How do I fix these:
When commands like gf and ^] jump to a location in another file, the file opens in a new buffer in the current tab. Is there a way to have all of these sorts of commands open the file in a new tab, or switch to the existing tab with the file if it is already open?
When switching buffers I can use
:b <part of filename><tab>
and it will complete the names of files in existing buffers. <part of filename> can even be the middle of a filename instead of the beginning. Is there an equivalent for switching tabs?
Stop, stop, stop.
This is not how Vim's tabs are designed to be used. In fact, they're misnamed. A better name would be "viewport" or "layout", because that's what a tab is—it's a different layout of windows of all of your existing buffers.
Trying to beat Vim into 1 tab == 1 buffer is an exercise in futility. Vim doesn't know or care and it will not respect it on all commands—in particular, anything that uses the quickfix buffer (:make, :grep, and :helpgrep are the ones that spring to mind) will happily ignore tabs and there's nothing you can do to stop that.
Instead:
:set hidden
If you don't have this set already, then do so. It makes vim work like every other multiple-file editor on the planet. You can have edited buffers that aren't visible in a window somewhere.
Use :bn, :bp, :b #, :b name, and ctrl-6 to switch between buffers. I like ctrl-6 myself (alone it switches to the previously used buffer, or #ctrl-6 switches to buffer number #).
Use :ls to list buffers, or a plugin like MiniBufExpl or BufExplorer.
Bit late to the party here but surprised I didn't see the following in this list:
:tab sball - this opens a new tab for each open buffer.
:help switchbuf - this controls buffer switching behaviour, try :set switchbuf=usetab,newtab. This should mean switching to the existing tab if the buffer is open, or creating a new one if not.
Vim :help window explains the confusion "tabs vs buffers" pretty well.
A buffer is the in-memory text of a file.
A window is a viewport
on a buffer.
A tab page is a collection of windows.
Opening multiple files is achieved in vim with buffers. In other editors (e.g. notepad++) this is done with tabs, so the name tab in vim maybe misleading.
Windows are for the purpose of splitting the workspace and displaying multiple files (buffers) together on one screen. In other editors this could be achieved by opening multiple GUI windows and rearranging them on the desktop.
Finally in this analogy vim's tab pages would correspond to multiple desktops, that is different rearrangements of windows.
As vim help: tab-page explains a tab page can be used, when one wants to temporarily edit a file, but does not want to change anything in the current layout of windows and buffers. In such a case another tab page can be used just for the purpose of editing that particular file.
Of course you have to remember that displaying the same file in many tab pages or windows would result in displaying the same working copy (buffer).
Contrary to some of the other answers here, I say that you can use tabs however you want. vim was designed to be versatile and customizable, rather than forcing you to work according to predefined parameters. We all know how us programmers love to impose our "ethics" on everyone else, so this achievement is certainly a primary feature.
<C-w>gf is the tab equivalent of buffers' gf command. <C-PageUp> and <C-PageDown> will switch between tabs. (In Byobu, these two commands never work for me, but they work outside of Byobu/tmux. Alternatives are gt and gT.) <C-w>T will move the current window to a new tab page.
If you'd prefer that vim use an existing tab if possible, rather than creating a duplicate tab, add :set switchbuf=usetab to your .vimrc file. You can add newtab to the list (:set switchbuf=usetab,newtab) to force QuickFix commands that display compile errors to open in separate tabs. I prefer split instead, which opens the compile errors in a split window.
If you have mouse support enabled with :set mouse=a, you can interact with the tabs by clicking on them. There's also a + button by default that will create a new tab.
For the documentation on tabs, type :help tab-page in normal mode. (After you do that, you can practice moving a window to a tab using <C-w>T.) There's a long list of commands. Some of the window commands have to do with tabs, so you might want to look at that documentation as well via :help windows.
Addition: 2013-12-19
To open multiple files in vim with each file in a separate tab, use vim -p file1 file2 .... If you're like me and always forget to add -p, you can add it at the end, as vim follows the normal command line option parsing rules. Alternatively, you can add a bash alias mapping vim to vim -p.
I ran into the same problem. I wanted tabs to work like buffers and I never quite manage to get them to. The solution that I finally settled on was to make buffers behave like tabs!
Check out the plugin called Mini Buffer Explorer, once installed and configured, you'll be able to work with buffers virtaully the same way as tabs without losing any functionality.
This is an answer for those not familiar with Vim and coming from other text editors (in my case Sublime Text).
I read through all these answers and it still wasn't clear. If you read through them enough things begin to make sense, but it took me hours of going back and forth between questions.
The first thing is, as others have explained:
Tab Pages, sound a lot like tabs, they act like tabs and look a lot like tabs in most other GUI editors, but they're not. I think it's an a bad mental model that was built on in Vim, which unfortunately clouds the extra power that you have within a tab page.
The first description that I understood was from #crenate's answer is that they are the equivalent to multiple desktops. When seen in that regard you'd only ever have a couple of desktops open but have lots of GUI windows open within each one.
I would say they are similar to in other editors/browsers:
Tab groupings
Sublime Text workspaces (i.e. a list of the open files that you have in a project)
When you see them like that you realise the power of them that you can easily group sets of files (buffers) together e.g. your CSS files, your HTML files and your JS files in different tab pages. Which is actually pretty awesome.
Other descriptions that I find confusing
Viewport
This makes no sense to me. A viewport which although it does have a defined dictionary term, I've only heard referring to Vim windows in the :help window doc. Viewport is not a term I've ever heard with regards to editors like Sublime Text, Visual Studio, Atom, Notepad++. In fact I'd never heard about it for Vim until I started to try using tab pages.
If you view tab pages like multiple desktops, then referring to a desktop as a single window seems odd.
Workspaces
This possibly makes more sense, the dictionary definition is:
A memory storage facility for temporary use.
So it's like a place where you store a group of buffers.
I didn't initially sound like Sublime Text's concept of a workspace which is a list of all the files that you have open in your project:
the sublime-workspace file, which contains user specific data, such as the open files and the modifications to each.
However thinking about it more, this does actually agree. If you regard a Vim tab page like a Sublime Text project, then it would seem odd to have just one file open in each project and keep switching between projects. Hence why using a tab page to have open only one file is odd.
Collection of windows
The :help window refers to tab pages this way. Plus numerous other answers use the same concept. However until you get your head around what a vim window is, then that's not much use, like building a castle on sand.
As I referred to above, a vim window is the same as a viewport and quiet excellently explained in this linux.com article:
A really useful feature in Vim is the ability to split the viewable area between one or more files, or just to split the window to view two bits of the same file more easily. The Vim documentation refers to this as a viewport or window, interchangeably.
You may already be familiar with this feature if you've ever used Vim's help feature by using :help topic or pressing the F1 key. When you enter help, Vim splits the viewport and opens the help documentation in the top viewport, leaving your document open in the bottom viewport.
I find it odd that a tab page is referred to as a collection of windows instead of a collection of buffers. But I guess you can have two separate tab pages open each with multiple windows all pointing at the same buffer, at least that's what I understand so far.
You can map commands that normally manipulate buffers to manipulate tabs, as I've done with gf in my .vimrc:
map gf :tabe <cfile><CR>
I'm sure you can do the same with [^
I don't think vim supports this for tabs (yet). I use gt and gT to move to the next and previous tabs, respectively. You can also use Ngt, where N is the tab number. One peeve I have is that, by default, the tab number is not displayed in the tab line. To fix this, I put a couple functions at the end of my .vimrc file (I didn't paste here because it's long and didn't format correctly).
I use buffers like tabs, using the BufExplorer plugin and a few macros:
" CTRL+b opens the buffer list
map <C-b> <esc>:BufExplorer<cr>
" gz in command mode closes the current buffer
map gz :bdelete<cr>
" g[bB] in command mode switch to the next/prev. buffer
map gb :bnext<cr>
map gB :bprev<cr>
With BufExplorer you don't have a tab bar at the top, but on the other hand it saves space on your screen, plus you can have an infinite number of files/buffers open and the buffer list is searchable...
Looking at
:help tabs
it doesn't look like vim wants to work the way you do...
Buffers are shared across tabs, so it doesn't seem possible to lock a given buffer to appear only on a certain tab.
It's a good idea, though.
You could probably get the effect you want by using a terminal that supports tabs, like multi-gnome-terminal, then running vim instances in each terminal tab. Not perfect, though...
If you want buffers to work like tabs, check out the tabline plugin.
That uses a single window, and adds a line on the top to simulate the tabs (just showing the list of buffers). This came out a long time ago when tabs were only supported in GVim but not in the command line vim. Since it is only operating with buffers, everything integrates well with the rest of vim.
relevant:
Vim: can global marks switch tabs instead of the file in the current tab?
maybe useful to solve a little part of OP's problem:
nno \ <Cmd>call To_global_mark()<cr>
fun! To_global_mark()
-tab drop /tmp/useless.md
exe 'normal! `' .. toupper(input("To global mark: "))
endf

Resources