How to have different title and tab title in vim - 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

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

vim open buffer in existing tab

How can you tell vim to use an existing tab page for a file if it's already open?
I thought this option is supposed to do that
set switchbuf=usetab
As a minimal example I had only the above line in my .vimrc and moved all plugins (no .vim directory) but when I do for example vim .vimrc and then :tabe .vimrc I get two tab pages with the same file. Is there a way to prevent that?
You should read :help 'switchbuf' more carefully:
This option controls the behavior when switching between buffers.
So… that option has no effect on non-buffer-switching commands like :tabedit.
Also, :help :tabedit says:
Open a new tab page with an empty window, after the current tab page.
So… you can't really expect that command to not open a new tab page, do you?
If you want to edit a new file in place, use :e filename.
If you want to edit a file in a horizontal window, use :sp filename.
If you want to edit a file in a vertical window, use :vs filename.
If you want to edit a file in a new tab page, use :tabe filename.
If you want to switch to another buffer, use :b.
If you want to switch to another buffer and benefit from the switchbuf option, use :sb.

Vim - open new tab in buffer

I jsut switched from sublime text to vim and I'm trying to replicate sublime's tab view.
I usually have a vertical split opened with :vsp and each split I'd like to open new tabs. To do this I type in bufdo tab split but it opens a new tab over my split and not within the split.
How can I open the tab within the split?
Many thanks
To Open a tab, editing the current file's name you can use %, which acts as a macro for the current file:
:tabe %
To Open a new tab & show the current file's directory:
:Te or :tabe %:h
To move between opened tabs:
gt # Go to next tab
gT # Go to previous tab
In Vim, each edited file corresponds to a buffer. These are displayed in windows. Multiple windows can be split. Multiple such an arrangements of window(s) can be switched to in tab pages (this is a more recent addition).
In this hierarchy, the tab pages are always "above" the windows, so there can only be one single tabline that structures the tab pages. (And it's always between the menu / window title and the windows.)
In Vim, working with window splits is preferred over tab pages. It's recommended to use the latter only to separate different workspaces / projects, etc. Vim is very powerful (and with a long heritage), so you cannot directly take over concepts seen in other editors.

Indication of current tab in 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:

Set Vim window size and selection from command line

I want to launch two files from the command line and I want the window to be split horizontally. This can be achieved with the following command:
vim -o index.html index.1
Which gives me the following output split evenly
What I want, instead, is for the top window to be substantially larger, like so
How do I achieve this? Also, currently, the top window is selected, which is what I want. However, if it wasn't selected, or I wanted the bottom window selected, how would I go about achieving this?
You can open the two files with
vim index.html +10sp index.1
After vim has read index.html it executes the ex command 10sp. That means that the current window is split into two with the new window being 10 rows high. After that index.1 is read by vim and loaded into the currently active window.
If you already set splitbelow in your .vimrc index.1 is loaded into the bottom window that is active at the same time.
For example if you want the top window to be active and splitbelow is set you can append the corresponding ex command to the line
vim index.html +10sp index.1 +"wincmd k"
One possible solution would be to make the top window 80% of the available size:
vim +'execute "resize" (&lines / 10) * 8' -o file1 file2
See :help :resize and :help 'lines' for more information.
Small clarification: & is used in front of options to retrieve its value. Thus &lines holds the value of what you could set yourself, e.g.:set lines=100. In this case, &lines gets set by Vim on-the-fly even when you resize the window that holds Vim.

Resources