itchyny/vim-gitbranch

Unlocking the mysteries of the vim function for the uninitiated ...

8i8 opened this issue · 8 comments

8i8 commented

Hello itchyny,

Thank you for your time and your advice.

Would you be so kind as to give a brief explanation of how to implement the function in your vim gitbranch plugin, I am relatively new to the programming world, also due to my current use of the vundle plugin to install vim scripts I am consequently lacking in experience in this area.

How can I call this function, is is possible to make the git branch name appear in lightline?

Thank you for your kind consideration and should you see fit; Any consequent advice.

Firstly, try :echo gitbranch#name() . To configure this plugin to appear in the statusline with lightline, register gitbranch#name to g:lightline.component_function.

8i8 commented

So I will add :echo gitbranch#name() to my vimrc, right?
Where do I register gitbranch#name# I have never written a vim script.

Thank you.

  1. Open a file in a git repository.
  2. Execute :echo gitbranch#name()
  3. The command shows the name of the current branch.
8i8 commented

Ah great, yes it does, I feel silly not to have tried that!

8i8 commented

So, can I add this function to the light line script that you have also written?

Add the following configuration to your .vimrc file.

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

And then restart Vim.

8i8 commented

Thank you so much itchyny; It works perfectly.
I am very greatfull for both your code and your help in getting it installed.

Fine. Good luck!