Search code examples
vimvim-plugin

vim-airline: how to create a custom tabline formatter so that it contains the current directory?


In vim-airline, how to create a custom tabline formatter so that it contains the current directory? something like: dir/filename or filename (dir). I did google this, but don't find an answer.


Solution

  • I found the solution.

    In ~/.vim/bundle/vim-airline/autoload/airline/extensions/tabline/formatters, create the custom formatter, for instance, you can name it as custom_dir_filename.vim which has the following file content:

    function! airline#extensions#tabline#formatters#custom_dir_filename#format(bufnr, buffers)
      let name = bufname(a:bufnr)
      return  fnamemodify(name, ':p:h:t') . '/' . fnamemodify(name, ':t')
    endfunction
    

    In your .vimrc, add the following:

    let g:airline#extensions#tabline#formatter = 'custom_dir_filename'