Skip to content

Instantly share code, notes, and snippets.

@louwers
Last active November 15, 2020 00:38
Show Gist options
  • Save louwers/c56b2e0ef6da8b460b9f2a6874d49027 to your computer and use it in GitHub Desktop.
Save louwers/c56b2e0ef6da8b460b9f2a6874d49027 to your computer and use it in GitHub Desktop.
Hydras for vim: proof of concept
" 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
[w] move line up
[s] move line down
[q] quit
@louwers
Copy link
Author

louwers commented Mar 31, 2020

q should close the cheat sheets that are visible.

If you want hydra for vim, you're going to have to pick up Vimscript.

@jkroes
Copy link

jkroes commented Mar 31, 2020

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.

@attomos
Copy link

attomos commented Nov 15, 2020

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