Skip to content

Instantly share code, notes, and snippets.

@eduardoarandah
Last active October 6, 2022 15:54
Show Gist options
  • Save eduardoarandah/f1355e51c11e6c774b221c730fada4e1 to your computer and use it in GitHub Desktop.
Save eduardoarandah/f1355e51c11e6c774b221c730fada4e1 to your computer and use it in GitHub Desktop.
neovim lua command to copy filename, line number and branch
-- Copy filename, line number and branch
-- example: src/filename.js +123 # branch master
vim.api.nvim_create_user_command("CopyPathLineNumberBranch", function()
local branch = vim.fn.systemlist("git branch --show-current")
local comment = ""
if not string.find(branch[1], "not a git repository") then
comment = " # branch " .. branch[1]
end
vim.fn.setreg("*", vim.fn.expand("%") .. " +" .. vim.api.nvim_win_get_cursor(0)[1] .. comment)
end, args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment