Open leaxoy opened 2 years ago
You can simply configure winbar
to use nvim-gps. nvim-gps is a statusline component, so how to use it for winbar, statusline, tabline, etc., is up to users or other plugins.
For example:
_G.gps_location = function()
local gps = require "nvim-gps"
return gps.is_available() and gps.get_location() or ""
end
vim.opt.winbar = "%{%v:lua.gps_location()%}"
Or via your favorite statusline/tabline plugin.
@wookayin Thanks for the code. However, winbar
won't be updated automatically like what statusline does when we move cursor, so it seems we need to use autocmd CursorMoved *
to update it.
However,
winbar
won't be updated automatically asstatusline
when we move cursor, so it seems we need to useautocmd CursorMoved *
to update it.
@rockyzhang24 No, that's not correct and the above code works as you'd expect. Did you try them out?%{...%}
expression means that the function will be called whenever needed (including after cursor update). Read the documentation::help statusline
@wookayin Yes, I know it works as expected and no bugs for statusline
. I've been using this plugin for a long time.
Confirmed that this is a bug of the newly added winbar
(see this https://github.com/neovim/neovim/pull/17336#issuecomment-1132085879). I already opened an issue in the neovim repo (https://github.com/neovim/neovim/issues/18645)
So far, until this winbar
bug is fixed, we should use a piece of code like this:
_G.gps_location = function()
local gps = require "nvim-gps"
return gps.is_available() and gps.get_location() or ""
end
vim.opt.winbar = "%{%v:lua.gps_location()%}"
vim.api.nvim_create_autocmd ("CursorMoved", {
pattern = '*',
command = "set winbar=%{%v:lua.gps_location()%}",
})
Corner case, the winbar always shows even gps is not available.
Correct case
Wrong case
@leaxoy Use my code above and it works well currently. Because winbar won't be updated when you move your cursor (it's a bug and the PR solving it will be merged soon), thus you need the autocmd to refresh it. When that mentioned issue gets fixed, you can remove the autocmd part.
@rockyzhang24 This causes Telescope to turn from looking like the first image to the second. Other than that, it works really great!
@emuel-vassallo Using the autocmd is just a temporary workaround to solve the winbar update issue I mentioned above and it causes this telescope side effect. Waiting for the fix (https://github.com/neovim/neovim/pull/18646) to be merged, and then the autocmd will not be needed.
@emuel-vassallo Try to change the autocmd event to CursorHold
to avoid it disrupting telescope windows.
@emuel-vassallo Try to change the autocmd event to
CursorHold
to avoid it disrupting telescope windows.
@rockyzhang24 That works, thank you!
Will add instructions in README on how to setup in winbar 👍🏽
@SmiteshP Great! You can wait until that PR fixing the update bug gets merged.
it's merged
Great. Then adding gps to winbar is the same with adding it to statusline. It's very handy. And this issue can be closed now.
Now that https://github.com/neovim/neovim/pull/18650 is merged, is it possible to add click support to each part of gps to jump to it?
perhaps open a new issue for that @nghialm269
https://github.com/neovim/neovim/pull/17336 winbar ui has been merged into nightly, it's general to show the gps component, there is vscode example:
and neovim example:![image](https://user-images.githubusercontent.com/8556349/169231034-178da62a-514c-4856-a904-9d41b0663e91.png)