Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Created April 26, 2024 11:23
Show Gist options
  • Save mgedmin/690b2a9a1b470f7205c205b56d6dac40 to your computer and use it in GitHub Desktop.
Save mgedmin/690b2a9a1b470f7205c205b56d6dac40 to your computer and use it in GitHub Desktop.
Show/hide terminal by pressing F12 in Vim
fun! ToggleTerminal()
let terms = term_list()
if terms == [] " no terminals, open one
botright term
elseif bufwinnr(terms[0]) == -1 " terminal hidden, show it
exec 'botright sbuffer' terms[0]
else " terminal visible, hide it
exec bufwinnr(terms[0]) .. 'hide'
endif
endf
map <F12> <Cmd>call ToggleTerminal()<CR>
tmap <F12> <Cmd>call ToggleTerminal()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment