Reputation: 1442
I understand that a variant of this question might have been answered.
I have tried :set guitablabel=%t
, but there are two problems:
To better understand my question, say I have a project folder, awesome-project
with the following structure:
awesome-project
AAA/
file1.txt
file2.txt
CCC/
special.txt
BBB/
file2.txt
file3.txt
DDD/
special.txt
Say I cd
to the project in my terminal and vim
from there.Then I proceed to open all the files in separate tabs.
Currently, my vim is set up to display the tabs as following (the |
s are separators - use your imagination!):
AAA/file1.txt | AAA/file1.txt | AAA/CCC/special.txt | BBB/file2.txt | BBB/file3.txt | BBB/DDD/special.txt
I want the tabs to display as:
file1.txt | AAA/file2.txt | CCC/special.txt | BBB/file2.txt | file3.txt | DDD/special.txt
or what Sublime Text does:
file1.txt | file2.txt --- AAA | special.txt --- AAA/CCC | file2.txt --- BBB | file3.txt | special.txt --- BBB/DDD
Essentially, given the current tabs have file names that are unique, all tabs should just display their file name. Otherwise, provide the first distinct relative folder to display in the tab so I can tell which files are file.
This is a feature in many other text editors (Sublime Text, Atom) that I would really like to keep because the relative path file names are too long for my own good.
Any help would be appreciated, whether it be:
.vimrc
Upvotes: 0
Views: 1991
Reputation: 41
I am also trying to do the same thing. You need to read tabline and setting-tabline if you are interested in writting your own tab lines. However, if you just want a simple one, you are free to copy this to your vimrc:
"tabline
if exists("+showtabline")
function MyTabLine()
let s = ''
let t = tabpagenr()
let i = 1
while i <= tabpagenr('$')
let buflist = tabpagebuflist(i)
let winnr = tabpagewinnr(i)
let s .= '%' . i . 'T'
let s .= (i == t ? '%1*' : '%2*')
let s .= ' '
let s .= '|'. i . ')'
let s .= ' %*'
let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')
let file = bufname(buflist[winnr - 1])
let file = fnamemodify(file, ':p:t')
if file == ''
let file = '[No Name]'
endif
let s .= file
let s .= ' '
let i = i + 1
endwhile
let s .= '%T%#TabLineFill#%='
let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
return s
endfunction
set stal=2
set tabline=%!MyTabLine()
endif
Upvotes: 2
Reputation: 196789
You are — unsurprisingly — misunderstanding and misusing tab pages.
Just like Atom or Sublime Text, Vim is a document-based program but, unlike the others, it doesn't use the "tab" metaphor as proxy for those documents. Instead, tab pages are workspaces designed to contain one or more windows, themselves viewports designed to display buffers. Buffers are Vim's equivalent of the documents in other editors and there's thankfully no built-in way to have an "always-on" list of buffers. "Thankfully" because such a feature would be just as useless as it is in those other editors.
Instead of using tab pages as document proxies — something that can't work anyway — I'd suggest you get used to Vim's buffer-based workflow.
Here is a bit of reading to get you started on the good foot.
Upvotes: 2