2

Here is my code from .vimrc but is not showing any icon near the branch name

I'm using

Plug 'itchyny/lightline.vim' " Lightline UI
Plug 'tpope/vim-fugitive'    " Git wrapper for Vim
Plug 'itchyny/vim-gitbranch' " Show branch in buffer
let g:lightline = {
      \ 'colorscheme': 'dracula',
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ],
      \             [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
      \ },
      \ 'component_function': {
      \   'gitbranch': 'FugitiveHead'
      \ },
      \ 'component_prefix': {
      \   'gitbranch': '\uf126 '
      \ },
        \ 'tabline': {
      \   'left': [ ['buffers'] ],
      \   'right': [ ['close'] ]
      \ },
      \ 'component_expand': {
      \   'buffers': 'lightline#bufferline#buffers'
      \ },
      \ 'component_type': {
      \   'buffers': 'tabsel'
      \ }
      \ }

autocmd BufWritePost,TextChanged,TextChangedI * call lightline#update()

1 Answer 1

2

I found no trace of component_prefix in the documentation or in the code of lightline.

I would propose you to do the following:

function MyFugitiveHead()
  let head = FugitiveHead()
  if head != ""
    let head = "\uf126 " .. head
  endif
  return head
endfunction

let g:lightline = {
    \ 'active': {
    \   'left': [ [ 'mode', 'paste' ],
    \             [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
    \ },
    \ 'component_function': {
    \   'gitbranch': 'MyFugitiveHead'
    \ },
    \}

Remark: This solution doesn't requires 'itchyny/vim-gitbranch'.

3
  • Thanks a lot for fixing the code!
    – Mafsi
    Feb 26, 2023 at 19:24
  • You are welcome :-) Thanks for the feedback. Feb 26, 2023 at 19:27
  • 1
    Presumably this requires a "Nerd" font, since my font (and a few others I've tried) doesn't have the glyph for \uf126
    – D. Ben Knoble
    Feb 27, 2023 at 18:52

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.