Last active
November 21, 2023 00:16
-
-
Save sedm0784/3823884149c70369d7c7791443bff2f3 to your computer and use it in GitHub Desktop.
Split Toggle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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