Lightline.vim: How to config filename to show full path

Created on 12 Mar 2018  路  6Comments  路  Source: itchyny/lightline.vim

This may not be a problem, But I am confused about configuring full path of current file.
Could you please show me ?

configuration

Most helpful comment

Assuming you are working on git repositories, configure as follows

let g:lightline = {
      \ 'component_function': {
      \   'filename': 'LightlineFilename',
      \ }
      \ }

function! LightlineFilename()
  let root = fnamemodify(get(b:, 'git_dir'), ':h')
  let path = expand('%:p')
  if path[:len(root)-1] ==# root
    return path[len(root)+1:]
  endif
  return expand('%')
endfunction

Note that this configuration requires vim-fugitive plugin.

If you have vim-gitbranch plugin installed, replace the let root line with as follows.

  let root = fnamemodify(get(b:, 'gitbranch_path'), ':h:h')

All 6 comments

Use absolutepath component:

let g:lightline = {
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ], [ 'readonly', 'absolutepath', 'modified' ] ],
      \ }
      \ }

Is there a configure that can show the file path relative to project root directory?

Assuming you are working on git repositories, configure as follows

let g:lightline = {
      \ 'component_function': {
      \   'filename': 'LightlineFilename',
      \ }
      \ }

function! LightlineFilename()
  let root = fnamemodify(get(b:, 'git_dir'), ':h')
  let path = expand('%:p')
  if path[:len(root)-1] ==# root
    return path[len(root)+1:]
  endif
  return expand('%')
endfunction

Note that this configuration requires vim-fugitive plugin.

If you have vim-gitbranch plugin installed, replace the let root line with as follows.

  let root = fnamemodify(get(b:, 'gitbranch_path'), ':h:h')

it works, awesome, @itchyny thanks for the quick reply

@itchyny my hero :)

Hi it's work great, thank you! Just have to made small adjustment on Windows that root variable was C:\...\... and path variable was C:/.../... at least with fugitive. Then It didn't match because of different file separator symbol.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Char-Aznable picture Char-Aznable  路  4Comments

codepushr picture codepushr  路  3Comments

dongsibo picture dongsibo  路  4Comments

Blosberg picture Blosberg  路  4Comments

dessaya picture dessaya  路  3Comments