randomness2077
randomness2077

Reputation: 1139

how vim map two command

I am wondering how to use one hotkey mapping two command in vim. for exmpale, I already have those two mapping

map <silent> <F7> zM
map <silent> <F8> zR

But, I just want to use F8 to toggle between zM and zR. Hoping anyone can give me solution. Thanks a lot.

Upvotes: 2

Views: 549

Answers (1)

chx
chx

Reputation: 11760

Won't zA do what you wanted...?

If it won't then we need to go deeper. http://www.vim.org/scripts/script.php?script_id=1494 tells you what to do, here's the relevant script:

map <buffer> F8 :call ToggleFold()<CR> 
let b:folded = 1 
function! ToggleFold() 
  if( b:folded == 0 ) 
      exec "normal! zM" 
      let b:folded = 1 
  else 
      exec "normal! zR" 
      let b:folded = 0 
  endif 
endfunction 

Upvotes: 9

Related Questions