Skip to content

Instantly share code, notes, and snippets.

@sedm0784
Last active November 21, 2023 00:16
Show Gist options
  • Save sedm0784/3823884149c70369d7c7791443bff2f3 to your computer and use it in GitHub Desktop.
Save sedm0784/3823884149c70369d7c7791443bff2f3 to your computer and use it in GitHub Desktop.
Split Toggle
nnoremap <Leader>s <Cmd>call SplitToggle()<CR>
command SplitToggle call SplitToggle()
function! SplitToggle() abort
" Check if there's already a split
if !exists('s:split_id')
" Create the split
vsplit
" Move to the new window
wincmd p
" Make a note of its ID
let s:split_id = win_getid()
" Move back
wincmd p
else
" Try moving to the split
if win_gotoid(s:split_id)
" Close it
wincmd c
endif
" Remove the saved ID
unlet s:split_id
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment