0

I use Vim 8.0 (homebrew) from iTerm 3.

How do I use full filenames instead of these abominations that Vim seems to print by default? enter image description here

Some context as filenames:

  • sidebar.php
  • sponsors.php
  • donate.php
  • sort-bar.php
  • single-product.php
  • archive-product.php
  • product-box.php
  • templates.js
  • card-page.php

So yeah, these serve basically no value. I can't guess which "uct.php" is what I want. How do I make Vim print the full filenames (leave folders and path out)?

I researched before asking the question, and none of the answers provided in these worked for me: https://stackoverflow.com/questions/20256380/show-filename-only-in-tabs-terminal-vim https://stackoverflow.com/questions/2468939/how-to-let-tab-display-only-file-name-rather-than-the-full-path-in-vim

2
  • where do you see those filenames? Could it be, that this comes from a plugin you use? Commented Feb 6, 2017 at 10:26
  • In the "tab bar" or whatever it is, that appears on top then I open files using :tabe filename
    – Christian
    Commented Feb 6, 2017 at 10:52

1 Answer 1

3

For the terminal, you want to check the 'tabline' option. For the gui version, check the 'guitablabel' setting. Since you seem to be using a terminal vim, here is what I would do:

The help page for 'tabline' the help already mentions how to set it, so follow the link setting-tabline and copy the function found there:

  function MyTabLine()
      let s = ''
      for i in range(tabpagenr('$'))
        " select the highlighting
        if i + 1 == tabpagenr()
          let s .= '%#TabLineSel#'
        else
          let s .= '%#TabLine#'
        endif

        " set the tab page number (for mouse clicks)
        let s .= '%' . (i + 1) . 'T'

        " the label is made by MyTabLabel()
        let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
      endfor

      " after the last tab fill with TabLineFill and reset tab page nr
      let s .= '%#TabLineFill#%T'

      " right-align the label to close the current tab page
      if tabpagenr('$') > 1
        let s .= '%=%#TabLine#%999Xclose'
      endif

      return s
    endfunction

    function MyTabLabel(n)
      let buflist = tabpagebuflist(a:n)
      let winnr = tabpagewinnr(a:n)
      return bufname(buflist[winnr - 1])
    endfunction

    :set tabline=%!MyTabLine()

Now, since you want to have the fullname, make the second last line of the MyTabLabel() function this:

return fnamemodify(bufname(buflist[winnr - 1]), ':t')

or if you want to see the whole path:

return fnamemodify(bufname(buflist[winnr - 1]), ':p')

Read more about the fnamemodify() function and the various arguments it accepts at filename-modifiers

1
  • Works fine! I'll have some reading to do. Thanks.
    – Christian
    Commented Feb 6, 2017 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.