0

I'd like to create a hotkey to insert the current branch name directly in insert mode with the hotkey <C-b>. I use the plugin gitsigns which has a variable vim.b.gitsigns_head containing the current branch but I can't seem to find a way to input it. I figured I need to add something like

vim.keymap.set('i', '<C-b>', vim.b.gitsigns_head)

but I can't find any way to reference and print the variable.

1 Answer 1

1

I would do:

vim.keymap.set('i', '<C-b>', 'b:gitsigns_head', {expr = true})

Or if you prefer a "pure" lua version:

lua vim.keymap.set('i', '<C-b>', "luaeval('vim.b.gitsigns_head')", {expr = true})

The {expr = true} makes that the lhs is evaluated instead of used directly as input.

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.