-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide callbacks as native Vim commands #29
Comments
I was able to recreate this behavior with the following in my config: local function copyToClipboard(mode)
require('gitlinker').get_buf_range_url(
mode,
{ action_callback = require('gitlinker.actions').copy_to_clipboard }
)
end
local function openInBrowser(mode)
require('gitlinker').get_buf_range_url(
mode,
{ action_callback = require('gitlinker.actions').open_in_browser }
)
end
function _G.gbrowse(range, bang)
local mode = range > 0 and 'v' or 'n'
local hasBang = bang == '!'
if hasBang then
return copyToClipboard(mode)
else
return openInBrowser(mode)
end
end
vim.cmd([[
command! -nargs=0 -range -bang GBrowse call v:lua.gbrowse(<range>, '<bang>')
]])
u.nnoremap('<leader>gc', [[:GBrowse!<CR>]])
u.vnoremap('<leader>gc', [[:'<,'>GBrowse!<CR>]])
u.nnoremap('<leader>go', [[:GBrowse<CR>]])
u.vnoremap('<leader>go', [[:'<,'>GBrowse<CR>]]) |
Hi @roginfarrer , great to hear that! The decision to not provide native vim commands was deliberate. It goes in line with most new lua plugins and their philosophy. The same goes for the plugin not actually doing anything until a I very much like that since it's transparent and forces the user to acknowledge what he is doing. Yes, mapping to lua functions his currently very cumbersome but I hope that will improve in the near future with neovim's core rapid development. I would happily accept a PR with your suggestion above somewhere in the README. I would even be open to providing those commands if and only if the user calls Thanking for your issue and sorry for the late reply. I'm on holidays until the end of the month. |
No worries about the late reply, enjoy your holiday!
While it may be common, I don't entirely agree that it's a standard nor user-friendly. There's a good conversation about this on reddit. I think some popular counter-examples would be Telescope (which uses
Would this prevent users from using |
I should add, I respect your decision since it's your plugin! Just interested in continuing the conversation. |
Unrelated but, @roginfarrer does the code you pasted works for a line range if I manually type To reproduce:
|
Actually I think there's a bug with the range option in the plugin. I suggest opening a new issue for it |
Describe the solution you'd like
I think this plugin would be a lot easier to use if it provided commands, just like vim-fugitive. Not only would it then be much more approachable to create your own keymappings, but it would make it easier to migrate from vim-fugitive (if the commands were the same).
If it were the same, I'd like to see:
:GBrowse
: open the current file in the browser (in normal mode and visual mode):GBrowse!
: copy the link to the clipboard (I think this comes fromvim-rhubarb
)The text was updated successfully, but these errors were encountered: