So I have been getting very acquainted with Neovim/Spacevim lately, and it's freakin awesome!
I am in the process of setting up some personal keybindings and commands and what have you, and am currently working on Git stuff.
Coming from using VSCode and iTerm2, when wanting to switch from any branch to master
or main
or whatever the main branch is, I have an alias as follows:
alias gcom=git checkout $(git_main_branch)
Where I can just type gcom
into the terminal, and it will automatically switch to whatever the main branch is. Unfortunately in Neovim, git_main_branch
is not a thing, so I am trying to figure out an equivalent, where I can do something like type :Gcom
into the Neovim command prompt, and it switches to the main branch.
I tried to set up a function like this in my init.vim
file (I have coc
and all corresponding Git plugins installed, including fugitive
):
function! GitCheckoutMain()
let gitMainBranch = system('git_main_branch')
execute "normal! :Git checkout" . gitMainBranch
endfunction
and then setting up a command like
command! Gcom :call GitCheckoutMain()
But that does not do the trick. Does anyone know how I might accomplish this with Neovim? Thanks!