Show vim tab line even if only one file is open - vim

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

Related

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.

Gvim does not write tabs

In C++ files that I edit with Gvim I have noticed that code lines which are in inside blocks
(curly braces {})
although are being shown on the screen with the correct amount of tabs in Gvim
(i.e. plus one tab from the code which is outside of this code block)
when I open the same files with an another editor
like sublime text
that extra tab that must exist in every line inside the code block does not exist.
So after opening these files with a hex editor I noticed that Gvim does not write those extra tabs in the code blocks?
Why does this happen?
Is it because of cindent?
Also how can I fix this rather than auto-reformat every time?
I am pretty sure that vim will faithfully save all the characters that are in the buffer. Various options affect how tabs are displayed, and whether actual tab characters or spaces are used for indenting. You can check their values, and see where they were set (default, in your vimrc file, or by some plugin) with
:verbose set ts? sts? et? sw? sta? ci? pi?
(These and more related options are grouped together if you open an options window with :options and look at Section 15.) If you want to visually check where you have tab characters rather than spaces, you can :set hls and then search for tab characters (or :match Search '\t') or you can :set list.
If you try all that and you still think that vim is not saving what is in the buffer, then there are odd things to check, like whether you have any BufWrite or related autocommands.

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:

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

Sync vim and a regular text editor

I usually prefer to write my website's paragraphs in LibreOffice. After finishing, I have to copy and paste the text to vim. I would prefer to keep "connected" this two editors, so what I write in LibreOffice is also in vim.
Is there any way to sync contents?
Solutions using Latex are also welcomed, since it is more hackable..
Add set autoread in your .vimrc. Then open the file both in vim and libreoffice, and vim will automatically reload the file if it detects changes.
BTW, if you are missing automatic line filling in vim, look at the formatoptions variable.

Resources