Last active
November 15, 2020 00:38
-
-
Save louwers/c56b2e0ef6da8b460b9f2a6874d49027 to your computer and use it in GitHub Desktop.
Hydras for vim: proof of concept
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
" Based on abo-abo/hydra (an Emacs plugin): hydras for vim. | |
" maparg can be used to read, store and restore pre-existing mappings. | |
" also important is having just one place to define hydras | |
" the rest should be automatically generated | |
function! Hydra_Move_Enable() | |
call Hydra_OpenCheatsheet("move") | |
nmap <buffer> s :m .+1<CR>== | |
nmap <buffer> w :m .-2<CR>== | |
nmap <buffer> q :call Hydra_Move_Disable()<CR> | |
endfunction | |
nmap <silent> <leader>m :call Hydra_Move_Enable()<CR> | |
function! Hydra_Move_Disable() | |
nunmap <buffer> s | |
nunmap <buffer> w | |
nunmap <buffer> q | |
bufdo call Hydra_CloseCheatsheets() | |
endfunction | |
function! Hydra_OpenCheatsheet(filename) | |
exe "bo split ~/.vim/hydra/cheatsheets/" . a:filename | |
setlocal laststatus=0 | |
exe "resize " . line('$') | |
set nonumber | |
setlocal filetype=hydracheatsheet | |
setlocal nomodifiable | |
wincmd p | |
endfunction | |
function! Hydra_CloseCheatsheets() | |
if &ft == "hydracheatsheet" | |
bd! | |
endif | |
endfunction |
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
[w] move line up | |
[s] move line down | |
[q] quit |
I know just enough Vimscript to figure there's no reason why this script should close multiple windows. Unfortunately it does on Neovim 0.4.3, so I reached out. Abandoning this in favor of other solutions for the moment.
I changed bufdo call Hydra_CloseCheatsheets()
to windo call Hydra_CloseCheatsheets()
.
Seems to work fine.
It won't close other windows/tabs.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
q
should close the cheat sheets that are visible.If you want hydra for vim, you're going to have to pick up Vimscript.
:h usr_toc