I try to write a function to toggle my mappings in Vim script.
Here are the steps I have tested it:
- I load my vim. (open a file)
- Check my mapping in command mode with :imap and I can see mapping(etc. i ffff ...)
- I press F6 to toggle the function
- I got error message: No such mapping
- I check my mapping in command mode with :imap again and I see the mapping(i ffff ...)
- In command mode, I can use iunmpa ffff to unmap the ffff :iunmap ffff
- The mapping is gone.(I can check with :imap)
Does anyone get any idea why iunmap is not working inside my Vim script?
Here is code
nnoremap <F6> :call ToggleBracketGroup()<CR> let g:bracketmap = 1 function! ToggleBracketGroup() if g:bracketmap == 1 inoremap <buffer> ffff print("cool") let g:bracketmap = 0 else **iunmap <buffer> ffff** let g:bracketmap = 1 endif endfunction