Closed h0adp0re closed 4 years ago
Great idea, i'll do that, it's quite simple in fact!
(the PR will close this issue when merged into master)
Wow, that was fast, thanks! However, I can't seem to use the method quite yet... I'm getting an error on the command line when starting vim, if I follow the instructions in the README.
let header_tips = GetTip()
let g:startify_custom_header = 'startify#pad(header_tips)'
---
E117: Unknown function: GetTip
Is it the order the plugins are loaded in? Or is it something specific to Startify instead?
Edit: I have since tried the following, and now I'm getting the same error inside of vim.
function! s:tips_wrapper()
redir => var
silent! call GetTip()
redir END
return map(split(var, '\n'), '" " . v:val') + ['']
endfunction
let g:startify_custom_header = s:tips_wrapper()
---
E117: Unknown function: GetTip
Are you sure you updated vim-tips? I was able to call echo GetTip()
from the nvim command without issue.
As for calling it from another plugin / from vimrc, you should make sure vim-tips
is loaded beforehand.
You can make sure of that by preceding utilisation by the lineruntime plugin/vim-tips.vim
For example, in my vimrc, I have those lines:
runtime plugin/vim-tips.vim
let g:test = GetTip()
I can then echo test
from the nvim command and get a tip as expected.
Yeah, positive I have the newest vim-tips. I am loading vim-tips as the first plugin and it still doesn't work in vim-startify. I use vim-plug if that's relevant somehow.
I can also run :echom GetTIp()
and a tip is printed to the command line.
I also use vim-plug, but I didn't know there was any substantial changes from the order of the Plug statements.
If you can use GetTip() from the neovim command line, the reason you can't use it inside your vimrc or another plugin has to do with vim & sourcing plugin, not vim-tips: the function is correctly provided. I can't debug it further because (I think) the issue does not lie with vim-tips but the management & loading of plugin functions themselves.
If my trick to precede the GetTip() calls with a runtime plugin/vim-tips
does not work for you (it does for my linux/neovim) I'm a bit out of ideas.... :cry:
If I was wrong in any way, or if you have insight on how to make it work, please share them, I'll do my best
Okay, I got it working, somewhat.
It works only after sourcing .vimrc
and then running Startify from inside vim manually. It doesn't work on initial launch, there's an empty line in the header where the tip is supposed to be. So if I run :so $MYVIMRC
first, and then trigger Startify manually, a tip is rendered in the header.
Weirdly, calling :call DisplayTip()
works straight after launch.
I have very little experience with vimscript so I'm gonna paste the relevant parts here, I've no clue what I'm still doing wrong.
" vim plugins, contains only Plug stuff
so $HOME/.vim/plugins.vim
" Custom startify header
function! s:tips_wrapper()
redir => var
if exists('*GetTip')
runtime $HOME/.vim/bundle/vim-tips/plugin/vim-tips.vim
let tip = GetTip()
silent! echo tip
endif
redir END
return map(split(var, '\n'), '" " . v:val') + ['']
endfunction
let g:startify_custom_header = s:tips_wrapper()
It seems to me that if exists('*GetTip')
prevents any errors being shown, but the issue is still there. If I remove the condition, I still get E117: Unknown function: GetTip
.
Unfortunately, I'm probably less of a vimscript guru than you, since I don't understand how you code is supposed to work... really
However, my guess (of this being a vim, sourcing & plugin management issue) stands.
I don't think it would be productive to drag this any longer here, as I am 100% unable to come up with a fix, because it (looks like it) does not have nothing to do with vim-tips itself. You'll probably have more chance if you ask a question on r/vim or another similar forum.
If you do find a workaround, i'll be happy to include your contribution to the project's README.
Thanks for the feedback and sorry for being unable to help you
I'm no guru, that function is courtesy of vim-startify's author, copied from this issue. I merely added the conditional.
But I agree, let's not continue here. I'll go seek advice from vim-startify as well. Maybe there's something to be done on their side.
Last I heard, they were open to having the alternative of displaying tips instead of quotes in the header. Maybe you guys can collaborate on that? Just putting it out there.
Thank you for your time and thanks for the plugin!
Thanks for the tip, I'll leave a message on their repo
Maybe if you look into how they get their quotes, you'll be able to do the same with vim-tips :-), just an idea, I haven't looked into anything and maybe they're juste different things.
I'll leave this issue open for some time in case someone finds a fix
You can close this now, the solution was as simple as this:
let g:startify_custom_header = 'startify#pad([GetTip()])'
There's some semantics that I'd never thought of.
great, i'll include that in the README in case someone has the same use case - problem
Hey, I'd like to use this plugin in the custom header of vim-startify, since the output is removed from the command area (due to the use of
mksession
), as you've also mentioned in your readme. Currently there's no way to use this plugin with Startify, but it'd be cool to display a tip in the header, I think. I appreciate the work, thanks.